liquid 2.6.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +194 -29
  3. data/{MIT-LICENSE → LICENSE} +0 -0
  4. data/README.md +60 -2
  5. data/lib/liquid.rb +25 -14
  6. data/lib/liquid/block.rb +47 -96
  7. data/lib/liquid/block_body.rb +143 -0
  8. data/lib/liquid/condition.rb +70 -39
  9. data/lib/liquid/context.rb +116 -157
  10. data/lib/liquid/document.rb +19 -9
  11. data/lib/liquid/drop.rb +31 -14
  12. data/lib/liquid/errors.rb +54 -10
  13. data/lib/liquid/expression.rb +49 -0
  14. data/lib/liquid/extensions.rb +19 -7
  15. data/lib/liquid/file_system.rb +25 -14
  16. data/lib/liquid/forloop_drop.rb +42 -0
  17. data/lib/liquid/i18n.rb +39 -0
  18. data/lib/liquid/interrupts.rb +2 -3
  19. data/lib/liquid/lexer.rb +55 -0
  20. data/lib/liquid/locales/en.yml +26 -0
  21. data/lib/liquid/parse_context.rb +38 -0
  22. data/lib/liquid/parse_tree_visitor.rb +42 -0
  23. data/lib/liquid/parser.rb +90 -0
  24. data/lib/liquid/parser_switching.rb +31 -0
  25. data/lib/liquid/profiler.rb +158 -0
  26. data/lib/liquid/profiler/hooks.rb +23 -0
  27. data/lib/liquid/range_lookup.rb +37 -0
  28. data/lib/liquid/resource_limits.rb +23 -0
  29. data/lib/liquid/standardfilters.rb +311 -77
  30. data/lib/liquid/strainer.rb +39 -26
  31. data/lib/liquid/tablerowloop_drop.rb +62 -0
  32. data/lib/liquid/tag.rb +28 -11
  33. data/lib/liquid/tags/assign.rb +34 -10
  34. data/lib/liquid/tags/break.rb +1 -4
  35. data/lib/liquid/tags/capture.rb +11 -9
  36. data/lib/liquid/tags/case.rb +37 -22
  37. data/lib/liquid/tags/comment.rb +10 -3
  38. data/lib/liquid/tags/continue.rb +1 -4
  39. data/lib/liquid/tags/cycle.rb +20 -14
  40. data/lib/liquid/tags/decrement.rb +4 -8
  41. data/lib/liquid/tags/for.rb +121 -60
  42. data/lib/liquid/tags/if.rb +73 -30
  43. data/lib/liquid/tags/ifchanged.rb +3 -5
  44. data/lib/liquid/tags/include.rb +77 -46
  45. data/lib/liquid/tags/increment.rb +4 -8
  46. data/lib/liquid/tags/raw.rb +35 -10
  47. data/lib/liquid/tags/table_row.rb +62 -0
  48. data/lib/liquid/tags/unless.rb +6 -9
  49. data/lib/liquid/template.rb +130 -32
  50. data/lib/liquid/tokenizer.rb +31 -0
  51. data/lib/liquid/truffle.rb +5 -0
  52. data/lib/liquid/utils.rb +57 -4
  53. data/lib/liquid/variable.rb +121 -30
  54. data/lib/liquid/variable_lookup.rb +88 -0
  55. data/lib/liquid/version.rb +2 -1
  56. data/test/fixtures/en_locale.yml +9 -0
  57. data/test/integration/assign_test.rb +48 -0
  58. data/test/integration/blank_test.rb +106 -0
  59. data/test/integration/block_test.rb +12 -0
  60. data/test/{liquid → integration}/capture_test.rb +13 -3
  61. data/test/integration/context_test.rb +32 -0
  62. data/test/integration/document_test.rb +19 -0
  63. data/test/integration/drop_test.rb +273 -0
  64. data/test/integration/error_handling_test.rb +260 -0
  65. data/test/integration/filter_test.rb +178 -0
  66. data/test/integration/hash_ordering_test.rb +23 -0
  67. data/test/integration/output_test.rb +123 -0
  68. data/test/integration/parse_tree_visitor_test.rb +247 -0
  69. data/test/integration/parsing_quirks_test.rb +122 -0
  70. data/test/integration/render_profiling_test.rb +154 -0
  71. data/test/integration/security_test.rb +80 -0
  72. data/test/integration/standard_filter_test.rb +776 -0
  73. data/test/{liquid → integration}/tags/break_tag_test.rb +2 -3
  74. data/test/{liquid → integration}/tags/continue_tag_test.rb +1 -2
  75. data/test/integration/tags/for_tag_test.rb +410 -0
  76. data/test/integration/tags/if_else_tag_test.rb +188 -0
  77. data/test/integration/tags/include_tag_test.rb +253 -0
  78. data/test/integration/tags/increment_tag_test.rb +23 -0
  79. data/test/{liquid → integration}/tags/raw_tag_test.rb +9 -2
  80. data/test/integration/tags/standard_tag_test.rb +296 -0
  81. data/test/integration/tags/statements_test.rb +111 -0
  82. data/test/{liquid/tags/html_tag_test.rb → integration/tags/table_row_test.rb} +25 -24
  83. data/test/integration/tags/unless_else_tag_test.rb +26 -0
  84. data/test/integration/template_test.rb +332 -0
  85. data/test/integration/trim_mode_test.rb +529 -0
  86. data/test/integration/variable_test.rb +96 -0
  87. data/test/test_helper.rb +106 -19
  88. data/test/truffle/truffle_test.rb +9 -0
  89. data/test/{liquid/block_test.rb → unit/block_unit_test.rb} +9 -9
  90. data/test/unit/condition_unit_test.rb +166 -0
  91. data/test/{liquid/context_test.rb → unit/context_unit_test.rb} +85 -74
  92. data/test/unit/file_system_unit_test.rb +35 -0
  93. data/test/unit/i18n_unit_test.rb +37 -0
  94. data/test/unit/lexer_unit_test.rb +51 -0
  95. data/test/unit/parser_unit_test.rb +82 -0
  96. data/test/{liquid/regexp_test.rb → unit/regexp_unit_test.rb} +4 -4
  97. data/test/unit/strainer_unit_test.rb +164 -0
  98. data/test/unit/tag_unit_test.rb +21 -0
  99. data/test/unit/tags/case_tag_unit_test.rb +10 -0
  100. data/test/unit/tags/for_tag_unit_test.rb +13 -0
  101. data/test/unit/tags/if_tag_unit_test.rb +8 -0
  102. data/test/unit/template_unit_test.rb +78 -0
  103. data/test/unit/tokenizer_unit_test.rb +55 -0
  104. data/test/unit/variable_unit_test.rb +162 -0
  105. metadata +157 -77
  106. data/lib/extras/liquid_view.rb +0 -51
  107. data/lib/liquid/htmltags.rb +0 -74
  108. data/lib/liquid/module_ex.rb +0 -62
  109. data/test/liquid/assign_test.rb +0 -21
  110. data/test/liquid/condition_test.rb +0 -127
  111. data/test/liquid/drop_test.rb +0 -180
  112. data/test/liquid/error_handling_test.rb +0 -81
  113. data/test/liquid/file_system_test.rb +0 -29
  114. data/test/liquid/filter_test.rb +0 -125
  115. data/test/liquid/hash_ordering_test.rb +0 -25
  116. data/test/liquid/module_ex_test.rb +0 -87
  117. data/test/liquid/output_test.rb +0 -116
  118. data/test/liquid/parsing_quirks_test.rb +0 -52
  119. data/test/liquid/security_test.rb +0 -64
  120. data/test/liquid/standard_filter_test.rb +0 -251
  121. data/test/liquid/strainer_test.rb +0 -52
  122. data/test/liquid/tags/for_tag_test.rb +0 -297
  123. data/test/liquid/tags/if_else_tag_test.rb +0 -166
  124. data/test/liquid/tags/include_tag_test.rb +0 -166
  125. data/test/liquid/tags/increment_tag_test.rb +0 -24
  126. data/test/liquid/tags/standard_tag_test.rb +0 -295
  127. data/test/liquid/tags/statements_test.rb +0 -134
  128. data/test/liquid/tags/unless_else_tag_test.rb +0 -26
  129. data/test/liquid/template_test.rb +0 -146
  130. data/test/liquid/variable_test.rb +0 -186
