liquid 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 764c2e81dc860fd817e71e6fd689b45a66bfee70
4
- data.tar.gz: 2340fffb775ff15bfac14cb84df48a5a5556225f
3
+ metadata.gz: 0a34ea9118594ad84171322f5dbb0b07e5e7b148
4
+ data.tar.gz: e4b170c02fd107b8fa6210554d5a3b647e65a4be
5
5
  SHA512:
6
- metadata.gz: 6315676f23fbe9883c76df24f32ff92668febe745cb7d632004b77d07938fab98d76ed62a1afea594a1ff1c341cc1c1d83dbe13754064aedb1c2c947a1f62db4
7
- data.tar.gz: 5516c2fe89c5e55fdfa788521cc7b3973e47ef9a206c942d2d8c1e3c184ed692ef65dcca596f273ef84b3b568c013a7275852d120d41008472cb8160aa36278b
6
+ metadata.gz: b09f3628e0002d6193fa3c7e0629e0c0c075a50e9d96561dc5a40e8f461793b04c948e4a4aebf4885afe738d58ace2e5ec149b0956fd6f5be1448dbe9b3fa02d
7
+ data.tar.gz: b9a76c51a795058d2b447b95c85a689b6e628b99ada9e0a4db97aebd3a2dda3cc29d790bcef72bb0b86c3fe49b45da9e8fba6eb63ac6e081178542f6dd79b63e
data/History.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # Liquid Version History
2
2
 
