curlybars 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/curlybars/error/lex.rb +1 -1
  3. data/lib/curlybars/error/parse.rb +1 -1
  4. data/lib/curlybars/node/path.rb +11 -13
  5. data/lib/curlybars/presenter.rb +2 -2
  6. data/lib/curlybars/template_handler.rb +3 -11
  7. data/lib/curlybars/version.rb +1 -1
  8. metadata +17 -93
  9. data/spec/acceptance/application_layout_spec.rb +0 -60
  10. data/spec/acceptance/collection_blocks_spec.rb +0 -28
  11. data/spec/acceptance/global_helper_spec.rb +0 -25
  12. data/spec/curlybars/configuration_spec.rb +0 -57
  13. data/spec/curlybars/error/base_spec.rb +0 -41
  14. data/spec/curlybars/error/compile_spec.rb +0 -19
  15. data/spec/curlybars/error/lex_spec.rb +0 -25
  16. data/spec/curlybars/error/parse_spec.rb +0 -74
  17. data/spec/curlybars/error/render_spec.rb +0 -19
  18. data/spec/curlybars/error/validate_spec.rb +0 -19
  19. data/spec/curlybars/lexer_spec.rb +0 -490
  20. data/spec/curlybars/method_whitelist_spec.rb +0 -299
  21. data/spec/curlybars/processor/tilde_spec.rb +0 -60
  22. data/spec/curlybars/rendering_support_spec.rb +0 -421
  23. data/spec/curlybars/safe_buffer_spec.rb +0 -46
  24. data/spec/curlybars/template_handler_spec.rb +0 -225
  25. data/spec/integration/cache_spec.rb +0 -126
  26. data/spec/integration/comment_spec.rb +0 -60
  27. data/spec/integration/exception_spec.rb +0 -31
  28. data/spec/integration/node/block_helper_else_spec.rb +0 -420
  29. data/spec/integration/node/each_else_spec.rb +0 -408
  30. data/spec/integration/node/each_spec.rb +0 -289
  31. data/spec/integration/node/escape_spec.rb +0 -27
  32. data/spec/integration/node/helper_spec.rb +0 -186
  33. data/spec/integration/node/if_else_spec.rb +0 -170
  34. data/spec/integration/node/if_spec.rb +0 -153
  35. data/spec/integration/node/output_spec.rb +0 -66
  36. data/spec/integration/node/partial_spec.rb +0 -64
  37. data/spec/integration/node/path_spec.rb +0 -296
  38. data/spec/integration/node/root_spec.rb +0 -13
  39. data/spec/integration/node/sub_expression_spec.rb +0 -426
  40. data/spec/integration/node/template_spec.rb +0 -84
  41. data/spec/integration/node/unless_else_spec.rb +0 -139
  42. data/spec/integration/node/unless_spec.rb +0 -128
  43. data/spec/integration/node/with_spec.rb +0 -178
  44. data/spec/integration/processor/tilde_spec.rb +0 -38
  45. data/spec/integration/processors_spec.rb +0 -29
  46. data/spec/integration/visitor_spec.rb +0 -154
@@ -1,296 +0,0 @@
1
- describe "{{path}}" do
2
- let(:global_helpers_providers) { [] }
3
-
4
- describe "#compile" do
5
- let(:post) { double("post") }
6
- let(:presenter) { IntegrationTest::Presenter.new(double("view_context"), post: post) }
7
-
8
- it "evaluates the methods chain call" do
9
- template = Curlybars.compile(<<-HBS)
10
- {{user.avatar.url}}
11
- HBS
12
-
13
- expect(eval(template)).to resemble(<<-HTML)
14
- http://example.com/foo.png
15
- HTML
16
- end
17
-
18
- it "is tolerant to paths that return `nil`" do
19
- template = Curlybars.compile(<<-HBS)
20
- {{return_nil.property}}
21
- HBS
22
-
23
- expect(eval(template)).to resemble("")
24
- end
25
-
26
- it "{{../path}} is evaluated on the second to last context in the stack" do
27
- template = Curlybars.compile(<<-HBS)
28
- {{#with user.avatar}}
29
- {{../context}}
30
- {{/with}}
31
- HBS
32
-
33
- expect(eval(template)).to resemble(<<-HTML)
34
- root_context
35
- HTML
36
- end
37
-
38
- it "{{-a-path-}} is a valid path" do
39
- template = Curlybars.compile(<<-HBS)
40
- {{-a-path-}}
41
- HBS
42
-
43
- expect(eval(template)).to resemble(<<-HTML)
44
- a path, whose name contains underscores
45
- HTML
46
- end
47
-
48
- it "{{../../path}} is evaluated on the third to last context in the stack" do
49
- template = Curlybars.compile(<<-HBS)
50
- {{#with user}}
51
- {{#with avatar}}
52
- {{../../context}}
53
- {{/with}}
54
- {{/with}}
55
- HBS
56
-
57
- expect(eval(template)).to resemble(<<-HTML)
58
- root_context
59
- HTML
60
- end
61
-
62
- it "{{../path}} uses the right context, even when using the same name" do
63
- template = Curlybars.compile(<<-HBS)
64
- {{#with user}}
65
- {{#with avatar}}
66
- {{../context}}
67
- {{/with}}
68
- {{../context}}
69
- {{/with}}
70
- HBS
71
-
72
- expect(eval(template)).to resemble(<<-HTML)
73
- user_context
74
- root_context
75
- HTML
76
- end
77
-
78
- it "a path with more `../` than the stack size will resolve to empty string" do
79
- template = Curlybars.compile(<<-HBS)
80
- {{context}}
81
- {{../context}}
82
- {{../../context}}
83
- HBS
84
-
85
- expect(eval(template)).to resemble(<<-HTML)
86
- root_context
87
- HTML
88
- end
89
-
90
- it "understands `this` as the current presenter" do
91
- template = Curlybars.compile(<<-HBS)
92
- {{user.avatar.url}}
93
- {{#with this}}
94
- {{user.avatar.url}}
95
- {{/with}}
96
- HBS
97
-
98
- expect(eval(template)).to resemble(<<-HTML)
99
- http://example.com/foo.png
100
- http://example.com/foo.png
101
- HTML
102
- end
103
-
104
- it "understands `length` as allowed method on a collection" do
105
- template = Curlybars.compile(<<-HBS)
106
- {{array_of_users.length}}
107
- HBS
108
-
109
- expect(eval(template)).to resemble(<<-HTML)
110
- 1
111
- HTML
112
- end
113
-
114
- it "raises when trying to call methods not implemented on context" do
115
- template = Curlybars.compile(<<-HBS)
116
- {{not_in_whitelist}}
117
- HBS
118
-
119
- expect do
120
- eval(eval(template))
121
- end.to raise_error(Curlybars::Error::Render)
122
- end
123
- end
124
-
125
- describe "#validate" do
126
- it "without errors" do
127
- dependency_tree = { sub_context: {}, outer_field: nil }
128
-
129
- source = <<-HBS
130
- {{#with sub_context}}
131
- {{../outer_field}}
132
- {{/with}}
133
- HBS
134
-
135
- errors = Curlybars.validate(dependency_tree, source)
136
-
137
- expect(errors).to be_empty
138
- end
139
-
140
- it "gives errors errors when it goes out of context" do
141
- dependency_tree = {}
142
-
143
- source = <<-HBS
144
- {{../outer_field}}
145
- HBS
146
-
147
- errors = Curlybars.validate(dependency_tree, source)
148
-
149
- expect(errors).not_to be_empty
150
- end
151
-
152
- it "without errors using `this`" do
153
- dependency_tree = { field: nil }
154
-
155
- source = <<-HBS
156
- {{#with this}}
157
- {{field}}
158
- {{/with}}
159
- HBS
160
-
161
- errors = Curlybars.validate(dependency_tree, source)
162
-
163
- expect(errors).to be_empty
164
- end
165
-
166
- it "without errors using `length` on a collection of presenters" do
167
- dependency_tree = { collection_of_presenters: [{}] }
168
-
169
- source = <<-HBS
170
- {{collection_of_presenters.length}}
171
- HBS
172
-
173
- errors = Curlybars.validate(dependency_tree, source)
174
-
175
- expect(errors).to be_empty
176
- end
177
-
178
- it "with errors using `length` on anything else than a collection" do
179
- dependency_tree = { presenter: {} }
180
-
181
- source = <<-HBS
182
- {{presenter.length}}
183
- HBS
184
-
185
- errors = Curlybars.validate(dependency_tree, source)
186
-
187
- expect(errors).not_to be_empty
188
- end
189
-
190
- it "with errors when adding another step after `length`" do
191
- dependency_tree = { presenter: {} }
192
-
193
- source = <<-HBS
194
- {{presenter.length.anything}}
195
- HBS
196
-
197
- errors = Curlybars.validate(dependency_tree, source)
198
-
199
- expect(errors).not_to be_empty
200
- end
201
-
202
- it "to refer an outer scope using `this`" do
203
- dependency_tree = { field: nil, sub_presenter: {} }
204
-
205
- source = <<-HBS
206
- {{#with sub_presenter}}
207
- {{#with ../this}}
208
- {{field}}
209
- {{/with}}
210
- {{/with}}
211
- HBS
212
-
213
- errors = Curlybars.validate(dependency_tree, source)
214
-
215
- expect(errors).to be_empty
216
- end
217
-
218
- describe "with errors" do
219
- it "raises with errors" do
220
- dependency_tree = {}
221
- errors = Curlybars.validate(dependency_tree, "{{unallowed_path}}")
222
-
223
- expect(errors).not_to be_empty
224
- end
225
-
226
- it "raises with metadata" do
227
- dependency_tree = {}
228
- errors = Curlybars.validate(dependency_tree, "{{unallowed_path}}")
229
-
230
- expect(errors.first.metadata).to eq(path: "unallowed_path", step: :unallowed_path)
231
- end
232
-
233
- it "raises with length 0 when the error has no length" do
234
- dependency_tree = {}
235
- errors = Curlybars.validate(dependency_tree, "{{ok}")
236
-
237
- expect(errors.first.position).to eq(Curlybars::Position.new(nil, 1, 4, 0))
238
- end
239
-
240
- describe "raises correct error message" do
241
- let(:dependency_tree) { { ok: nil } }
242
-
243
- it "when path contains several parts" do
244
- source = "{{ok.unallowed.ok}}"
245
- errors = Curlybars.validate(dependency_tree, source)
246
-
247
- expect(errors.first.message).to eq("not possible to access `unallowed` in `ok.unallowed.ok`")
248
- end
249
-
250
- it "when path contains one part" do
251
- source = "{{unallowed}}"
252
- errors = Curlybars.validate(dependency_tree, source)
253
-
254
- expect(errors.first.message).to eq("'unallowed' does not exist")
255
- end
256
- end
257
-
258
- it "with errors when going outside of scope" do
259
- dependency_tree = { ok: { ok: { ok: nil } } }
260
-
261
- source = <<~HBS
262
- {{../ok.ok.ok}}
263
- HBS
264
-
265
- errors = Curlybars.validate(dependency_tree, source)
266
-
267
- expect(errors.first.message).to eq("'../ok.ok.ok' goes out of scope")
268
- end
269
-
270
- describe "raises exact location of unallowed steps" do
271
- let(:dependency_tree) { { ok: { allowed: { ok: nil } } } }
272
-
273
- it "when in a compacted form" do
274
- source = "{{ok.unallowed.ok}}"
275
- errors = Curlybars.validate(dependency_tree, source)
276
-
277
- expect(errors.first.position).to eq(Curlybars::Position.new(nil, 1, 5, 12))
278
- end
279
-
280
- it "with `this` keyword" do
281
- source = "{{ok.this.unallowed.ok}}"
282
- errors = Curlybars.validate(dependency_tree, source)
283
-
284
- expect(errors.first.position).to eq(Curlybars::Position.new(nil, 1, 10, 12))
285
- end
286
-
287
- it "with some spacing" do
288
- source = " {{ ok.unallowed.ok }} "
289
- errors = Curlybars.validate(dependency_tree, source)
290
-
291
- expect(errors.first.position).to eq(Curlybars::Position.new(nil, 1, 9, 12))
292
- end
293
- end
294
- end
295
- end
296
- end
@@ -1,13 +0,0 @@
1
- describe "root" do
2
- describe "#validate" do
3
- it "without errors if template is empty" do
4
- dependency_tree = {}
5
-
6
- source = ""
7
-
8
- errors = Curlybars.validate(dependency_tree, source)
9
-
10
- expect(errors).to be_empty
11
- end
12
- end
13
- end