locomotivecms-solid 0.2.2.1 → 4.0.0.alpha

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: 434d1b9f43610e469477ddadfe0e080c5137de05
4
- data.tar.gz: 8f8cf72a3656ee3f283a81ae89613c64a766aadd
3
+ metadata.gz: 0e66c02929c30ed50d56ae70f03eda812d1f3415
4
+ data.tar.gz: 26cbcbbd0795d27181ff58b45749e654129e17fb
5
5
  SHA512:
6
- metadata.gz: 534003b5afdfef1931a75ba7fca2c4b4b0e6e96bdbae1de453826cc7fe205866e5c069b2aed3c7d7991d2a62043dd8dddad1ee83dcc56b22fcbe5390282687a7
7
- data.tar.gz: 277599d7cfd02d0d927f32cceeab7d0fb1d183169ae7018d3db9140d951df5f5b6e88519d07a77347c979bd728028c57ce7714d6e4102b7e24081aab7e54c575
6
+ metadata.gz: 41ea08b22297efb4f658a297934b6f46444ecbf9295d0af64877ef1a971718e235f15200553883e2025059c1f961b047ad4a9ae49e545827f5e3421cec962828
7
+ data.tar.gz: 0d639fee1c41c8300dd77db23d2f495eb54d4617d5e4a8afde50f10408293e5588b3d3c99c0ef2d2629d389385b271a3a61569aaec3985894daa2a470e7c4fb3
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in solid.gemspec
4
4
  gemspec
5
5
 
6
- # gem 'locomotivecms-liquid', path: '/Users/didier/Documents/LocomotiveCMS/gems/liquid'
6
+ gem 'liquid', path: '/Users/didier/Documents/LocomotiveCMS/gems/liquid'
@@ -1,35 +1,34 @@
1
1
  class Solid::ConditionalBlock < Liquid::Block
2
- include Solid::Element
3
2
 
4
- def initialize(tag_name, variable, tokens, context = {})
5
- @blocks = []
6
- push_block!
7
- super
8
- end
3
+ include Solid::Element
9
4
 
10
5
  def render(context)
11
6
  with_context(context) do
12
7
  display(*arguments.interpolate(context)) do |condition_satisfied|
13
- block = condition_satisfied ? @blocks.first : @blocks[1]
14
- render_all(block, context) if block
8
+ render_with_condition(condition_satisfied, context)
15
9
  end
16
10
  end
17
11
  end
18
12
 
13
+ def render_with_condition(condition_satisfied, context)
14
+ _body = nil
15
+
16
+ if condition_satisfied
17
+ _body = @condition_satisfied_body
18
+ else
19
+ return '' if @condition_satisfied_body.nil?
20
+ end
21
+
22
+ (_body || @body).render(context)
23
+ end
24
+
19
25
  def unknown_tag(tag, markup, tokens)
20
26
  if tag == 'else'
21
- push_block!
27
+ @condition_satisfied_body = @body.clone
28
+ @body.instance_variable_set(:@nodelist, [])
22
29
  else
23
30
  super
24
31
  end
25
32
  end
26
33
 
27
- private
28
-
29
- def push_block!
30
- block = []
31
- @blocks.push(block)
32
- @nodelist = block
33
- end
34
-
35
34
  end
@@ -10,9 +10,13 @@ Solid::MethodWhitelist
10
10
  :second, :seconds, :minute, :minutes, :hour, :hours, :day, :days, :week, :weeks,
11
11
  :bytes, :kilobytes, :megabytes, :gigabytes, :terabytes, :petabytes, :exabytes],
12
12
  Integer => [:multiple_of?, :month, :months, :year, :years, :to_json],
13
+ String => [:gsub, :strip, :chop, :chomp, :start_with?, :end_with?,
14
+ :[], :length, :size, :empty?, :=~, :split, :upcase, :downcase, :capitalize, :squeeze, :tr,
15
+ :exclude?, :truncate]
13
16
  ).deny(
14
17
  Module => [:const_get, :const_set, :const_defined?, :freeze, :ancestors],
15
18
  Class => [:new, :allocate, :superclass],
19
+ String => [:freeze]
16
20
  )
