https://github.com/jekyll/jekyll
Raw File
Tip revision: 6f2d1591fcfb61e27347defb7e5f3df846fe6e9c authored by Parker Moore on 05 October 2016, 18:47:43 UTC
Release :gem: 3.3.0.pre.rc1
Tip revision: 6f2d159
test_liquid_extensions.rb
require "helper"

class TestLiquidExtensions < JekyllUnitTest
  context "looking up a variable in a Liquid context" do
    class SayHi < Liquid::Tag
      include Jekyll::LiquidExtensions

      def initialize(_tag_name, markup, _tokens)
        @markup = markup.strip
      end

      def render(context)
        "hi #{lookup_variable(context, @markup)}"
      end
    end
    Liquid::Template.register_tag("say_hi", SayHi)
    setup do
      # Parses and compiles the template
      @template = Liquid::Template.parse("{% say_hi page.name %}")
    end

    should "extract the var properly" do
      assert_equal @template.render({ "page" => { "name" => "tobi" } }), "hi tobi"
    end

    should "return the variable name if the value isn't there" do
      assert_equal @template.render({ "page" => { "title" => "tobi" } }), "hi page.name"
    end
  end
end
back to top