Class: Jekyll::LanguagePlugin::Loaders::BuiltinDataLoader

Inherits:
BaseLoader
  • Object
show all
Defined in:
lib/jekyll/language-plugin/loaders/builtin_data_loader.rb

Instance Attribute Summary collapse

Attributes inherited from BaseLoader

#site

Instance Method Summary collapse

Methods inherited from BaseLoader

#get_with_placeholders, #resolve_dot_notation, #traverse_hash

Constructor Details

#initialize(site) ⇒ BuiltinDataLoader

Returns a new instance of BuiltinDataLoader.



13
14
15
16
# File 'lib/jekyll/language-plugin/loaders/builtin_data_loader.rb', line 13

def initialize(site)
  super
  @data = Hash.new
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/jekyll/language-plugin/loaders/builtin_data_loader.rb', line 11

def data
  @data
end

Instance Method Details

#get(key, language) ⇒ Object



31
32
33
34
35
# File 'lib/jekyll/language-plugin/loaders/builtin_data_loader.rb', line 31

def get(key, language)
  return nil unless loaded?(language)

  traverse_hash(@data, resolve_dot_notation([language, key]))
end

#load(language) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/jekyll/language-plugin/loaders/builtin_data_loader.rb', line 22

def load(language)
  return true if loaded?(language)

  file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'data', 'lang', "#{language}.yml"))
  return false unless File.file?(file)

  !!@data.merge!(YAML.load_file(file));
end

#loaded?(language) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/jekyll/language-plugin/loaders/builtin_data_loader.rb', line 18

def loaded?(language)
  @data.has_key?(language)
end