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 +4 -4
- data/Gemfile +1 -1
- data/lib/solid/conditional_block.rb +16 -17
- data/lib/solid/default_security_rules.rb +4 -0
- data/lib/solid/element.rb +3 -3
- data/lib/solid/liquid_extensions/assign_tag.rb +2 -2
- data/lib/solid/liquid_extensions/if_tag.rb +17 -6
- data/lib/solid/liquid_extensions/unless_tag.rb +2 -2
- data/lib/solid/liquid_extensions/variable.rb +3 -1
- data/lib/solid/version.rb +1 -1
- data/locomotivecms-solid.gemspec +3 -2
- data/spec/solid/block_spec.rb +1 -1
- data/spec/solid/conditional_block_spec.rb +13 -6
- data/spec/solid/default_security_rules_spec.rb +4 -1
- data/spec/solid/element_examples.rb +4 -4
- data/spec/solid/tag_spec.rb +2 -2
- metadata +25 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e66c02929c30ed50d56ae70f03eda812d1f3415
|
4
|
+
data.tar.gz: 26cbcbbd0795d27181ff58b45749e654129e17fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41ea08b22297efb4f658a297934b6f46444ecbf9295d0af64877ef1a971718e235f15200553883e2025059c1f961b047ad4a9ae49e545827f5e3421cec962828
|
7
|
+
data.tar.gz: 0d639fee1c41c8300dd77db23d2f495eb54d4617d5e4a8afde50f10408293e5588b3d3c99c0ef2d2629d389385b271a3a61569aaec3985894daa2a470e7c4fb3
|
data/Gemfile
CHANGED
@@ -1,35 +1,34 @@
|
|
1
1
|
class Solid::ConditionalBlock < Liquid::Block
|
2
|
-
include Solid::Element
|
3
2
|
|
4
|
-
|
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
|
-
|
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
|
-
|
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) &&
|
data/lib/solid/element.rb
CHANGED
@@ -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,
|
9
|
-
|
10
|
-
|
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,
|
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,
|
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,
|
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,
|
20
|
+
@blocks.each do |expression, body|
|
18
21
|
if expression.evaluate(context)
|
19
|
-
return
|
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
|
-
|
38
|
-
|
39
|
-
@
|
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,
|
8
|
-
super(tag_name, "!(#{expression})",
|
7
|
+
def initialize(tag_name, expression, options)
|
8
|
+
super(tag_name, "!(#{expression})", options)
|
9
9
|
end
|
10
10
|
|
11
11
|
end
|
data/lib/solid/version.rb
CHANGED
data/locomotivecms-solid.gemspec
CHANGED
@@ -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", "~>
|
23
|
+
s.add_development_dependency "activesupport", "~> 4.2"
|
24
24
|
|
25
|
-
|
25
|
+
# TODO
|
26
|
+
s.add_runtime_dependency "locomotivecms-liquid", "4.0.0.alpha"
|
26
27
|
end
|
data/spec/solid/block_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe Solid::Block do
|
|
20
20
|
|
21
21
|
let(:tokens) { ["dummy", "{% enddummy %}", "outside"] }
|
22
22
|
|
23
|
-
subject{ DummyBlock.
|
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(:
|
19
|
+
let(:template) { "{% ifpresent mystring %}present{% else %}blank{% endifpresent %}"}
|
18
20
|
|
19
|
-
subject{
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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.
|
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.
|
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.
|
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.
|
59
|
+
element = described_class.parse('name', 'ARGUMENTS_STRING', ['{% endname %}'], {})
|
60
60
|
expect{
|
61
61
|
element.display
|
62
62
|
}.to raise_error(NotImplementedError)
|
data/spec/solid/tag_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Solid::Tag do
|
|
12
12
|
|
13
13
|
it_behaves_like "a Solid element"
|
14
14
|
|
15
|
-
subject{ DummyTag.
|
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.
|
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:
|
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: '
|
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: '
|
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:
|
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:
|
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:
|
177
|
+
version: 1.3.1
|
178
178
|
requirements: []
|
179
179
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.
|
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
|