curlybars 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
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 +14 -90
  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,490 +0,0 @@
1
- describe Curlybars::Lexer do
2
- describe "{{!-- ... --}}" do
3
- it "skips begin of block comment" do
4
- expect(lex('{{!--')).to produce []
5
- end
6
-
7
- it "skips begin and end of block comment" do
8
- expect(lex('{{!----}}')).to produce []
9
- end
10
-
11
- it "skips a comment block containing curlybar code" do
12
- expect(lex('{{!--{{helper}}--}}')).to produce []
13
- end
14
-
15
- it "is resilient to whitespaces" do
16
- expect(lex('{{!-- --}}')).to produce []
17
- end
18
-
19
- it "is resilient to newlines" do
20
- expect(lex("{{!--\n--}}")).to produce []
21
- end
22
-
23
- it "is skipped when present in plain text" do
24
- expect(lex('text {{!----}} text')).to produce [:TEXT, :TEXT]
25
- end
26
- end
27
-
28
- describe "{{! ... }}" do
29
- it "skips begin of block comment" do
30
- expect(lex('{{!')).to produce []
31
- end
32
-
33
- it "skips begin and end of block comment" do
34
- expect(lex('{{!}}')).to produce []
35
- end
36
-
37
- it "is resilient to whitespaces" do
38
- expect(lex('{{! }}')).to produce []
39
- end
40
-
41
- it "is resilient to newlines" do
42
- expect(lex("{{!\n}}")).to produce []
43
- end
44
-
45
- it "is lexed when present in plain text" do
46
- expect(lex('text {{!}} text')).to produce [:TEXT, :TEXT]
47
- end
48
- end
49
-
50
- describe "{{<integer>}}" do
51
- it "is lexed as an integer" do
52
- expect(lex("{{7}}")).to produce [:START, :LITERAL, :END]
53
- end
54
-
55
- it "returns the expressed integer" do
56
- literal_token = lex("{{7}}").detect { |token| token.type == :LITERAL }
57
- expect(literal_token.value).to eq 7
58
- end
59
- end
60
-
61
- describe "{{<boolean>}}" do
62
- it "{{true}} is lexed as boolean" do
63
- expect(lex("{{true}}")).to produce [:START, :LITERAL, :END]
64
- end
65
-
66
- it "{{false}} is lexed as boolean" do
67
- expect(lex("{{false}}")).to produce [:START, :LITERAL, :END]
68
- end
69
-
70
- it "returns the expressed boolean" do
71
- literal_token = lex("{{true}}").detect { |token| token.type == :LITERAL }
72
- expect(literal_token.value).to be_truthy
73
- end
74
- end
75
-
76
- describe "{{''}}" do
77
- it "is lexed as a literal" do
78
- expect(lex("{{''}}")).to produce [:START, :LITERAL, :END]
79
- end
80
-
81
- it "returns the string between quotes" do
82
- literal_token = lex("{{'string'}}").detect { |token| token.type == :LITERAL }
83
- expect(literal_token.value).to eq '"string"'
84
- end
85
-
86
- it "is resilient to whitespaces" do
87
- expect(lex("{{ '' }}")).to produce [:START, :LITERAL, :END]
88
- end
89
-
90
- it "is lexed when present in plain text" do
91
- expect(lex("text {{''}} text")).to produce [:TEXT, :START, :LITERAL, :END, :TEXT]
92
- end
93
- end
94
-
95
- describe '{{""}}' do
96
- it "is lexed as a literal" do
97
- expect(lex('{{""}}')).to produce [:START, :LITERAL, :END]
98
- end
99
-
100
- it "returns the string between quotes" do
101
- literal_token = lex('{{"string"}}').detect { |token| token.type == :LITERAL }
102
- expect(literal_token.value).to eq '"string"'
103
- end
104
-
105
- it "is resilient to whitespaces" do
106
- expect(lex('{{ "" }}')).to produce [:START, :LITERAL, :END]
107
- end
108
-
109
- it "is lexed when present in plain text" do
110
- expect(lex('text {{""}} text')).to produce [:TEXT, :START, :LITERAL, :END, :TEXT]
111
- end
112
- end
113
-
114
- describe "{{@variable}}" do
115
- it "is lexed as a varaible" do
116
- expect(lex('{{@var}}')).to produce [:START, :VARIABLE, :END]
117
- end
118
-
119
- it "returns the identifier after `@`" do
120
- variable_token = lex('{{@var}}').detect { |token| token.type == :VARIABLE }
121
- expect(variable_token.value).to eq 'var'
122
- end
123
-
124
- it "returns the identifier after `@` also when using `../`" do
125
- variable_token = lex('{{@../var}}').detect { |token| token.type == :VARIABLE }
126
- expect(variable_token.value).to eq '../var'
127
- end
128
-
129
- it "is resilient to whitespaces" do
130
- expect(lex('{{ @var }}')).to produce [:START, :VARIABLE, :END]
131
- end
132
-
133
- it "is lexed when present in plain text" do
134
- expect(lex('text {{@var}} text')).to produce [:TEXT, :START, :VARIABLE, :END, :TEXT]
135
- end
136
- end
137
-
138
- describe "{{path context options}}" do
139
- it "is lexed with context and options" do
140
- expect(lex('{{path context key=value}}')).to produce [:START, :PATH, :PATH, :KEY, :PATH, :END]
141
- end
142
-
143
- it "is lexed without context" do
144
- expect(lex('{{path key=value}}')).to produce [:START, :PATH, :KEY, :PATH, :END]
145
- end
146
-
147
- it "is lexed without options" do
148
- expect(lex('{{path context}}')).to produce [:START, :PATH, :PATH, :END]
149
- end
150
-
151
- it "is lexed without context and options" do
152
- expect(lex('{{path}}')).to produce [:START, :PATH, :END]
153
- end
154
-
155
- it "is resilient to whitespaces" do
156
- expect(lex('{{ path }}')).to produce [:START, :PATH, :END]
157
- end
158
-
159
- it "is lexed when present in plain text" do
160
- expect(lex('text {{ path }} text')).to produce [:TEXT, :START, :PATH, :END, :TEXT]
161
- end
162
- end
163
-
164
- describe "{{path (path context options)}}" do
165
- it "is lexed with path, context and options" do
166
- expect(lex('{{path (path context key=value)}}')).to produce [:START, :PATH, :LPAREN, :PATH, :PATH, :KEY, :PATH, :RPAREN, :END]
167
- end
168
-
169
- it "is lexed without options" do
170
- expect(lex('{{path (path context)}}')).to produce [:START, :PATH, :LPAREN, :PATH, :PATH, :RPAREN, :END]
171
- end
172
-
173
- it "is lexed without context" do
174
- expect(lex('{{path (path key=value)}}')).to produce [:START, :PATH, :LPAREN, :PATH, :KEY, :PATH, :RPAREN, :END]
175
- end
176
-
177
- it "is lexed without context and options" do
178
- expect(lex('{{path (path)}}')).to produce [:START, :PATH, :LPAREN, :PATH, :RPAREN, :END]
179
- end
180
-
181
- it "is lexed with a nested subexpression" do
182
- expect(lex('{{path (path (path context key=value) key=value)}}')).to produce [:START, :PATH, :LPAREN, :PATH, :LPAREN, :PATH, :PATH, :KEY, :PATH, :RPAREN, :KEY, :PATH, :RPAREN, :END]
183
- end
184
- end
185
-
186
- describe "{{#if path}}...{{/if}}" do
187
- it "is lexed" do
188
- expect(lex('{{#if path}} text {{/if}}')).to produce(
189
- [:START, :HASH, :IF, :PATH, :END, :TEXT, :START, :SLASH, :IF, :END]
190
- )
191
- end
192
-
193
- it "is resilient to whitespaces" do
194
- expect(lex('{{ # if path }} text {{/ if }}')).to produce(
195
- [:START, :HASH, :IF, :PATH, :END, :TEXT, :START, :SLASH, :IF, :END]
196
- )
197
- end
198
-
199
- it "is lexed when present in plain text" do
200
- expect(lex('text {{#if path}} text {{/if}} text')).to produce(
201
- [:TEXT, :START, :HASH, :IF, :PATH, :END, :TEXT, :START, :SLASH, :IF, :END, :TEXT]
202
- )
203
- end
204
- end
205
-
206
- # rubocop:disable Layout/ArrayAlignment
207
- describe "{{#if path}}...{{else}}...{{/if}}" do
208
- it "is lexed" do
209
- expect(lex('{{#if path}} text {{else}} text {{/if}}')).to produce(
210
- [:START, :HASH, :IF, :PATH, :END,
211
- :TEXT, :START, :ELSE, :END,
212
- :TEXT, :START, :SLASH, :IF, :END]
213
- )
214
- end
215
-
216
- it "is resilient to whitespaces" do
217
- expect(lex('{{ # if path }} text {{ else }} text {{/ if }}')).to produce(
218
- [:START, :HASH, :IF, :PATH, :END,
219
- :TEXT, :START, :ELSE, :END,
220
- :TEXT, :START, :SLASH, :IF, :END]
221
- )
222
- end
223
-
224
- it "is lexed when present in plain text" do
225
- expect(lex('text {{#if path}} text {{else}} text {{/if}} text')).to produce(
226
- [:TEXT, :START, :HASH, :IF, :PATH, :END,
227
- :TEXT, :START, :ELSE, :END,
228
- :TEXT, :START, :SLASH, :IF, :END, :TEXT]
229
- )
230
- end
231
- end
232
-
233
- describe "{{#unless path}}...{{/unless}}" do
234
- it "is lexed" do
235
- expect(lex('{{#unless path}} text {{/unless}}')).to produce(
236
- [:START, :HASH, :UNLESS, :PATH, :END, :TEXT, :START, :SLASH, :UNLESS, :END]
237
- )
238
- end
239
-
240
- it "is resilient to whitespaces" do
241
- expect(lex('{{ # unless path }} text {{/ unless }}')).to produce(
242
- [:START, :HASH, :UNLESS, :PATH, :END, :TEXT, :START, :SLASH, :UNLESS, :END]
243
- )
244
- end
245
-
246
- it "is lexed when present in plain text" do
247
- expect(lex('text {{#unless path}} text {{/unless}} text')).to produce(
248
- [:TEXT, :START, :HASH, :UNLESS, :PATH, :END, :TEXT, :START, :SLASH, :UNLESS, :END, :TEXT]
249
- )
250
- end
251
- end
252
-
253
- describe "{{#unless path}}...{{else}}...{{/unless}}" do
254
- it "is lexed" do
255
- expect(lex('{{#unless path}} text {{else}} text {{/unless}}')).to produce(
256
- [:START, :HASH, :UNLESS, :PATH, :END,
257
- :TEXT, :START, :ELSE, :END,
258
- :TEXT, :START, :SLASH, :UNLESS, :END]
259
- )
260
- end
261
-
262
- it "is resilient to whitespaces" do
263
- expect(lex('{{ # unless path }} text {{ else }} text {{/ unless }}')).to produce(
264
- [:START, :HASH, :UNLESS, :PATH, :END,
265
- :TEXT, :START, :ELSE, :END,
266
- :TEXT, :START, :SLASH, :UNLESS, :END]
267
- )
268
- end
269
-
270
- it "is lexed when present in plain text" do
271
- expect(lex('text {{#unless path}} text {{else}} text {{/unless}} text')).to produce(
272
- [:TEXT, :START, :HASH, :UNLESS, :PATH, :END,
273
- :TEXT, :START, :ELSE, :END,
274
- :TEXT, :START, :SLASH, :UNLESS, :END, :TEXT]
275
- )
276
- end
277
- end
278
-
279
- describe "{{#each path}}...{{/each}}" do
280
- it "is lexed" do
281
- expect(lex('{{#each path}} text {{/each}}')).to produce(
282
- [:START, :HASH, :EACH, :PATH, :END, :TEXT, :START, :SLASH, :EACH, :END]
283
- )
284
- end
285
-
286
- it "is resilient to whitespaces" do
287
- expect(lex('{{ # each path }} text {{/ each }}')).to produce(
288
- [:START, :HASH, :EACH, :PATH, :END, :TEXT, :START, :SLASH, :EACH, :END]
289
- )
290
- end
291
-
292
- it "is lexed when present in plain text" do
293
- expect(lex('text {{#each path}} text {{/each}} text')).to produce(
294
- [:TEXT, :START, :HASH, :EACH, :PATH, :END, :TEXT, :START, :SLASH, :EACH, :END, :TEXT]
295
- )
296
- end
297
- end
298
-
299
- describe "{{#each path}}...{{else}}...{{/each}}" do
300
- it "is lexed" do
301
- expect(lex('{{#each path}} text {{else}} text {{/each}}')).to produce(
302
- [:START, :HASH, :EACH, :PATH, :END,
303
- :TEXT, :START, :ELSE, :END,
304
- :TEXT, :START, :SLASH, :EACH, :END]
305
- )
306
- end
307
-
308
- it "is resilient to whitespaces" do
309
- expect(lex('{{ # each path }} text {{ else }} text {{/ each }}')).to produce(
310
- [:START, :HASH, :EACH, :PATH, :END,
311
- :TEXT, :START, :ELSE, :END,
312
- :TEXT, :START, :SLASH, :EACH, :END]
313
- )
314
- end
315
-
316
- it "is lexed when present in plain text" do
317
- expect(lex('text {{#each path}} text {{else}} text {{/each}} text')).to produce(
318
- [:TEXT, :START, :HASH, :EACH, :PATH, :END,
319
- :TEXT, :START, :ELSE, :END,
320
- :TEXT, :START, :SLASH, :EACH, :END, :TEXT]
321
- )
322
- end
323
- end
324
- # rubocop:enable Layout/ArrayAlignment
325
-
326
- describe "{{#with path}}...{{/with}}" do
327
- it "is lexed" do
328
- expect(lex('{{#with path}} text {{/with}}')).to produce(
329
- [:START, :HASH, :WITH, :PATH, :END, :TEXT, :START, :SLASH, :WITH, :END]
330
- )
331
- end
332
-
333
- it "is resilient to whitespaces" do
334
- expect(lex('{{ # with path }} text {{/ with }}')).to produce(
335
- [:START, :HASH, :WITH, :PATH, :END, :TEXT, :START, :SLASH, :WITH, :END]
336
- )
337
- end
338
-
339
- it "is lexed when present in plain text" do
340
- expect(lex('text {{#with path}} text {{/with}} text')).to produce(
341
- [:TEXT, :START, :HASH, :WITH, :PATH, :END, :TEXT, :START, :SLASH, :WITH, :END, :TEXT]
342
- )
343
- end
344
- end
345
-
346
- describe "{{#path path options}}...{{/path}}" do
347
- it "is lexed with context and options" do
348
- expect(lex('{{#path context key=value}} text {{/path}}')).to produce(
349
- [:START, :HASH, :PATH, :PATH, :KEY, :PATH, :END, :TEXT, :START, :SLASH, :PATH, :END]
350
- )
351
- end
352
-
353
- it "is lexed without options" do
354
- expect(lex('{{#path context}} text {{/path}}')).to produce(
355
- [:START, :HASH, :PATH, :PATH, :END, :TEXT, :START, :SLASH, :PATH, :END]
356
- )
357
- end
358
-
359
- it "is resilient to whitespaces" do
360
- expect(lex('{{ # path context key = value}} text {{/ path }}')).to produce(
361
- [:START, :HASH, :PATH, :PATH, :KEY, :PATH, :END, :TEXT, :START, :SLASH, :PATH, :END]
362
- )
363
- end
364
-
365
- it "is lexed when present in plain text" do
366
- expect(lex('text {{#path context key=value}} text {{/path}} text')).to produce(
367
- [:TEXT, :START, :HASH, :PATH, :PATH, :KEY, :PATH, :END, :TEXT, :START, :SLASH, :PATH, :END, :TEXT]
368
- )
369
- end
370
- end
371
-
372
- describe "{{>path}}" do
373
- it "is lexed" do
374
- expect(lex('{{>path}}')).to produce [:START, :GT, :PATH, :END]
375
- end
376
-
377
- it "is resilient to whitespaces" do
378
- expect(lex('{{ > path }}')).to produce [:START, :GT, :PATH, :END]
379
- end
380
-
381
- it "is lexed when present in plain text" do
382
- expect(lex('text {{>path}} text')).to produce [:TEXT, :START, :GT, :PATH, :END, :TEXT]
383
- end
384
- end
385
-
386
- describe "when a leading backslash is present" do
387
- it "`{` is lexed as plain text" do
388
- expect(lex('\{')).to produce [:TEXT]
389
- end
390
-
391
- it "returns the original text" do
392
- text_token = lex('\{').detect { |token| token.type == :TEXT }
393
- expect(text_token.value).to eq '{'
394
- end
395
-
396
- it "is lexed when present in plain text" do
397
- expect(lex('text \{ text')).to produce [:TEXT, :TEXT, :TEXT]
398
- end
399
- end
400
-
401
- describe "can lex paths with or without leading `../`s" do
402
- it "`path` is lexed as a path" do
403
- expect(lex('{{path}}')).to produce [:START, :PATH, :END]
404
- end
405
-
406
- it "`../path` is lexed as a path" do
407
- expect(lex('{{../path}}')).to produce [:START, :PATH, :END]
408
- end
409
-
410
- it "`../../path` is lexed as a path" do
411
- expect(lex('{{../../path}}')).to produce [:START, :PATH, :END]
412
- end
413
-
414
- it "`path/../` raises an error" do
415
- expect do
416
- lex('{{path/../}}')
417
- end.to raise_error(RLTK::LexingError)
418
- end
419
- end
420
-
421
- describe "can lex paths with dashes" do
422
- it "`surrounded by other valid chars" do
423
- expect(lex('{{a-path}}')).to produce [:START, :PATH, :END]
424
- end
425
-
426
- it "at the beginning" do
427
- expect(lex('{{-path}}')).to produce [:START, :PATH, :END]
428
- end
429
-
430
- it "at the end" do
431
- expect(lex('{{path-}}')).to produce [:START, :PATH, :END]
432
- end
433
- end
434
-
435
- describe "can lex paths with identifiers that are numebrs" do
436
- it "`surrounded by other valid chars" do
437
- expect(lex('{{path.123}}')).to produce [:START, :PATH, :END]
438
- end
439
- end
440
-
441
- describe "outside a curlybar context" do
442
- it "`--}}` is lexed as plain text" do
443
- expect(lex('--}}')).to produce [:TEXT]
444
- end
445
-
446
- it "`}}` is lexed as plain text" do
447
- expect(lex('}}')).to produce [:TEXT]
448
- end
449
-
450
- it "`#` is lexed as plain text" do
451
- expect(lex('#')).to produce [:TEXT]
452
- end
453
-
454
- it "`/` is lexed as plain text" do
455
- expect(lex('/')).to produce [:TEXT]
456
- end
457
-
458
- it "`>` is lexed as plain text" do
459
- expect(lex('>')).to produce [:TEXT]
460
- end
461
-
462
- it "`if` is lexed as plain text" do
463
- expect(lex('if')).to produce [:TEXT]
464
- end
465
-
466
- it "`unless` is lexed as plain text" do
467
- expect(lex('unless')).to produce [:TEXT]
468
- end
469
-
470
- it "`each` is lexed as plain text" do
471
- expect(lex('each')).to produce [:TEXT]
472
- end
473
-
474
- it "`with` is lexed as plain text" do
475
- expect(lex('with')).to produce [:TEXT]
476
- end
477
-
478
- it "`else` is lexed as plain text" do
479
- expect(lex('else')).to produce [:TEXT]
480
- end
481
-
482
- it "a path is lexed as plain text" do
483
- expect(lex('this.is.a.path')).to produce [:TEXT]
484
- end
485
-
486
- it "an option is lexed as plain text" do
487
- expect(lex('key=value')).to produce [:TEXT]
488
- end
489
- end
490
- end