Class: Jekyll::ConstantValues

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll_constant_values.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, key, tokens) ⇒ ConstantValues

Returns a new instance of ConstantValues.



41
42
43
44
# File 'lib/jekyll_constant_values.rb', line 41

def initialize(tag_name, key, tokens)
  super
  @key = key.strip
end

Instance Method Details

#render(context) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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