curlybars 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/curlybars/railtie.rb +2 -8
- data/lib/curlybars/version.rb +1 -1
- data/spec/curlybars/rendering_support_spec.rb +12 -12
- data/spec/curlybars/safe_buffer_spec.rb +3 -3
- data/spec/curlybars/template_handler_spec.rb +16 -16
- data/spec/integration/node/block_helper_else_spec.rb +1 -1
- data/spec/integration/node/each_else_spec.rb +12 -12
- data/spec/integration/node/each_spec.rb +11 -11
- data/spec/integration/node/if_else_spec.rb +10 -10
- data/spec/integration/node/if_spec.rb +16 -16
- data/spec/integration/node/unless_else_spec.rb +10 -10
- data/spec/integration/node/unless_spec.rb +14 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d425b234907702e06326b091a5dd9bea96d8a5494796e122ee77c56a79dd63ae
|
4
|
+
data.tar.gz: c23f25a52b8c252ebb5aae349c01faefb7daff9e3e8a112e12f676249ad21f23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63657e140e3377cea321adfb20ff4ff1445e1bb00901e49e5f9b095f65b25b6d89cd2ef814e425f9abc7b0ed62d4d003c52459f8f7810943359f9160a9c64b7a
|
7
|
+
data.tar.gz: 077401e926e847f7ee34df7ebce3a0323ae57c9ce6daa8454b67bc6ce6785807cfe96dfcdf406f8a7928f2d2ba992e344d8a7a8581f32c55e3f0459a82dd1f94
|
data/lib/curlybars/railtie.rb
CHANGED
@@ -1,22 +1,16 @@
|
|
1
1
|
require 'curlybars/template_handler'
|
2
2
|
require 'curlybars/dependency_tracker'
|
3
|
+
require 'action_view/dependency_tracker'
|
3
4
|
|
4
5
|
module Curlybars
|
5
6
|
class Railtie < Rails::Railtie
|
6
7
|
initializer 'curlybars.initialize_template_handler' do
|
7
8
|
ActionView::Template.register_template_handler(:hbs, Curlybars::TemplateHandler)
|
9
|
+
ActionView::DependencyTracker.register_tracker(:hbs, Curlybars::DependencyTracker)
|
8
10
|
end
|
9
11
|
|
10
12
|
initializer 'curlybars.set_cache' do
|
11
13
|
Curlybars.cache = Rails.cache
|
12
14
|
end
|
13
|
-
|
14
|
-
if defined?(CacheDigests::DependencyTracker)
|
15
|
-
CacheDigests::DependencyTracker.register_tracker :hbs, Curlybars::DependencyTracker
|
16
|
-
end
|
17
|
-
|
18
|
-
if defined?(ActionView::DependencyTracker)
|
19
|
-
ActionView::DependencyTracker.register_tracker :hbs, Curlybars::DependencyTracker
|
20
|
-
end
|
21
15
|
end
|
22
16
|
end
|
data/lib/curlybars/version.rb
CHANGED
@@ -71,7 +71,7 @@ describe Curlybars::RenderingSupport do
|
|
71
71
|
describe "#path" do
|
72
72
|
it "returns the method in the current context" do
|
73
73
|
allow_all_methods(presenter)
|
74
|
-
allow(presenter).to receive(:method)
|
74
|
+
allow(presenter).to receive(:method).and_return(:method)
|
75
75
|
|
76
76
|
expect(rendering.path('method', rendering.position(0, 1))).to eq :method
|
77
77
|
end
|
@@ -79,7 +79,7 @@ describe Curlybars::RenderingSupport do
|
|
79
79
|
it "returns the sub presenter method in the current context" do
|
80
80
|
sub = double(:sub_presenter)
|
81
81
|
allow_all_methods(sub)
|
82
|
-
allow(sub).to receive(:method)
|
82
|
+
allow(sub).to receive(:method).and_return(:method)
|
83
83
|
|
84
84
|
allow_all_methods(presenter)
|
85
85
|
allow(presenter).to receive(:sub) { sub }
|
@@ -100,7 +100,7 @@ describe Curlybars::RenderingSupport do
|
|
100
100
|
|
101
101
|
it "raises an exception when the method is not allowed" do
|
102
102
|
disallow_all_methods(presenter)
|
103
|
-
allow(presenter).to receive(:forbidden_method)
|
103
|
+
allow(presenter).to receive(:forbidden_method).and_return(:forbidden_method)
|
104
104
|
|
105
105
|
expect do
|
106
106
|
rendering.path('forbidden_method', rendering.position(0, 1))
|
@@ -109,7 +109,7 @@ describe Curlybars::RenderingSupport do
|
|
109
109
|
|
110
110
|
it "exposes the unallowed method in the exception payload" do
|
111
111
|
disallow_all_methods(presenter)
|
112
|
-
allow(presenter).to receive(:forbidden_method)
|
112
|
+
allow(presenter).to receive(:forbidden_method).and_return(:forbidden_method)
|
113
113
|
|
114
114
|
begin
|
115
115
|
rendering.path('forbidden_method', rendering.position(0, 1))
|
@@ -130,10 +130,10 @@ describe Curlybars::RenderingSupport do
|
|
130
130
|
it "refers to the second to last presenter in the stack when using `../`" do
|
131
131
|
sub = double(:sub_presenter)
|
132
132
|
allow_all_methods(sub)
|
133
|
-
allow(sub).to receive(:method)
|
133
|
+
allow(sub).to receive(:method).and_return(:sub_method)
|
134
134
|
|
135
135
|
allow_all_methods(presenter)
|
136
|
-
allow(presenter).to receive(:method)
|
136
|
+
allow(presenter).to receive(:method).and_return(:root_method)
|
137
137
|
|
138
138
|
contexts.push(sub)
|
139
139
|
|
@@ -143,14 +143,14 @@ describe Curlybars::RenderingSupport do
|
|
143
143
|
it "refers to the third to last presenter in the stack when using `../../`" do
|
144
144
|
sub_sub = double(:sub_presenter)
|
145
145
|
allow_all_methods(sub_sub)
|
146
|
-
allow(sub_sub).to receive(:method)
|
146
|
+
allow(sub_sub).to receive(:method).and_return(:sub_sub_method)
|
147
147
|
|
148
148
|
sub = double(:sub_presenter)
|
149
149
|
allow_all_methods(sub)
|
150
|
-
allow(sub).to receive(:method)
|
150
|
+
allow(sub).to receive(:method).and_return(:sub_method)
|
151
151
|
|
152
152
|
allow_all_methods(presenter)
|
153
|
-
allow(presenter).to receive(:method)
|
153
|
+
allow(presenter).to receive(:method).and_return(:root_method)
|
154
154
|
|
155
155
|
contexts.push(sub)
|
156
156
|
contexts.push(sub_sub)
|
@@ -160,7 +160,7 @@ describe Curlybars::RenderingSupport do
|
|
160
160
|
|
161
161
|
it "returns a method that returns nil, if nil is returned from any method in the chain (except the latter)" do
|
162
162
|
allow_all_methods(presenter)
|
163
|
-
allow(presenter).to receive(:returns_nil)
|
163
|
+
allow(presenter).to receive(:returns_nil).and_return(nil)
|
164
164
|
|
165
165
|
outcome = rendering.path('returns_nil.another_method', rendering.position(0, 1)).call
|
166
166
|
expect(outcome).to be_nil
|
@@ -417,10 +417,10 @@ describe Curlybars::RenderingSupport do
|
|
417
417
|
private
|
418
418
|
|
419
419
|
def allow_all_methods(presenter)
|
420
|
-
allow(presenter).to receive(:allows_method?)
|
420
|
+
allow(presenter).to receive(:allows_method?).and_return(true)
|
421
421
|
end
|
422
422
|
|
423
423
|
def disallow_all_methods(presenter)
|
424
|
-
allow(presenter).to receive(:allows_method?)
|
424
|
+
allow(presenter).to receive(:allows_method?).and_return(false)
|
425
425
|
end
|
426
426
|
end
|
@@ -17,7 +17,7 @@ describe Curlybars::SafeBuffer do
|
|
17
17
|
|
18
18
|
describe "#concat" do
|
19
19
|
it "accepts when (buffer length + the existing output lenght) <= output_limit" do
|
20
|
-
allow(configuration).to receive(:output_limit)
|
20
|
+
allow(configuration).to receive(:output_limit).and_return(10)
|
21
21
|
|
22
22
|
buffer = Curlybars::SafeBuffer.new('*' * 5)
|
23
23
|
|
@@ -27,7 +27,7 @@ describe Curlybars::SafeBuffer do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "raises when (buffer length + the existing output lenght) > output_limit" do
|
30
|
-
allow(configuration).to receive(:output_limit)
|
30
|
+
allow(configuration).to receive(:output_limit).and_return(10)
|
31
31
|
buffer = Curlybars::SafeBuffer.new('*' * 10)
|
32
32
|
|
33
33
|
expect do
|
@@ -36,7 +36,7 @@ describe Curlybars::SafeBuffer do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "raises when buffer length > output_limit" do
|
39
|
-
allow(configuration).to receive(:output_limit)
|
39
|
+
allow(configuration).to receive(:output_limit).and_return(10)
|
40
40
|
|
41
41
|
expect do
|
42
42
|
Curlybars::SafeBuffer.new.concat('*' * 11)
|
@@ -113,44 +113,44 @@ describe Curlybars::TemplateHandler do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
it "passes in the presenter context to the presenter class" do
|
116
|
-
allow(context).to receive(:bar)
|
117
|
-
allow(template).to receive(:source)
|
116
|
+
allow(context).to receive(:bar).and_return("BAR")
|
117
|
+
allow(template).to receive(:source).and_return("{{bar}}")
|
118
118
|
expect(output).to eq("BAR")
|
119
119
|
end
|
120
120
|
|
121
121
|
it "fails if there's no matching presenter class" do
|
122
|
-
allow(template).to receive(:virtual_path)
|
123
|
-
allow(template).to receive(:source)
|
122
|
+
allow(template).to receive(:virtual_path).and_return("missing")
|
123
|
+
allow(template).to receive(:source).and_return(" FOO ")
|
124
124
|
expect { output }.to raise_exception(Curlybars::Error::Presenter::NotFound)
|
125
125
|
end
|
126
126
|
|
127
127
|
it "allows calling public methods on the presenter" do
|
128
|
-
allow(template).to receive(:source)
|
128
|
+
allow(template).to receive(:source).and_return("{{foo}}")
|
129
129
|
expect(output).to eq("FOO")
|
130
130
|
end
|
131
131
|
|
132
132
|
it "marks its output as HTML safe" do
|
133
|
-
allow(template).to receive(:source)
|
133
|
+
allow(template).to receive(:source).and_return("{{foo}}")
|
134
134
|
expect(output).to be_html_safe
|
135
135
|
end
|
136
136
|
|
137
137
|
it "calls the #setup! method before rendering the view" do
|
138
|
-
allow(template).to receive(:source)
|
138
|
+
allow(template).to receive(:source).and_return("{{foo}}")
|
139
139
|
output
|
140
140
|
expect(context.content_for(:foo)).to eq("bar")
|
141
141
|
end
|
142
142
|
|
143
143
|
describe "caching" do
|
144
144
|
before do
|
145
|
-
allow(template).to receive(:source)
|
146
|
-
allow(context).to receive(:bar)
|
145
|
+
allow(template).to receive(:source).and_return("{{bar}}")
|
146
|
+
allow(context).to receive(:bar).and_return("BAR")
|
147
147
|
end
|
148
148
|
|
149
149
|
it "caches the result with the #cache_key from the presenter" do
|
150
150
|
context.assigns[:cache_key] = "x"
|
151
151
|
expect(output).to eq("BAR")
|
152
152
|
|
153
|
-
allow(context).to receive(:bar)
|
153
|
+
allow(context).to receive(:bar).and_return("BAZ")
|
154
154
|
expect(output).to eq("BAR")
|
155
155
|
|
156
156
|
context.assigns[:cache_key] = "y"
|
@@ -161,7 +161,7 @@ describe Curlybars::TemplateHandler do
|
|
161
161
|
context.assigns[:cache_key] = nil
|
162
162
|
expect(output).to eq("BAR")
|
163
163
|
|
164
|
-
allow(context).to receive(:bar)
|
164
|
+
allow(context).to receive(:bar).and_return("BAZ")
|
165
165
|
expect(output).to eq("BAZ")
|
166
166
|
end
|
167
167
|
|
@@ -169,13 +169,13 @@ describe Curlybars::TemplateHandler do
|
|
169
169
|
# Make sure caching is enabled
|
170
170
|
context.assigns[:cache_key] = "x"
|
171
171
|
|
172
|
-
allow(presenter_class).to receive(:cache_key)
|
172
|
+
allow(presenter_class).to receive(:cache_key).and_return("foo")
|
173
173
|
|
174
174
|
expect(output).to eq("BAR")
|
175
175
|
|
176
|
-
allow(presenter_class).to receive(:cache_key)
|
176
|
+
allow(presenter_class).to receive(:cache_key).and_return("bar")
|
177
177
|
|
178
|
-
allow(context).to receive(:bar)
|
178
|
+
allow(context).to receive(:bar).and_return("FOOBAR")
|
179
179
|
expect(output).to eq("FOOBAR")
|
180
180
|
end
|
181
181
|
|
@@ -185,7 +185,7 @@ describe Curlybars::TemplateHandler do
|
|
185
185
|
|
186
186
|
expect(output).to eq("BAR")
|
187
187
|
|
188
|
-
allow(context).to receive(:bar)
|
188
|
+
allow(context).to receive(:bar).and_return("FOO")
|
189
189
|
|
190
190
|
# Cached fragment has not yet expired.
|
191
191
|
context.advance_clock(41)
|
@@ -202,7 +202,7 @@ describe Curlybars::TemplateHandler do
|
|
202
202
|
|
203
203
|
expect(output).to eq("BAR")
|
204
204
|
|
205
|
-
allow(context).to receive(:bar)
|
205
|
+
allow(context).to receive(:bar).and_return("FOO")
|
206
206
|
|
207
207
|
# Cached fragment has not yet expired.
|
208
208
|
context.advance_clock(41)
|
@@ -233,7 +233,7 @@ describe "{{#helper arg1 arg2 ... key=value ...}}...<{{else}}>...{{/helper}}" do
|
|
233
233
|
let(:presenter_class) { double(:presenter_class) }
|
234
234
|
|
235
235
|
it "without errors when global helper" do
|
236
|
-
allow(Curlybars.configuration).to receive(:global_helpers_provider_classes)
|
236
|
+
allow(Curlybars.configuration).to receive(:global_helpers_provider_classes).and_return([IntegrationTest::GlobalHelperProvider])
|
237
237
|
|
238
238
|
dependency_tree = {}
|
239
239
|
|
@@ -6,7 +6,7 @@ describe "{{#each collection}}...{{else}}...{{/each}}" do
|
|
6
6
|
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
7
|
|
8
8
|
it "uses each_template when collection is not empty" do
|
9
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_collection)
|
9
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_collection).and_return(true)
|
10
10
|
allow(presenter).to receive(:non_empty_collection) { [presenter] }
|
11
11
|
|
12
12
|
template = Curlybars.compile(<<-HBS)
|
@@ -23,8 +23,8 @@ describe "{{#each collection}}...{{else}}...{{/each}}" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "uses else_template when collection is empty" do
|
26
|
-
allow(presenter).to receive(:allows_method?).with(:empty_collection)
|
27
|
-
allow(presenter).to receive(:empty_collection)
|
26
|
+
allow(presenter).to receive(:allows_method?).with(:empty_collection).and_return(true)
|
27
|
+
allow(presenter).to receive(:empty_collection).and_return([])
|
28
28
|
|
29
29
|
template = Curlybars.compile(<<-HBS)
|
30
30
|
{{#each empty_collection}}
|
@@ -51,7 +51,7 @@ describe "{{#each collection}}...{{else}}...{{/each}}" do
|
|
51
51
|
a_path_presenter = path_presenter_class.new(nil, path: 'a_path')
|
52
52
|
another_path_presenter = path_presenter_class.new(nil, path: 'another_path')
|
53
53
|
|
54
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_collection)
|
54
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_collection).and_return(true)
|
55
55
|
allow(presenter).to receive(:non_empty_collection) { [a_path_presenter, another_path_presenter] }
|
56
56
|
|
57
57
|
template = Curlybars.compile(<<-HBS)
|
@@ -69,8 +69,8 @@ describe "{{#each collection}}...{{else}}...{{/each}}" do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "allows empty each_template" do
|
72
|
-
allow(presenter).to receive(:allows_method?).with(:empty_collection)
|
73
|
-
allow(presenter).to receive(:empty_collection)
|
72
|
+
allow(presenter).to receive(:allows_method?).with(:empty_collection).and_return(true)
|
73
|
+
allow(presenter).to receive(:empty_collection).and_return([])
|
74
74
|
|
75
75
|
template = Curlybars.compile(<<-HBS)
|
76
76
|
{{#each empty_collection}}{{else}}
|
@@ -84,7 +84,7 @@ describe "{{#each collection}}...{{else}}...{{/each}}" do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "allows empty else_template" do
|
87
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_collection)
|
87
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_collection).and_return(true)
|
88
88
|
allow(presenter).to receive(:non_empty_collection) { [presenter] }
|
89
89
|
|
90
90
|
template = Curlybars.compile(<<-HBS)
|
@@ -99,7 +99,7 @@ describe "{{#each collection}}...{{else}}...{{/each}}" do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it "allows empty each_template and else_template" do
|
102
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_collection)
|
102
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_collection).and_return(true)
|
103
103
|
allow(presenter).to receive(:non_empty_collection) { [presenter] }
|
104
104
|
|
105
105
|
template = Curlybars.compile(<<-HBS)
|
@@ -124,8 +124,8 @@ describe "{{#each collection}}...{{else}}...{{/each}}" do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
it "raises an error if the context is not an array-like object" do
|
127
|
-
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:not_a_collection)
|
128
|
-
allow(presenter).to receive(:not_a_collection)
|
127
|
+
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:not_a_collection).and_return(true)
|
128
|
+
allow(presenter).to receive(:not_a_collection).and_return("string")
|
129
129
|
|
130
130
|
template = Curlybars.compile(<<-HBS)
|
131
131
|
{{#each not_a_collection}}{{else}}{{/each}}
|
@@ -137,8 +137,8 @@ describe "{{#each collection}}...{{else}}...{{/each}}" do
|
|
137
137
|
end
|
138
138
|
|
139
139
|
it "raises an error if the objects inside of the context array are not presenters" do
|
140
|
-
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:not_a_presenter_collection)
|
141
|
-
allow(presenter).to receive(:not_a_presenter_collection)
|
140
|
+
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:not_a_presenter_collection).and_return(true)
|
141
|
+
allow(presenter).to receive(:not_a_presenter_collection).and_return([:an_element])
|
142
142
|
|
143
143
|
template = Curlybars.compile(<<-HBS)
|
144
144
|
{{#each not_a_presenter_collection}}{{else}}{{/each}}
|
@@ -6,7 +6,7 @@ describe "{{#each collection}}...{{/each}}" do
|
|
6
6
|
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
7
|
|
8
8
|
it "uses each_template when collection is not empty" do
|
9
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_collection)
|
9
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_collection).and_return(true)
|
10
10
|
allow(presenter).to receive(:non_empty_collection) { [presenter] }
|
11
11
|
|
12
12
|
template = Curlybars.compile(<<-HBS)
|
@@ -21,8 +21,8 @@ describe "{{#each collection}}...{{/each}}" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "doesn't use each_template when collection is empty" do
|
24
|
-
allow(presenter).to receive(:allows_method?).with(:empty_collection)
|
25
|
-
allow(presenter).to receive(:empty_collection)
|
24
|
+
allow(presenter).to receive(:allows_method?).with(:empty_collection).and_return(true)
|
25
|
+
allow(presenter).to receive(:empty_collection).and_return([])
|
26
26
|
|
27
27
|
template = Curlybars.compile(<<-HBS)
|
28
28
|
{{#each empty_collection}}
|
@@ -34,7 +34,7 @@ describe "{{#each collection}}...{{/each}}" do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "allows empty each_template" do
|
37
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_collection)
|
37
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_collection).and_return(true)
|
38
38
|
allow(presenter).to receive(:non_empty_collection) { [presenter] }
|
39
39
|
|
40
40
|
template = Curlybars.compile(<<-HBS)
|
@@ -56,7 +56,7 @@ describe "{{#each collection}}...{{/each}}" do
|
|
56
56
|
a_path_presenter = path_presenter_class.new(nil, path: 'a_path')
|
57
57
|
another_path_presenter = path_presenter_class.new(nil, path: 'another_path')
|
58
58
|
|
59
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_collection)
|
59
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_collection).and_return(true)
|
60
60
|
allow(presenter).to receive(:non_empty_collection) { [a_path_presenter, another_path_presenter] }
|
61
61
|
|
62
62
|
template = Curlybars.compile(<<-HBS)
|
@@ -83,7 +83,7 @@ describe "{{#each collection}}...{{/each}}" do
|
|
83
83
|
a_path_presenter = path_presenter_class.new(nil, path: 'a_path')
|
84
84
|
another_path_presenter = path_presenter_class.new(nil, path: 'another_path')
|
85
85
|
|
86
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_hash)
|
86
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_hash).and_return(true)
|
87
87
|
allow(presenter).to receive(:non_empty_hash) do
|
88
88
|
{ first: a_path_presenter, second: another_path_presenter }
|
89
89
|
end
|
@@ -101,8 +101,8 @@ describe "{{#each collection}}...{{/each}}" do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
it "raises an error if the context is not an array-like object" do
|
104
|
-
allow(presenter).to receive(:allows_method?).with(:not_a_collection)
|
105
|
-
allow(presenter).to receive(:not_a_collection)
|
104
|
+
allow(presenter).to receive(:allows_method?).with(:not_a_collection).and_return(true)
|
105
|
+
allow(presenter).to receive(:not_a_collection).and_return("string")
|
106
106
|
|
107
107
|
template = Curlybars.compile(<<-HBS)
|
108
108
|
{{#each not_a_collection}}{{/each}}
|
@@ -206,7 +206,7 @@ describe "{{#each collection}}...{{/each}}" do
|
|
206
206
|
a_path_presenter = path_presenter_class.new(nil, path: 'a_path')
|
207
207
|
another_path_presenter = path_presenter_class.new(nil, path: 'another_path')
|
208
208
|
|
209
|
-
allow(presenter).to receive(:allows_method?).with(:non_empty_hash)
|
209
|
+
allow(presenter).to receive(:allows_method?).with(:non_empty_hash).and_return(true)
|
210
210
|
allow(presenter).to receive(:non_empty_hash) do
|
211
211
|
{ first: a_path_presenter, second: another_path_presenter }
|
212
212
|
end
|
@@ -224,8 +224,8 @@ describe "{{#each collection}}...{{/each}}" do
|
|
224
224
|
end
|
225
225
|
|
226
226
|
it "raises an error if the objects inside of the context array are not presenters" do
|
227
|
-
allow(presenter).to receive(:allows_method?).with(:not_a_presenter_collection)
|
228
|
-
allow(presenter).to receive(:not_a_presenter_collection)
|
227
|
+
allow(presenter).to receive(:allows_method?).with(:not_a_presenter_collection).and_return(true)
|
228
|
+
allow(presenter).to receive(:not_a_presenter_collection).and_return([:an_element])
|
229
229
|
|
230
230
|
template = Curlybars.compile(<<-HBS)
|
231
231
|
{{#each not_a_presenter_collection}}{{/each}}
|
@@ -6,8 +6,8 @@ describe "{{#if}}...{{else}}...{{/if}}" do
|
|
6
6
|
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
7
|
|
8
8
|
it "renders the if_template" do
|
9
|
-
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:return_true)
|
10
|
-
allow(presenter).to receive(:return_true)
|
9
|
+
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:return_true).and_return(true)
|
10
|
+
allow(presenter).to receive(:return_true).and_return(true)
|
11
11
|
|
12
12
|
template = Curlybars.compile(<<-HBS)
|
13
13
|
{{#if return_true}}
|
@@ -23,8 +23,8 @@ describe "{{#if}}...{{else}}...{{/if}}" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "renders the else_template" do
|
26
|
-
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:return_false)
|
27
|
-
allow(presenter).to receive(:return_false)
|
26
|
+
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:return_false).and_return(true)
|
27
|
+
allow(presenter).to receive(:return_false).and_return(false)
|
28
28
|
|
29
29
|
template = Curlybars.compile(<<-HBS)
|
30
30
|
{{#if return_false}}
|
@@ -40,8 +40,8 @@ describe "{{#if}}...{{else}}...{{/if}}" do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "allows empty if_template" do
|
43
|
-
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:valid)
|
44
|
-
allow(presenter).to receive(:valid)
|
43
|
+
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
44
|
+
allow(presenter).to receive(:valid).and_return(false)
|
45
45
|
|
46
46
|
template = Curlybars.compile(<<-HBS)
|
47
47
|
{{#if valid}}{{else}}
|
@@ -55,8 +55,8 @@ describe "{{#if}}...{{else}}...{{/if}}" do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "allows empty else_template" do
|
58
|
-
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:valid)
|
59
|
-
allow(presenter).to receive(:valid)
|
58
|
+
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
59
|
+
allow(presenter).to receive(:valid).and_return(true)
|
60
60
|
|
61
61
|
template = Curlybars.compile(<<-HBS)
|
62
62
|
{{#if valid}}
|
@@ -70,8 +70,8 @@ describe "{{#if}}...{{else}}...{{/if}}" do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "allows empty if_template and else_template" do
|
73
|
-
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:valid)
|
74
|
-
allow(presenter).to receive(:valid)
|
73
|
+
allow(IntegrationTest::Presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
74
|
+
allow(presenter).to receive(:valid).and_return(true)
|
75
75
|
|
76
76
|
template = Curlybars.compile(<<-HBS)
|
77
77
|
{{#if valid}}{{else}}{{/if}}
|
@@ -6,8 +6,8 @@ describe "{{#if}}...{{/if}}" do
|
|
6
6
|
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
7
|
|
8
8
|
it "returns positive branch when condition is true" do
|
9
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
10
|
-
allow(presenter).to receive(:valid)
|
9
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
10
|
+
allow(presenter).to receive(:valid).and_return(true)
|
11
11
|
|
12
12
|
template = Curlybars.compile(<<-HBS)
|
13
13
|
{{#if valid}}
|
@@ -21,8 +21,8 @@ describe "{{#if}}...{{/if}}" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "doesn't return positive branch when condition is false" do
|
24
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
25
|
-
allow(presenter).to receive(:valid)
|
24
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
25
|
+
allow(presenter).to receive(:valid).and_return(false)
|
26
26
|
|
27
27
|
template = Curlybars.compile(<<-HBS)
|
28
28
|
{{#if valid}}
|
@@ -34,8 +34,8 @@ describe "{{#if}}...{{/if}}" do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "doesn't return positive branch when condition is empty array" do
|
37
|
-
allow(presenter).to receive(:allows_method?).with(:collection)
|
38
|
-
allow(presenter).to receive(:collection)
|
37
|
+
allow(presenter).to receive(:allows_method?).with(:collection).and_return(true)
|
38
|
+
allow(presenter).to receive(:collection).and_return([])
|
39
39
|
|
40
40
|
template = Curlybars.compile(<<-HBS)
|
41
41
|
{{#if collection}}
|
@@ -47,10 +47,10 @@ describe "{{#if}}...{{/if}}" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "works with nested `if blocks` (double positive)" do
|
50
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
51
|
-
allow(presenter).to receive(:allows_method?).with(:visible)
|
52
|
-
allow(presenter).to receive(:valid)
|
53
|
-
allow(presenter).to receive(:visible)
|
50
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
51
|
+
allow(presenter).to receive(:allows_method?).with(:visible).and_return(true)
|
52
|
+
allow(presenter).to receive(:valid).and_return(true)
|
53
|
+
allow(presenter).to receive(:visible).and_return(true)
|
54
54
|
|
55
55
|
template = Curlybars.compile(<<-HBS)
|
56
56
|
{{#if valid}}
|
@@ -68,10 +68,10 @@ describe "{{#if}}...{{/if}}" do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "works with nested `if blocks` (positive and negative)" do
|
71
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
72
|
-
allow(presenter).to receive(:allows_method?).with(:visible)
|
73
|
-
allow(presenter).to receive(:valid)
|
74
|
-
allow(presenter).to receive(:visible)
|
71
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
72
|
+
allow(presenter).to receive(:allows_method?).with(:visible).and_return(true)
|
73
|
+
allow(presenter).to receive(:valid).and_return(true)
|
74
|
+
allow(presenter).to receive(:visible).and_return(false)
|
75
75
|
|
76
76
|
template = Curlybars.compile(<<-HBS)
|
77
77
|
{{#if valid}}
|
@@ -88,8 +88,8 @@ describe "{{#if}}...{{/if}}" do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
it "allows empty if_template" do
|
91
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
92
|
-
allow(presenter).to receive(:valid)
|
91
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
92
|
+
allow(presenter).to receive(:valid).and_return(true)
|
93
93
|
|
94
94
|
template = Curlybars.compile(<<-HBS)
|
95
95
|
{{#if valid}}{{/if}}
|
@@ -6,8 +6,8 @@ describe "{{#unless}}...{{else}}...{{/unless}}" do
|
|
6
6
|
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
7
|
|
8
8
|
it "renders the unless_template" do
|
9
|
-
allow(presenter).to receive(:allows_method?).with(:condition)
|
10
|
-
allow(presenter).to receive(:condition)
|
9
|
+
allow(presenter).to receive(:allows_method?).with(:condition).and_return(true)
|
10
|
+
allow(presenter).to receive(:condition).and_return(false)
|
11
11
|
|
12
12
|
template = Curlybars.compile(<<-HBS)
|
13
13
|
{{#unless condition}}
|
@@ -23,8 +23,8 @@ describe "{{#unless}}...{{else}}...{{/unless}}" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "renders the else_template" do
|
26
|
-
allow(presenter).to receive(:allows_method?).with(:condition)
|
27
|
-
allow(presenter).to receive(:condition)
|
26
|
+
allow(presenter).to receive(:allows_method?).with(:condition).and_return(true)
|
27
|
+
allow(presenter).to receive(:condition).and_return(true)
|
28
28
|
|
29
29
|
template = Curlybars.compile(<<-HBS)
|
30
30
|
{{#unless condition}}
|
@@ -40,8 +40,8 @@ describe "{{#unless}}...{{else}}...{{/unless}}" do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "allows empty else_template" do
|
43
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
44
|
-
allow(presenter).to receive(:valid)
|
43
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
44
|
+
allow(presenter).to receive(:valid).and_return(false)
|
45
45
|
|
46
46
|
template = Curlybars.compile(<<-HBS)
|
47
47
|
{{#unless valid}}
|
@@ -55,8 +55,8 @@ describe "{{#unless}}...{{else}}...{{/unless}}" do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "allows empty unless_template" do
|
58
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
59
|
-
allow(presenter).to receive(:valid)
|
58
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
59
|
+
allow(presenter).to receive(:valid).and_return(true)
|
60
60
|
|
61
61
|
template = Curlybars.compile(<<-HBS)
|
62
62
|
{{#unless valid}}{{else}}
|
@@ -70,8 +70,8 @@ describe "{{#unless}}...{{else}}...{{/unless}}" do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "allows empty unless_template and else_template" do
|
73
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
74
|
-
allow(presenter).to receive(:valid)
|
73
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
74
|
+
allow(presenter).to receive(:valid).and_return(false)
|
75
75
|
|
76
76
|
template = Curlybars.compile(<<-HBS)
|
77
77
|
{{#unless valid}}{{else}}{{/unless}}
|
@@ -6,8 +6,8 @@ describe "{{#unless}}...{{/unless}}" do
|
|
6
6
|
let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
|
7
7
|
|
8
8
|
it "returns unless_template when condition is false" do
|
9
|
-
allow(presenter).to receive(:allows_method?).with(:condition)
|
10
|
-
allow(presenter).to receive(:condition)
|
9
|
+
allow(presenter).to receive(:allows_method?).with(:condition).and_return(true)
|
10
|
+
allow(presenter).to receive(:condition).and_return(false)
|
11
11
|
|
12
12
|
template = Curlybars.compile(<<-HBS)
|
13
13
|
{{#unless condition}}
|
@@ -21,8 +21,8 @@ describe "{{#unless}}...{{/unless}}" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "doesn't return unless_template when condition is true" do
|
24
|
-
allow(presenter).to receive(:allows_method?).with(:condition)
|
25
|
-
allow(presenter).to receive(:condition)
|
24
|
+
allow(presenter).to receive(:allows_method?).with(:condition).and_return(true)
|
25
|
+
allow(presenter).to receive(:condition).and_return(true)
|
26
26
|
|
27
27
|
template = Curlybars.compile(<<-HBS)
|
28
28
|
{{#unless condition}}
|
@@ -34,10 +34,10 @@ describe "{{#unless}}...{{/unless}}" do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "works with nested unless blocks (double negative)" do
|
37
|
-
allow(presenter).to receive(:allows_method?).with(:first_condition)
|
38
|
-
allow(presenter).to receive(:allows_method?).with(:second_condition)
|
39
|
-
allow(presenter).to receive(:first_condition)
|
40
|
-
allow(presenter).to receive(:second_condition)
|
37
|
+
allow(presenter).to receive(:allows_method?).with(:first_condition).and_return(true)
|
38
|
+
allow(presenter).to receive(:allows_method?).with(:second_condition).and_return(true)
|
39
|
+
allow(presenter).to receive(:first_condition).and_return(false)
|
40
|
+
allow(presenter).to receive(:second_condition).and_return(false)
|
41
41
|
|
42
42
|
template = Curlybars.compile(<<-HBS)
|
43
43
|
{{#unless first_condition}}
|
@@ -55,8 +55,8 @@ describe "{{#unless}}...{{/unless}}" do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "allows empty unless_template" do
|
58
|
-
allow(presenter).to receive(:allows_method?).with(:valid)
|
59
|
-
allow(presenter).to receive(:valid)
|
58
|
+
allow(presenter).to receive(:allows_method?).with(:valid).and_return(true)
|
59
|
+
allow(presenter).to receive(:valid).and_return(true)
|
60
60
|
|
61
61
|
template = Curlybars.compile(<<-HBS)
|
62
62
|
{{#unless valid}}{{/unless}}
|
@@ -66,10 +66,10 @@ describe "{{#unless}}...{{/unless}}" do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "works with nested unless blocks (negative and positive)" do
|
69
|
-
allow(presenter).to receive(:allows_method?).with(:first_condition)
|
70
|
-
allow(presenter).to receive(:allows_method?).with(:second_condition)
|
71
|
-
allow(presenter).to receive(:first_condition)
|
72
|
-
allow(presenter).to receive(:second_condition)
|
69
|
+
allow(presenter).to receive(:allows_method?).with(:first_condition).and_return(true)
|
70
|
+
allow(presenter).to receive(:allows_method?).with(:second_condition).and_return(true)
|
71
|
+
allow(presenter).to receive(:first_condition).and_return(false)
|
72
|
+
allow(presenter).to receive(:second_condition).and_return(true)
|
73
73
|
|
74
74
|
template = Curlybars.compile(<<-HBS)
|
75
75
|
{{#unless first_condition}}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curlybars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Libo Cannici
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2018-10-
|
16
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: actionpack
|