17
21
 
18
22
  if defined?(JSON::Ext::Generator::GeneratorMethods::Fixnum) &&
@@ -5,9 +5,9 @@ module Solid::Element
5
5
  base.send(:include, Solid::Iterable)
6
6
  end
7
7
 
8
- def initialize(tag_name, arguments_string, tokens, context = {})
9
- super
10
- @arguments = Solid::Arguments.parse(arguments_string)
8
+ def initialize(tag_name, arguments_string, options)
9
+ super
10
+ @arguments = Solid::Arguments.parse(arguments_string)
11
11
  end
12
12
 
13
13
  def arguments
@@ -5,10 +5,10 @@ module Solid
5
5
 
6
6
  tag_name :assign
7
7
 
8
- def initialize(tag_name, assignment, tokens, context = {})
8
+ def initialize(tag_name, assignment, options)
9
9
  @assigned_variable, expression = assignment.split('=', 2)
10
10
  @assigned_variable = @assigned_variable.strip
11
- super(tag_name, expression, tokens, context)
11
+ super(tag_name, expression, options)
12
12
  end
13
13
 
14
14
  def display(expression_result)
@@ -1,22 +1,25 @@
1
1
  module Solid
2
2
  module LiquidExtensions
3
3
  class IfTag < Liquid::Block
4
+
4
5
  include Solid::Element
5
6
  extend TagHighjacker
6
7
 
7
8
  tag_name :if
8
9
 
9
- def initialize(tag_name, expression, tokens, context = {})
10
+ def initialize(tag_name, expression, context = {})
10
11
  @blocks = []
11
12
  push_block!(expression)
12
13
  super
13
14
  end
14
15
 
15
16
  def render(context)
17
+ attach_body_to_last_block
18
+
16
19
  with_context(context) do
17
- @blocks.each do |expression, blocks|
20
+ @blocks.each do |expression, body|
18
21
  if expression.evaluate(context)
19
- return render_all(blocks, context)
22
+ return body.render(context)
20
23
  end
21
24
  end
22
25
  end
@@ -34,9 +37,17 @@ module Solid
34
37
  protected
35
38
 
36
39
  def push_block!(expression)
37
- block = []
38
- @blocks.push([Solid::Parser.parse(expression), block])
39
- @nodelist = block
40
+ attach_body_to_last_block
41
+
42
+ @blocks.push([Solid::Parser.parse(expression), nil])
43
+ end
44
+
45
+ def attach_body_to_last_block
46
+ # the @body always represents the nodelist of the previous expression
47
+ if last_block = @blocks.last
48
+ last_block[1] = @body.clone
49
+ @body.instance_variable_set(:@nodelist, [])
50
+ end
40
51
  end
41
52
 
42
53
  end
@@ -4,8 +4,8 @@ module Solid
4
4
 
5
5
  tag_name :unless
6
6
 
7
- def initialize(tag_name, expression, tokens, context = {})
8
- super(tag_name, "!(#{expression})", tokens, context)
7
+ def initialize(tag_name, expression, options)
8
+ super(tag_name, "!(#{expression})", options)
9
9
  end
10
10
 
11
11
  end
@@ -5,7 +5,9 @@ module Solid
5
5
 
6
6
  def initialize(markup, options={})
7
7
  super