3
- ## 3.0.0 / not yet released / branch "master"
3
+ ## 3.0.2 / 2015-04-24 / branch "3-0-stable"
4
+
5
+ * Expose VariableLookup private members (#551) [Justin Li, pushrax]
6
+ * Documentation fixes
7
+
8
+ ## 3.0.1 / 2015-01-23
9
+
10
+ * Remove duplicate `index0` key in TableRow tag (#502) [Alfred Xing]
11
+
12
+ ## 3.0.0 / 2014-11-12
4
13
 
5
- * ...
6
14
  * Removed Block#end_tag. Instead, override parse with `super` followed by your code. See #446 [Dylan Thacker-Smith, dylanahsmith]
7
15
  * Fixed condition with wrong data types, see #423 [Bogdan Gusiev]
8
16
  * Add url_encode to standard filters, see #421 [Derrick Reimer, djreimer]
@@ -61,21 +61,8 @@ module Liquid
61
61
  # for that
62
62
  def add_filters(filters)
63
63
  filters = [filters].flatten.compact
64
- filters.each do |f|
65
- raise ArgumentError, "Expected module but got: #{f.class}" unless f.is_a?(Module)
66
- Strainer.add_known_filter(f)
67
- end
68
-
69
- # If strainer is already setup then there's no choice but to use a runtime
70
- # extend call. If strainer is not yet created, we can utilize strainers
71
- # cached class based API, which avoids busting the method cache.
72
- if @strainer
73
- filters.each do |f|
74
- strainer.extend(f)
75
- end
76
- else
77
- @filters.concat filters
78
- end
64
+ @filters += filters
65
+ @strainer = nil
79
66
  end
80
67
 
81
68
  # are there any not handled interrupts?
@@ -8,12 +8,13 @@ module Liquid
8
8
  # The Strainer only allows method calls defined in filters given to it via Strainer.global_filter,
9
9
  # Context#add_filters or Template.register_filter
10
10
  class Strainer #:nodoc:
11
- @@filters = []
12
- @@known_filters = Set.new
13
- @@known_methods = Set.new
11
+ @@global_strainer = Class.new(Strainer) do
12
+ @filter_methods = Set.new
13
+ end
14
14
  @@strainer_class_cache = Hash.new do |hash, filters|
15
- hash[filters] = Class.new(Strainer) do
16
- filters.each { |f| include f }
15
+ hash[filters] = Class.new(@@global_strainer) do
16
+ @filter_methods = @@global_strainer.filter_methods.dup
17
+ filters.each { |f| add_filter(f) }
17
18
  end
18
19
  end
19
20
 
@@ -21,33 +22,32 @@ module Liquid
21
22
  @context = context
22
23
  end
23
24
 
24
- def self.global_filter(filter)
25
- raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module)
26
- add_known_filter(filter)
27
- @@filters << filter unless @@filters.include?(filter)
28
- end
29
-
30
- def self.add_known_filter(filter)
31
- unless @@known_filters.include?(filter)
32
- @@method_blacklist ||= Set.new(Strainer.instance_methods.map(&:to_s))
33
- new_methods = filter.instance_methods.map(&:to_s)
34
- new_methods.reject!{ |m| @@method_blacklist.include?(m) }
35
- @@known_methods.merge(new_methods)
36
- @@known_filters.add(filter)
25
+ def self.filter_methods
26
+ @filter_methods
27
+ end
28
+
29
+ def self.add_filter(filter)
30
+ raise ArgumentError, "Expected module but got: #{f.class}" unless filter.is_a?(Module)
31
+ unless self.class.include?(filter)
32
+ self.send(:include, filter)
33
+ @filter_methods.merge(filter.public_instance_methods.map(&:to_s))
37
34
  end
38
35
  end
39
36
 
40
- def self.strainer_class_cache
41
- @@strainer_class_cache
37
+ def self.global_filter(filter)
38
+ @@global_strainer.add_filter(filter)
39
+ end
40
+
41
+ def self.invokable?(method)
42
+ @filter_methods.include?(method.to_s)
42
43
  end
43
44
 
44
45
  def self.create(context, filters = [])
45
- filters = @@filters + filters
46
- strainer_class_cache[filters].new(context)
46
+ @@strainer_class_cache[filters].new(context)
47
47
  end
48
48
 
49
49
  def invoke(method, *args)
50
- if invokable?(method)
50
+ if self.class.invokable?(method)
51
51
  send(method, *args)
52
52
  else
53
53
  args.first
@@ -55,9 +55,5 @@ module Liquid
55
55
  rescue ::ArgumentError => e
56
56
  raise Liquid::ArgumentError.new(e.message)
57
57
  end
58
-
59
- def invokable?(method)
60
- @@known_methods.include?(method.to_s) && respond_to?(method)
61
- end
62
58
  end
63
59
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/if'
3
3
  module Liquid
4
4
  # Unless is a conditional just like 'if' but works on the inverse logic.
5
5
  #
6
- # {% unless x < 0 %} x is greater than zero {% end %}
6
+ # {% unless x < 0 %} x is greater than zero {% endunless %}
7
7
  #
8
8
  class Unless < If
9
9
  def render(context)
@@ -3,6 +3,8 @@ module Liquid
3
3
  SQUARE_BRACKETED = /\A\[(.*)\]\z/m
4
4
  COMMAND_METHODS = ['size'.freeze, 'first'.freeze, 'last'.freeze]
5
5
 
6
+ attr_reader :name, :lookups
7
+
6
8
  def self.parse(markup)
7
9
  new(markup)
8
10
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Liquid
3
- VERSION = "3.0.1"
3
+ VERSION = "3.0.2"
4
4
  end
@@ -25,6 +25,12 @@ end
25
25
  class FiltersTest < Minitest::Test
26
26
  include Liquid
27
27
 
28
+ module OverrideObjectMethodFilter
29
+ def tap(input)
30
+ "tap overridden"
31
+ end
32
+ end
33
+
28
34
  def setup
29
35
  @context = Context.new
30
36
  end
@@ -105,6 +111,13 @@ class FiltersTest < Minitest::Test
105
111
  output = Variable.new(%! 'hello %{first_name}, %{last_name}' | substitute: first_name: surname, last_name: 'doe' !).render(@context)
106
112
  assert_equal 'hello john, doe', output
107
113
  end
114
+
115
+ def test_override_object_method_in_filter
116
+ assert_equal "tap overridden", Template.parse("{{var | tap}}").render!({ 'var' => 1000 }, :filters => [OverrideObjectMethodFilter])
117
+
118
+ # tap still treated as a non-existent filter
119
+ assert_equal "1000", Template.parse("{{var | tap}}").render!({ 'var' => 1000 })
120
+ end
108
121
  end
109
122
 
110
123
  class FiltersInTemplate < Minitest::Test
data/test/test_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ ENV["MT_NO_EXPECTATIONS"] = "1"
3
4
  require 'minitest/autorun'
4
5
  require 'spy/integration'
5
6
 
@@ -48,13 +49,19 @@ module Minitest
48
49
  end
49
50
 
50
51
  def with_global_filter(*globals)
51
- original_filters = Array.new(Liquid::Strainer.class_variable_get(:@@filters))
52
+ original_global_strainer = Liquid::Strainer.class_variable_get(:@@global_strainer)
53
+ Liquid::Strainer.class_variable_set(:@@global_strainer, Class.new(Liquid::Strainer) do
54
+ @filter_methods = Set.new
55
+ end)
56
+ Liquid::Strainer.class_variable_get(:@@strainer_class_cache).clear
57
+
52
58
  globals.each do |global|
53
59
  Liquid::Template.register_filter(global)
54
60
  end
55
61
  yield
56
62
  ensure
57
- Liquid::Strainer.class_variable_set(:@@filters, original_filters)
63
+ Liquid::Strainer.class_variable_get(:@@strainer_class_cache).clear
64
+ Liquid::Strainer.class_variable_set(:@@global_strainer, original_global_strainer)
58
65
  end
59
66
 
60
67
  def with_taint_mode(mode)
@@ -31,11 +31,11 @@ class StrainerUnitTest < Minitest::Test
31
31
 
32
32
  def test_strainer_only_invokes_public_filter_methods
33
33
  strainer = Strainer.create(nil)
34
- assert_equal false, strainer.invokable?('__test__')
35
- assert_equal false, strainer.invokable?('test')
36
- assert_equal false, strainer.invokable?('instance_eval')
37
- assert_equal false, strainer.invokable?('__send__')
38
- assert_equal true, strainer.invokable?('size') # from the standard lib
34
+ assert_equal false, strainer.class.invokable?('__test__')
35
+ assert_equal false, strainer.class.invokable?('test')
36
+ assert_equal false, strainer.class.invokable?('instance_eval')
37
+ assert_equal false, strainer.class.invokable?('__send__')
38
+ assert_equal true, strainer.class.invokable?('size') # from the standard lib
39
39
  end
40
40
 
41
41
  def test_strainer_returns_nil_if_no_filter_method_found
@@ -63,9 +63,7 @@ class StrainerUnitTest < Minitest::Test
63
63
  assert_kind_of Strainer, strainer
64
64
  assert_kind_of a, strainer
65
65
  assert_kind_of b, strainer
66
- Strainer.class_variable_get(:@@filters).each do |m|
67
- assert_kind_of m, strainer
68
- end
66
+ assert_kind_of Liquid::StandardFilters, strainer
69
67
  end
70
68
 
71
69
  end # StrainerTest
@@ -136,4 +136,10 @@ class VariableUnitTest < Minitest::Test
136
136
  var = Variable.new(%! name_of_variable | upcase !)
137
137
  assert_equal " name_of_variable | upcase ", var.raw
138
138
  end
139
+
140
+ def test_variable_lookup_interface
141
+ lookup = VariableLookup.new('a.b.c')
142
+ assert_equal 'a', lookup.name
143
+ assert_equal ['b', 'c'], lookup.lookups
144
+ end
139
145
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-23 00:00:00.000000000 Z
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description:
@@ -47,10 +47,6 @@ extra_rdoc_files:
47
47
  - History.md
48
48
  - README.md
49
49
  files:
50
- - History.md
51
- - MIT-LICENSE
52
- - README.md
53
- - lib/liquid.rb
54
50
  - lib/liquid/block.rb
55
51
  - lib/liquid/block_body.rb
56
52
  - lib/liquid/condition.rb
@@ -68,8 +64,8 @@ files:
68
64
  - lib/liquid/module_ex.rb
69
65
  - lib/liquid/parser.rb
70
66
  - lib/liquid/parser_switching.rb
71
- - lib/liquid/profiler.rb
72
67
  - lib/liquid/profiler/hooks.rb
68
+ - lib/liquid/profiler.rb
73
69
  - lib/liquid/range_lookup.rb
74
70
  - lib/liquid/standardfilters.rb
75
71
  - lib/liquid/strainer.rb
@@ -96,6 +92,10 @@ files:
96
92
  - lib/liquid/variable.rb
97
93
  - lib/liquid/variable_lookup.rb
98
94
  - lib/liquid/version.rb
95
+ - lib/liquid.rb
96
+ - MIT-LICENSE
97
+ - README.md
98
+ - History.md
99
99
  - test/fixtures/en_locale.yml
100
100
  - test/integration/assign_test.rb
101
101
  - test/integration/blank_test.rb
@@ -151,17 +151,17 @@ require_paths:
151
151
  - lib
152
152
  required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
- - - ">="
154
+ - - '>='
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - ">="
159
+ - - '>='
160
160
  - !ruby/object:Gem::Version
161
161
  version: 1.3.7
162
162
  requirements: []
163
163
  rubyforge_project:
164
- rubygems_version: 2.2.0
164
+ rubygems_version: 2.0.3
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: A secure, non-evaling end user template engine with aesthetic markup.
@@ -211,3 +211,4 @@ test_files:
211
211
  - test/unit/template_unit_test.rb
212
212
  - test/unit/tokenizer_unit_test.rb
213
213
  - test/unit/variable_unit_test.rb
214
+ has_rdoc: