Sha256: 01eb9d2f34a9066cab1044cae453066ebcd4d04f044907e5728ecbf175b8c70c

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Jekyll
  module LanguagePlugin
    class LanguageData
      attr_reader :site, :language

      def initialize(site)
        @site = site
        @l_inst_ary = Array.new
      end

      def get(key, language)
        inject_loaders(language) do |result, loader|
          loader.get(key, language)
        end
      end

      def get_with_placeholders(key, tokens, language)
        inject_loaders(language) do |result, loader|
          loader.get_with_placeholders(key, tokens, language)
        end
      end

      def inject_loaders(language)
        self.class.loaders.inject(nil) do |result, loader|
          unless l_inst = @l_inst_ary.detect { |l| l.is_a?(loader) }
            l_inst = loader.new(@site)
            @l_inst_ary.push(l_inst)
          end

          l_inst.load(language) unless l_inst.loaded?(language)
          result = yield result, l_inst
          break result unless result.nil?
        end
      end

      class << self
        def loaders
          @loaders ||= []
        end

        def register_loader(loader)
          loaders.push(loader)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-language-plugin-1.2.3 lib/jekyll/language-plugin/language_data.rb