Sha256: 648adfc12904a09ed6989a912c643bae0163bbae2b72fe25443fd021232d97f8

Contents?: true

Size: 1012 Bytes

Versions: 6

Compression:

Stored size: 1012 Bytes

Contents

# Frozen-string-literal: true
# Encoding: utf-8

module Jekyll
  module LanguagePlugin
    module Loaders
      class JekyllDataLoader < BaseLoader
        def initialize(site)
          super
        end

        def get(key, language)
          key = resolve_dot_notation(key)

          data = get_language_data(language)
          traverse_hash(data, key)
        end

        def get_language_data(language)
          @language_data ||= site.config['language_data'].to_s || 'data.lang.%%'
          language_data_l = @language_data.gsub("%%", language)

          key = resolve_dot_notation(language_data_l)

          obj = site.send(key.shift)
          obj = traverse_hash(obj, key)
          raise Jekyll::LanguagePlugin::PluginError.new("Invalid language data configuration. Cannot retrieve data for language #{language} at #{language_data_l}") if obj.nil?
          obj
        end
      end
    end
  end
end

Jekyll::LanguagePlugin.register_loader(Jekyll::LanguagePlugin::Loaders::JekyllDataLoader)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jekyll-language-plugin-1.3.5 lib/jekyll/language-plugin/loaders/jekyll_data_loader.rb
jekyll-language-plugin-1.3.4 lib/jekyll/language-plugin/loaders/jekyll_data_loader.rb
jekyll-language-plugin-1.3.3 lib/jekyll/language-plugin/loaders/jekyll_data_loader.rb
jekyll-language-plugin-1.3.2 lib/jekyll/language-plugin/loaders/jekyll_data_loader.rb
jekyll-language-plugin-1.3.1 lib/jekyll/language-plugin/loaders/jekyll_data_loader.rb
jekyll-language-plugin-1.3.0 lib/jekyll/language-plugin/loaders/jekyll_data_loader.rb