class Jekyll::ConstantValues
Public Class Methods
new(tag_name, key, tokens)
click to toggle source
Calls superclass method
# File lib/jekyll_constant_values.rb, line 41 def initialize(tag_name, key, tokens) super @key = key.strip end
Public Instance Methods
render(context)
click to toggle source
# File lib/jekyll_constant_values.rb, line 46 def render(context) # Load Jekyll site object site = context.registers[:site] # Load constants file c_file = YAML.load_file(site.constants_file) # Get constant value c_value = @key.to_s.split('.').inject(c_file) { |h, k| h[k.to_s] } # Check if constant value is empty if c_value.nil? # Get the path of the file where is failing page_path = context.registers[:page]['path'] # Show info message puts "No constant value for key '#{@key}' in file '#{page_path}'" end # Return the constant value c_value end