@@ -1,51 +0,0 @@
1
- # LiquidView is a action view extension class. You can register it with rails
2
- # and use liquid as an template system for .liquid files
3
- #
4
- # Example
5
- #
6
- # ActionView::Base::register_template_handler :liquid, LiquidView
7
- class LiquidView
8
- PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
9
- _response url _request _cookies variables_added _flash params _headers request cookies
10
- ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
11
- PROTECTED_INSTANCE_VARIABLES = %w( @_request @controller @_first_render @_memoized__pick_template @view_paths
12
- @helpers @assigns_added @template @_render_stack @template_format @assigns )
13
-
14
- def self.call(template)
15
- "LiquidView.new(self).render(template, local_assigns)"
16
- end
17
-
18
- def initialize(view)
19
- @view = view
20
- end
21
-
22
- def render(template, local_assigns = nil)
23
- @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
24
-
25
- # Rails 2.2 Template has source, but not locals
26
- if template.respond_to?(:source) && !template.respond_to?(:locals)
27
- assigns = (@view.instance_variables - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, ivar|
28
- hash[ivar[1..-1]] = @view.instance_variable_get(ivar)
29
- hash
30
- end
31
- else
32
- assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
33
- end
34
-
35
- source = template.respond_to?(:source) ? template.source : template
36
- local_assigns = (template.respond_to?(:locals) ? template.locals : local_assigns) || {}
37
-
38
- if content_for_layout = @view.instance_variable_get("@content_for_layout")
39
- assigns['content_for_layout'] = content_for_layout
40
- end
41
- assigns.merge!(local_assigns.stringify_keys)
42
-
43
- liquid = Liquid::Template.parse(source)
44
- liquid.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
45
- end
46
-
47
- def compilable?
48
- false
49
- end
50
-
51
- end
@@ -1,74 +0,0 @@
1
- module Liquid
2
- class TableRow < Block
3
- Syntax = /(\w+)\s+in\s+(#{QuotedFragment}+)/o
4
-
5
- def initialize(tag_name, markup, tokens)
6
- if markup =~ Syntax
7
- @variable_name = $1
8
- @collection_name = $2
9
- @attributes = {}
10
- markup.scan(TagAttributes) do |key, value|
11
- @attributes[key] = value
12
- end
13
- else
14
- raise SyntaxError.new("Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3")
15
- end
16
-
17
- super
18
- end
19
-
20
- def render(context)
21
- collection = context[@collection_name] or return ''
22
-
23
- from = @attributes['offset'] ? context[@attributes['offset']].to_i : 0
24
- to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil
25
-
26
- collection = Utils.slice_collection_using_each(collection, from, to)
27
-
28
- length = collection.length
29
-
30
- cols = context[@attributes['cols']].to_i
31
-
32
- row = 1
33
- col = 0
34
-
35
- result = "<tr class=\"row1\">\n"
36
- context.stack do
37
-
38
- collection.each_with_index do |item, index|
39
- context[@variable_name] = item
40
- context['tablerowloop'] = {
41
- 'length' => length,
42
- 'index' => index + 1,
43
- 'index0' => index,
44
- 'col' => col + 1,
45
- 'col0' => col,
46
- 'index0' => index,
47
- 'rindex' => length - index,
48
- 'rindex0' => length - index - 1,
49
- 'first' => (index == 0),
50
- 'last' => (index == length - 1),
51
- 'col_first' => (col == 0),
52
- 'col_last' => (col == cols - 1)
53
- }
54
-
55
-
56
- col += 1
57
-
58
- result << "<td class=\"col#{col}\">" << render_all(@nodelist, context) << '</td>'
59
-
60
- if col == cols and (index != length - 1)
61
- col = 0
62
- row += 1
63
- result << "</tr>\n<tr class=\"row#{row}\">"
64
- end
65
-
66
- end
67
- end
68
- result << "</tr>\n"
69
- result
70
- end
71
- end
72
-
73
- Template.register_tag('tablerow', TableRow)
74
- end
@@ -1,62 +0,0 @@
1
- # Copyright 2007 by Domizio Demichelis
2
- # This library is free software. It may be used, redistributed and/or modified
3
- # under the same terms as Ruby itself
4
- #
5
- # This extension is used in order to expose the object of the implementing class
6
- # to liquid as it were a Drop. It also limits the liquid-callable methods of the instance
7
- # to the allowed method passed with the liquid_methods call
8
- # Example:
9
- #
10
- # class SomeClass
11
- # liquid_methods :an_allowed_method
12
- #
13
- # def an_allowed_method
14
- # 'this comes from an allowed method'
15
- # end
16
- # def unallowed_method
17
- # 'this will never be an output'
18
- # end
19
- # end
20
- #
21
- # if you want to extend the drop to other methods you can defines more methods
22
- # in the class <YourClass>::LiquidDropClass
23
- #
24
- # class SomeClass::LiquidDropClass
25
- # def another_allowed_method
26
- # 'and this from another allowed method'
27
- # end
28
- # end
29
- # end
30
- #
31
- # usage:
32
- # @something = SomeClass.new
33
- #
34
- # template:
35
- # {{something.an_allowed_method}}{{something.unallowed_method}} {{something.another_allowed_method}}
36
- #
37
- # output:
38
- # 'this comes from an allowed method and this from another allowed method'
39
- #
40
- # You can also chain associations, by adding the liquid_method call in the
41
- # association models.
42
- #
43
- class Module
44
-
45
- def liquid_methods(*allowed_methods)
46
- drop_class = eval "class #{self.to_s}::LiquidDropClass < Liquid::Drop; self; end"
47
- define_method :to_liquid do
48
- drop_class.new(self)
49
- end
50
- drop_class.class_eval do
51
- def initialize(object)
52
- @object = object
53
- end
54
- allowed_methods.each do |sym|
55
- define_method sym do
56
- @object.send sym
57
- end
58
- end
59
- end
60
- end
61
-
62
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AssignTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_assigned_variable
7
- assert_template_result('.foo.',
8
- '{% assign foo = values %}.{{ foo[0] }}.',
9
- 'values' => %w{foo bar baz})
10
-
11
- assert_template_result('.bar.',
12
- '{% assign foo = values %}.{{ foo[1] }}.',
13
- 'values' => %w{foo bar baz})
14
- end
15
-
16
- def test_assign_with_filter
17
- assert_template_result('.bar.',
18
- '{% assign foo = values | split: "," %}.{{ foo[1] }}.',
19
- 'values' => "foo,bar,baz")
20
- end
21
- end # AssignTest
@@ -1,127 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ConditionTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_basic_condition
7
- assert_equal false, Condition.new('1', '==', '2').evaluate
8
- assert_equal true, Condition.new('1', '==', '1').evaluate
9
- end
10
-
11
- def test_default_operators_evalute_true
12
- assert_evalutes_true '1', '==', '1'
13
- assert_evalutes_true '1', '!=', '2'
14
- assert_evalutes_true '1', '<>', '2'
15
- assert_evalutes_true '1', '<', '2'
16
- assert_evalutes_true '2', '>', '1'
17
- assert_evalutes_true '1', '>=', '1'
18
- assert_evalutes_true '2', '>=', '1'
19
- assert_evalutes_true '1', '<=', '2'
20
- assert_evalutes_true '1', '<=', '1'
21
- # negative numbers
22
- assert_evalutes_true '1', '>', '-1'
23
- assert_evalutes_true '-1', '<', '1'
24
- assert_evalutes_true '1.0', '>', '-1.0'
25
- assert_evalutes_true '-1.0', '<', '1.0'
26
- end
27
-
28
- def test_default_operators_evalute_false
29
- assert_evalutes_false '1', '==', '2'
30
- assert_evalutes_false '1', '!=', '1'
31
- assert_evalutes_false '1', '<>', '1'
32
- assert_evalutes_false '1', '<', '0'
33
- assert_evalutes_false '2', '>', '4'
34
- assert_evalutes_false '1', '>=', '3'
35
- assert_evalutes_false '2', '>=', '4'
36
- assert_evalutes_false '1', '<=', '0'
37
- assert_evalutes_false '1', '<=', '0'
38
- end
39
-
40
- def test_contains_works_on_strings
41
- assert_evalutes_true "'bob'", 'contains', "'o'"
42
- assert_evalutes_true "'bob'", 'contains', "'b'"
43
- assert_evalutes_true "'bob'", 'contains', "'bo'"
44
- assert_evalutes_true "'bob'", 'contains', "'ob'"
45
- assert_evalutes_true "'bob'", 'contains', "'bob'"
46
-
47
- assert_evalutes_false "'bob'", 'contains', "'bob2'"
48
- assert_evalutes_false "'bob'", 'contains', "'a'"
49
- assert_evalutes_false "'bob'", 'contains', "'---'"
50
- end
51
-
52
- def test_contains_works_on_arrays
53
- @context = Liquid::Context.new
54
- @context['array'] = [1,2,3,4,5]
55
-
56
- assert_evalutes_false "array", 'contains', '0'
57
- assert_evalutes_true "array", 'contains', '1'
58
- assert_evalutes_true "array", 'contains', '2'
59
- assert_evalutes_true "array", 'contains', '3'
60
- assert_evalutes_true "array", 'contains', '4'
61
- assert_evalutes_true "array", 'contains', '5'
62
- assert_evalutes_false "array", 'contains', '6'
63
- assert_evalutes_false "array", 'contains', '"1"'
64
- end
65
-
66
- def test_contains_returns_false_for_nil_operands
67
- @context = Liquid::Context.new
68
- assert_evalutes_false "not_assigned", 'contains', '0'
69
- assert_evalutes_false "0", 'contains', 'not_assigned'
70
- end
71
-
72
- def test_or_condition
73
- condition = Condition.new('1', '==', '2')
74
-
75
- assert_equal false, condition.evaluate
76
-
77
- condition.or Condition.new('2', '==', '1')
78
-
79
- assert_equal false, condition.evaluate
80
-
81
- condition.or Condition.new('1', '==', '1')
82
-
83
- assert_equal true, condition.evaluate
84
- end
85
-
86
- def test_and_condition
87
- condition = Condition.new('1', '==', '1')
88
-
89
- assert_equal true, condition.evaluate
90
-
91
- condition.and Condition.new('2', '==', '2')
92
-
93
- assert_equal true, condition.evaluate
94
-
95
- condition.and Condition.new('2', '==', '1')
96
-
97
- assert_equal false, condition.evaluate
98
- end
99
-
100
- def test_should_allow_custom_proc_operator
101
- Condition.operators['starts_with'] = Proc.new { |cond, left, right| left =~ %r{^#{right}} }
102
-
103
- assert_evalutes_true "'bob'", 'starts_with', "'b'"
104
- assert_evalutes_false "'bob'", 'starts_with', "'o'"
105
-
106
- ensure
107
- Condition.operators.delete 'starts_with'
108
- end
109
-
110
- def test_left_or_right_may_contain_operators
111
- @context = Liquid::Context.new
112
- @context['one'] = @context['another'] = "gnomeslab-and-or-liquid"
113
-
114
- assert_evalutes_true "one", '==', "another"
115
- end
116
-
117
- private
118
- def assert_evalutes_true(left, op, right)
119
- assert Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
120
- "Evaluated false: #{left} #{op} #{right}"
121
- end
122
-
123
- def assert_evalutes_false(left, op, right)
124
- assert !Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
125
- "Evaluated true: #{left} #{op} #{right}"
126
- end
127
- end # ConditionTest
@@ -1,180 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ContextDrop < Liquid::Drop
4
- def scopes
5
- @context.scopes.size
6
- end
7
-
8
- def scopes_as_array
9
- (1..@context.scopes.size).to_a
10
- end
11
-
12
- def loop_pos
13
- @context['forloop.index']
14
- end
15
-
16
- def before_method(method)
17
- return @context[method]
18
- end
19
- end
20
-
21
- class ProductDrop < Liquid::Drop
22
-
23
- class TextDrop < Liquid::Drop
24
- def array
25
- ['text1', 'text2']
26
- end
27
-
28
- def text
29
- 'text1'
30
- end
31
- end
32
-
33
- class CatchallDrop < Liquid::Drop
34
- def before_method(method)
35
- return 'method: ' << method.to_s
36
- end
37
- end
38
-
39
- def texts
40
- TextDrop.new
41
- end
42
-
43
- def catchall
44
- CatchallDrop.new
45
- end
46
-
47
- def context
48
- ContextDrop.new
49
- end
50
-
51
- protected
52
- def callmenot
53
- "protected"
54
- end
55
- end
56
-
57
- class EnumerableDrop < Liquid::Drop
58
-
59
- def size
60
- 3
61
- end
62
-
63
- def each
64
- yield 1
65
- yield 2
66
- yield 3
67
- end
68
- end
69
-
70
- class DropsTest < Test::Unit::TestCase
71
- include Liquid
72
-
73
- def test_product_drop
74
- assert_nothing_raised do
75
- tpl = Liquid::Template.parse( ' ' )
76
- tpl.render('product' => ProductDrop.new)
77
- end
78
- end
79
-
80
- def test_drop_does_only_respond_to_whitelisted_methods
81
- assert_equal "", Liquid::Template.parse("{{ product.inspect }}").render('product' => ProductDrop.new)
82
- assert_equal "", Liquid::Template.parse("{{ product.pretty_inspect }}").render('product' => ProductDrop.new)
83
- assert_equal "", Liquid::Template.parse("{{ product.whatever }}").render('product' => ProductDrop.new)
84
- assert_equal "", Liquid::Template.parse('{{ product | map: "inspect" }}').render('product' => ProductDrop.new)
85
- assert_equal "", Liquid::Template.parse('{{ product | map: "pretty_inspect" }}').render('product' => ProductDrop.new)
86
- assert_equal "", Liquid::Template.parse('{{ product | map: "whatever" }}').render('product' => ProductDrop.new)
87
- end
88
-
89
- def test_drops_respond_to_to_liquid
90
- assert_equal "text1", Liquid::Template.parse("{{ product.to_liquid.texts.text }}").render('product' => ProductDrop.new)
91
- assert_equal "text1", Liquid::Template.parse('{{ product | map: "to_liquid" | map: "texts" | map: "text" }}').render('product' => ProductDrop.new)
92
- end
93
-
94
- def test_text_drop
95
- output = Liquid::Template.parse( ' {{ product.texts.text }} ' ).render('product' => ProductDrop.new)
96
- assert_equal ' text1 ', output
97
- end
98
-
99
- def test_unknown_method
100
- output = Liquid::Template.parse( ' {{ product.catchall.unknown }} ' ).render('product' => ProductDrop.new)
101
- assert_equal ' method: unknown ', output
102
- end
103
-
104
- def test_integer_argument_drop
105
- output = Liquid::Template.parse( ' {{ product.catchall[8] }} ' ).render('product' => ProductDrop.new)
106
- assert_equal ' method: 8 ', output
107
- end
108
-
109
- def test_text_array_drop
110
- output = Liquid::Template.parse( '{% for text in product.texts.array %} {{text}} {% endfor %}' ).render('product' => ProductDrop.new)
111
- assert_equal ' text1 text2 ', output
112
- end
113
-
114
- def test_context_drop
115
- output = Liquid::Template.parse( ' {{ context.bar }} ' ).render('context' => ContextDrop.new, 'bar' => "carrot")
116
- assert_equal ' carrot ', output
117
- end
118
-
119
- def test_nested_context_drop
120
- output = Liquid::Template.parse( ' {{ product.context.foo }} ' ).render('product' => ProductDrop.new, 'foo' => "monkey")
121
- assert_equal ' monkey ', output
122
- end
123
-
124
- def test_protected
125
- output = Liquid::Template.parse( ' {{ product.callmenot }} ' ).render('product' => ProductDrop.new)
126
- assert_equal ' ', output
127
- end
128
-
129
- def test_object_methods_not_allowed
130
- [:dup, :clone, :singleton_class, :eval, :class_eval, :inspect].each do |method|
131
- output = Liquid::Template.parse(" {{ product.#{method} }} ").render('product' => ProductDrop.new)
132
- assert_equal ' ', output
133
- end
134
- end
135
-
136
- def test_scope
137
- assert_equal '1', Liquid::Template.parse( '{{ context.scopes }}' ).render('context' => ContextDrop.new)
138
- assert_equal '2', Liquid::Template.parse( '{%for i in dummy%}{{ context.scopes }}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
139
- assert_equal '3', Liquid::Template.parse( '{%for i in dummy%}{%for i in dummy%}{{ context.scopes }}{%endfor%}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
140
- end
141
-
142
- def test_scope_though_proc
143
- assert_equal '1', Liquid::Template.parse( '{{ s }}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] })
144
- assert_equal '2', Liquid::Template.parse( '{%for i in dummy%}{{ s }}{%endfor%}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] }, 'dummy' => [1])
145
- assert_equal '3', Liquid::Template.parse( '{%for i in dummy%}{%for i in dummy%}{{ s }}{%endfor%}{%endfor%}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] }, 'dummy' => [1])
146
- end
147
-
148
- def test_scope_with_assigns
149
- assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{{a}}' ).render('context' => ContextDrop.new)
150
- assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{%for i in dummy%}{{a}}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
151
- assert_equal 'test', Liquid::Template.parse( '{% assign header_gif = "test"%}{{header_gif}}' ).render('context' => ContextDrop.new)
152
- assert_equal 'test', Liquid::Template.parse( "{% assign header_gif = 'test'%}{{header_gif}}" ).render('context' => ContextDrop.new)
153
- end
154
-
155
- def test_scope_from_tags
156
- assert_equal '1', Liquid::Template.parse( '{% for i in context.scopes_as_array %}{{i}}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
157
- assert_equal '12', Liquid::Template.parse( '{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
158
- assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
159
- end
160
-
161
- def test_access_context_from_drop
162
- assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{{ context.loop_pos }}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1,2,3])
163
- end
164
-
165
- def test_enumerable_drop
166
- assert_equal '123', Liquid::Template.parse( '{% for c in collection %}{{c}}{% endfor %}').render('collection' => EnumerableDrop.new)
167
- end
168
-
169
- def test_enumerable_drop_size
170
- assert_equal '3', Liquid::Template.parse( '{{collection.size}}').render('collection' => EnumerableDrop.new)
171
- end
172
-
173
- def test_empty_string_value_access
174
- assert_equal '', Liquid::Template.parse('{{ product[value] }}').render('product' => ProductDrop.new, 'value' => '')
175
- end
176
-
177
- def test_nil_value_access
178
- assert_equal '', Liquid::Template.parse('{{ product[value] }}').render('product' => ProductDrop.new, 'value' => nil)
179
- end
180
- end # DropsTest