Class: Jekyll::Site

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#constants_fileObject

Returns the value of attribute constants_file.



5
6
7
# File 'lib/jekyll_constant_values.rb', line 5

def constants_file
  @constants_file
end

Instance Method Details

#constants_file_pathObject



21
22
23
24
25
26
27
28
# File 'lib/jekyll_constant_values.rb', line 21

def constants_file_path
  # Check if a custom name for constants file is defined
  if config['constants'].nil?
    '_data/constants.yml' # Default constants file
  else
    '_data/' + config['constants'] + '.yml' # Custom constants file
  end
end

#processObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jekyll_constant_values.rb', line 8

def process
  # Get the constants file path
  const_file = constants_file_path
  # Exit the process if not valid file
  exit unless valid_file?(const_file)
  # Assign the path if valid
  self.constants_file ||= const_file
  # Show info message
  puts "Using file #{const_file} for constant values"

  process_constants
end

#process_constantsObject



6
# File 'lib/jekyll_constant_values.rb', line 6

alias :process_constants :process

#valid_file?(const_file) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
# File 'lib/jekyll_constant_values.rb', line 30

def valid_file?(const_file)
  # Check if the constants file exist
  unless File.exist?(const_file)
    puts "No such file or directory #{const_file}"
    return false
  end
  true
end