Sha256: 7dcc4fa6bd59c7c61ae6bd5e8c91f93f48264a18899e7270cedfa041e2e903ca

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

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

module Jekyll
  module LanguagePlugin
    module Tags
      class LanguageTag < Liquid::Tag
        def initialize(tag_name, markup, tokens)
          super
          @markup = markup
        end

        def render(context)
          p = Liquid::Parser.new(@markup)
          name = Liquid::Expression.parse(exp = p.expression)
          key = context.evaluate(name)
          raise Liquid::SyntaxError.new("Invalid language key expression: #{exp}") if key.nil?

          tokens = Array.new
          if p.consume?(:colon)
            loop do
              arg = Liquid::Expression.parse(exp = p.expression)
              token = context.evaluate(arg)
              raise Liquid::SyntaxError.new("Invalid parameter expression: #{exp}") if token.nil?
              tokens.push(token)
              break if !p.consume?(:comma)
            end
          end

           Jekyll::LanguagePlugin::LiquidContext.get_language_string(context, key, tokens)
        end
      end
    end
  end
end

Liquid::Template.register_tag('t', Jekyll::LanguagePlugin::Tags::LanguageTag)

Version data entries

6 entries across 6 versions & 1 rubygems

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