locomotivecms_wagon 1.5.0.rc1 → 1.5.0

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: e7d570dba66f67cbb039827e8662d437905ef855
4
- data.tar.gz: fd86e0b2507280c1046bad99a730916b199c1b33
3
+ metadata.gz: 3eb1d85c3211cccddf3105489a759908fdd12832
4
+ data.tar.gz: 62a514ee0e9d0a749feb6dc18a09e696cd1b2e0d
5
5
  SHA512:
6
- metadata.gz: 7debdfefd1c0e609f8c022970d7725e436248e53d67196bdf3427b64d223dc1bd600665d30b1d5acb43a3407e7c3ad1a864df08d6657f7a071beb6d1f1e1857e
7
- data.tar.gz: 852a9e0f2405d4e51509ff154da6694b84e662824d95768411f3b98f2b842568621444c62848fbc2b2674d1666c4273cfcb23ccb309e47cc137321b6f79e5f50
6
+ metadata.gz: 3f0f662eaa63ae25c3ab9b52bd7f732e7352ca956827b4e2b5471575fe542398e823c6b6b321157163c20b2147cb913d2887bc017469d68811962730d68e9d52
7
+ data.tar.gz: 3d16d23bec319002eb7a0f185044364eb3dcd69b8bfd99612d04f9afca762f7c90fd7fb5a9e3e7730b0557dc674139963dc8cd898335d939be51836da3eb82e6
@@ -2,42 +2,46 @@ module Locomotive
2
2
  module Wagon
3
3
  module Liquid
4
4
  module Tags
5
- class WithScope < ::Liquid::Block
6
5
 
7
- SlashedString = /\/[^\/]*\//
8
- TagAttributes = /(\w+|\w+\.\w+)\s*\:\s*(#{SlashedString}|#{::Liquid::QuotedFragment})/
6
+ class WithScope < Solid::Block
9
7
 
10
- def initialize(tag_name, markup, tokens, options)
11
- @tag_options = HashWithIndifferentAccess.new
12
- markup.scan(TagAttributes) do |key, value|
13
- @tag_options[key] = value
14
- end
15
- super
8
+ OPERATORS = %w(all exists gt gte in lt lte ne nin size near within)
9
+
10
+ SYMBOL_OPERATORS_REGEXP = /(\w+\.(#{OPERATORS.join('|')})){1}\s*\:/
11
+
12
+ # register the tag
13
+ tag_name :with_scope
14
+
15
+ def initialize(tag_name, arguments_string, tokens, context = {})
16
+ # convert symbol operators into valid ruby code
17
+ arguments_string.gsub!(SYMBOL_OPERATORS_REGEXP, ':"\1" =>')
18
+
19
+ super(tag_name, arguments_string, tokens, context)
16
20
  end
17
21
 
18
- def render(context)
19
- context.stack do
20
- context['with_scope'] = decode(@tag_options, context)
21
- render_all(@nodelist, context)
22
+ def display(options = {}, &block)
23
+ current_context.stack do
24
+ current_context['with_scope'] = self.decode(options)
25
+ yield
22
26
  end
23
27
  end
24
28
 
25
- private
26
-
27
- def decode(attributes, context)
28
- attributes.each_pair do |key, value|
29
- attributes[key] = (case value
30
- when /^true|false$/i then value == 'true'
31
- when /^\/[^\/]*\/$/ then Regexp.new(value[1..-2])
32
- when /^["|'](.+)["|']$/ then $1.gsub(/^["|']/, '').gsub(/["|']$/, '')
33
- else
34
- context[value].nil? ? value : context[value]
35
- end)
29
+ protected
30
+
31
+ def decode(options)
32
+ HashWithIndifferentAccess.new.tap do |hash|
33
+ options.each do |key, value|
34
+ hash[key] = (case value
35
+ # regexp inside a string
36
+ when /^\/[^\/]*\/$/ then Regexp.new(value[1..-2])
37
+ else
38
+ value
39
+ end)
40
+ end
36
41
  end
37
42
  end
38
43
  end
39
44
 
40
- ::Liquid::Template.register_tag('with_scope', WithScope)
41
45
  end
42
46
  end
43
47
  end
@@ -1,5 +1,5 @@
1
1
  module Locomotive
2
2
  module Wagon
3
- VERSION = '1.5.0.rc1'
3
+ VERSION = '1.5.0'
4
4
  end
5
5
  end
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  title: Various uses of the with_scope tag
3
3
  ---
4
- {% assign begin = '2012-06-01 00:00:00' %}
5
- {% assign end = '2012-06-10 23:59:59' %}
6
- {% assign prices = '5.0,5.5' | split: ',' | map: 'to_f' %}
4
+ {% assign begin_date = '2012-06-01 00:00:00' %}
5
+ {% assign end_date = '2012-06-10 23:59:59' %}
6
+ {% assign prices = '5.0,5.5' | split: ',' | map: 'to_f' %}
7
7
 
8
- {% with_scope date.gte: begin, date.lte: end, city: /Kansas/, state.ne: 'Illinois', tags: 'awesome', tags.nin: 'bad', price.in: prices, order_by: 'price.desc' %}
8
+ {% with_scope date.gte: begin_date, date.lte: end_date, city: /Kansas/, state.ne: 'Illinois', tags: 'awesome', tags.nin: 'bad', price.in: prices, order_by: 'price.desc' %}
9
9
  events={{ contents.events.count }}.
10
10
  {% endwith_scope %}
11
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_wagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.rc1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-22 00:00:00.000000000 Z
12
+ date: 2014-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -845,9 +845,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
845
845
  version: '0'
846
846
  required_rubygems_version: !ruby/object:Gem::Requirement
847
847
  requirements:
848
- - - ">"
848
+ - - ">="
849
849
  - !ruby/object:Gem::Version
850
- version: 1.3.1
850
+ version: '0'
851
851
  requirements: []
852
852
  rubyforge_project:
853
853
  rubygems_version: 2.2.2