File: test_liquid_extensions.rb

package info (click to toggle)
jekyll 2.2.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,908 kB
  • ctags: 687
  • sloc: ruby: 6,811; sh: 121; xml: 106; makefile: 35
file content (31 lines) | stat: -rw-r--r-- 853 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'helper'

class TestLiquidExtensions < Test::Unit::TestCase

  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
      @template = Liquid::Template.parse("{% say_hi page.name %}") # Parses and compiles the template
    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