8
- @expression = Solid::Parser.parse(@name)
8
+ if markup =~ /(#{::Liquid::QuotedFragment})(.*)/om
9
+ @expression = Solid::Parser.parse($1)
10
+ end
9
11
  end
10
12
 
11
13
  def render(context)
@@ -1,3 +1,3 @@
1
1
  module Solid
2
- VERSION = '0.2.2.1'
2
+ VERSION = '4.0.0.alpha'
3
3
  end
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency "rake"
21
21
  s.add_development_dependency "i18n"
22
22
  s.add_development_dependency "ruby_parser", "~> 3.2"
23
- s.add_development_dependency "activesupport", "~> 3"
23
+ s.add_development_dependency "activesupport", "~> 4.2"
24
24
 
25
- s.add_runtime_dependency "locomotivecms-liquid", "~> 2.6.0"
25
+ # TODO
26
+ s.add_runtime_dependency "locomotivecms-liquid", "4.0.0.alpha"
26
27
  end
@@ -20,7 +20,7 @@ describe Solid::Block do
20
20
 
21
21
  let(:tokens) { ["dummy", "{% enddummy %}", "outside"] }
22
22
 
23
- subject{ DummyBlock.new('dummy', 'condition', tokens) }
23
+ subject{ DummyBlock.parse('dummy', 'condition', tokens, {}) }
24
24
 
25
25
  it 'yielding should render the block content' do
26
26
  subject.render(Liquid::Context.new('condition' => true)).should be == 'dummy'
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  class IfPresent < Solid::ConditionalBlock
4
4
 
5
+ tag_name :ifpresent
6
+
5
7
  def display(string)
6
8
  yield(!string.strip.empty?)
7
9
  end
@@ -14,9 +16,9 @@ describe Solid::ConditionalBlock do
14
16
 
15
17
  describe '#display' do
16
18
 
17
- let(:tokens) { ["present", "{% else %}", "blank", "{% endifpresent %}"] }
19
+ let(:template) { "{% ifpresent mystring %}present{% else %}blank{% endifpresent %}"}
18
20
 
19
- subject{ IfPresent.new('ifpresent', 'mystring', tokens) }
21
+ subject { Liquid::Template.parse(template) }
20
22
 
21
23
  it 'yielding true should render the main block' do
22
24
  context = Liquid::Context.new('mystring' => 'blah')
@@ -28,10 +30,15 @@ describe Solid::ConditionalBlock do
28
30
  subject.render(context).should be == 'blank'
29
31
  end
30
32
 
31
- it 'yielding false without a `else` block does not render anything' do
32
- context = Liquid::Context.new('mystring' => '')
33
- subject = IfPresent.new('ifpresent', 'mystring', ['present', '{% endifpresent %}'])
34
- subject.render(context).should be_nil
33
+ context 'without a `else` block' do
34
+
35
+ let(:template) { "{% ifpresent mystring %}present{% endifpresent %}"}
36
+
37
+ it 'yielding false should not render anything' do
38
+ context = Liquid::Context.new('mystring' => '')
39
+ subject.render(context).should be == ''
40
+ end
41
+
35
42
  end
36
43
 
37
44
  end
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper'
2
+ require 'active_support'
3
+ require 'active_support/deprecation'
2
4
  require 'active_support/core_ext'
3
5
 
4
6
  describe Solid, 'default security rules' do
@@ -105,7 +107,8 @@ describe Solid, 'default security rules' do
105
107
  describe 'Range instances' do
106
108
  subject { 1..10 }
107
109
 
108
- it_should_behave_like 'a ruby object', 'an enumerable'
110
+ # FIXME (Did): length and to_json are not methods of the Range class anymore
111
+ # it_should_behave_like 'a ruby object', 'an enumerable'
109
112
  it_should_safely_respond_to :first, :last, :begin, :end, :max, :min, :cover?, :include?, :member?
110
113
  end
111
114
 
@@ -22,7 +22,7 @@ shared_examples "a Solid element" do
22
22
  let(:element) do
23
23
  described_class.context_attribute :current_user
24
24
  Solid::Arguments.stub(:parse).with('ARGUMENTS_STRING')
25
- element = described_class.new('name', 'ARGUMENTS_STRING', ['{% endname %}'])
25
+ element = described_class.parse('name', 'ARGUMENTS_STRING', ['{% endname %}'], {})
26
26
  end
27
27
 
28
28
  it 'should define a custom accessor to the rendered context' do
@@ -42,11 +42,11 @@ shared_examples "a Solid element" do
42
42
 
43
43
  it 'should instanciate a Solid::Arguments with his arguments_string' do
44
44
  Solid::Arguments.should_receive(:parse).with('ARGUMENTS_STRING')
45
- described_class.new('name', 'ARGUMENTS_STRING', ['{% endname %}'])
45
+ described_class.parse('name', 'ARGUMENTS_STRING', ['{% endname %}'], {})
46
46
  end
47
47
 
48
48
  it 'should store his Solid:Arguments instance' do
49
- element = described_class.new('name', '1', ['{% endname %}'])
49
+ element = described_class.parse('name', '1', ['{% endname %}'], {})
50
50
  element.arguments.should be_a(Solid::Arguments)
51
51
  end
52
52
 
@@ -56,7 +56,7 @@ shared_examples "a Solid element" do
56
56
 
57
57
  it 'should force developper to define it in child class' do
58
58
  Solid::Arguments.stub(:parse).with('ARGUMENTS_STRING')
59
- element = described_class.new('name', 'ARGUMENTS_STRING', ['{% endname %}'])
59
+ element = described_class.parse('name', 'ARGUMENTS_STRING', ['{% endname %}'], {})
60
60
  expect{
61
61
  element.display
62
62
  }.to raise_error(NotImplementedError)
@@ -12,7 +12,7 @@ describe Solid::Tag do
12
12
 
13
13
  it_behaves_like "a Solid element"
14
14
 
15
- subject{ DummyTag.new('dummy', '1, "foo", myvar, myopts: false', 'token') }
15
+ subject{ DummyTag.parse('dummy', '1, "foo", myvar, myopts: false', 'token', {}) }
16
16
 
17
17
  it 'should works' do
18
18
  subject.render('myvar' => 'bar').should be == '[1, "foo", "bar", {:myopts=>false}]'
@@ -23,4 +23,4 @@ describe Solid::Tag do
23
23
  subject.render('myvar' => 'bar').should be == 'result'
24
24
  end
25
25
 
26
- end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms-solid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.1
4
+ version: 4.0.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
@@ -10,92 +10,92 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-08 00:00:00.000000000 Z
13
+ date: 2015-01-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - '>='
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - '>='
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - '>='
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '>='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: i18n
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: ruby_parser
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ~>
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
63
  version: '3.2'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ~>
68
+ - - "~>"
69
69
  - !ruby/object:Gem::Version
70
70
  version: '3.2'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: activesupport
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ~>
75
+ - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: '3'
77
+ version: '4.2'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ~>
82
+ - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: '3'
84
+ version: '4.2'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: locomotivecms-liquid
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ~>
89
+ - - '='
90
90
  - !ruby/object:Gem::Version
91
- version: 2.6.0
91
+ version: 4.0.0.alpha
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ~>
96
+ - - '='
97
97
  - !ruby/object:Gem::Version
98
- version: 2.6.0
98
+ version: 4.0.0.alpha
99
99
  description: The Solid gem from the TigerLily team but modified to work with LocomotiveCMS
100
100
  email:
101
101
  - jean.boussier@tigerlilyapps.com
@@ -105,9 +105,9 @@ executables: []
105
105
  extensions: []
106
106
  extra_rdoc_files: []
107
107
  files:
108
- - .gitignore
109
- - .rspec
110
- - .travis.yml
108
+ - ".gitignore"
109
+ - ".rspec"
110
+ - ".travis.yml"
111
111
  - Gemfile
112
112
  - LICENSE
113
113
  - README.md
@@ -167,17 +167,17 @@ require_paths:
167
167
  - lib
168
168
  required_ruby_version: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - '>='
170
+ - - ">="
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - '>='
175
+ - - ">"
176
176
  - !ruby/object:Gem::Version
177
- version: '0'
177
+ version: 1.3.1
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.0.7
180
+ rubygems_version: 2.2.2
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: Helpers for easily creating custom Liquid tags and block