mvz-ruby-handlebars 0.0.11 → 0.0.12

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.
data/spec/parser_spec.rb CHANGED
@@ -1,214 +1,214 @@
1
- require_relative 'spec_helper'
2
- require_relative '../lib/ruby-handlebars/parser'
1
+ require_relative "spec_helper"
2
+ require_relative "../lib/ruby-handlebars/parser"
3
3
 
4
4
  describe Handlebars::Parser do
5
5
  let(:parser) {Handlebars::Parser.new}
6
6
 
7
- context 'recognizes' do
8
- it 'simple templates' do
9
- expect(parser.parse('Ho hi !')).to eq({
7
+ context "recognizes" do
8
+ it "simple templates" do
9
+ expect(parser.parse("Ho hi !")).to eq({
10
10
  block_items: [
11
- {template_content: 'Ho hi !'}
11
+ {template_content: "Ho hi !"}
12
12
  ]
13
13
  })
14
14
  end
15
15
 
16
- it 'simple replacements' do
17
- expect(parser.parse('{{plic}}')).to eq({
16
+ it "simple replacements" do
17
+ expect(parser.parse("{{plic}}")).to eq({
18
18
  block_items: [
19
- {replaced_unsafe_item: 'plic'}
19
+ {replaced_unsafe_item: "plic"}
20
20
  ]
21
21
  })
22
22
 
23
- expect(parser.parse('{{ plic}}')).to eq({
23
+ expect(parser.parse("{{ plic}}")).to eq({
24
24
  block_items: [
25
- {replaced_unsafe_item: 'plic'}
25
+ {replaced_unsafe_item: "plic"}
26
26
  ]
27
27
  })
28
28
 
29
- expect(parser.parse('{{plic }}')).to eq({
29
+ expect(parser.parse("{{plic }}")).to eq({
30
30
  block_items: [
31
- {replaced_unsafe_item: 'plic'}
31
+ {replaced_unsafe_item: "plic"}
32
32
  ]
33
33
  })
34
34
 
35
- expect(parser.parse('{{ plic }}')).to eq({
35
+ expect(parser.parse("{{ plic }}")).to eq({
36
36
  block_items: [
37
- {replaced_unsafe_item: 'plic'}
37
+ {replaced_unsafe_item: "plic"}
38
38
  ]
39
39
  })
40
40
  end
41
41
 
42
- it 'special variables' do
43
- expect(parser.parse('{{@first}}')).to eq({
42
+ it "special variables" do
43
+ expect(parser.parse("{{@first}}")).to eq({
44
44
  block_items: [
45
- {replaced_unsafe_item: '@first'}
45
+ {replaced_unsafe_item: "@first"}
46
46
  ]
47
47
  })
48
- expect(parser.parse('{{@last}}')).to eq({
48
+ expect(parser.parse("{{@last}}")).to eq({
49
49
  block_items: [
50
- {replaced_unsafe_item: '@last'}
50
+ {replaced_unsafe_item: "@last"}
51
51
  ]
52
52
  })
53
- expect(parser.parse('{{@index}}')).to eq({
53
+ expect(parser.parse("{{@index}}")).to eq({
54
54
  block_items: [
55
- {replaced_unsafe_item: '@index'}
55
+ {replaced_unsafe_item: "@index"}
56
56
  ]
57
57
  })
58
58
  end
59
59
 
60
- it 'safe strings' do
61
- expect(parser.parse('{{{plic}}}')).to eq({
60
+ it "safe strings" do
61
+ expect(parser.parse("{{{plic}}}")).to eq({
62
62
  block_items: [
63
- {replaced_safe_item: 'plic'}
63
+ {replaced_safe_item: "plic"}
64
64
  ]
65
65
  })
66
66
 
67
- expect(parser.parse('{{{ plic}}}')).to eq({
67
+ expect(parser.parse("{{{ plic}}}")).to eq({
68
68
  block_items: [
69
- {replaced_safe_item: 'plic'}
69
+ {replaced_safe_item: "plic"}
70
70
  ]
71
71
  })
72
72
 
73
- expect(parser.parse('{{{plic }}}')).to eq({
73
+ expect(parser.parse("{{{plic }}}")).to eq({
74
74
  block_items: [
75
- {replaced_safe_item: 'plic'}
75
+ {replaced_safe_item: "plic"}
76
76
  ]
77
77
  })
78
78
 
79
- expect(parser.parse('{{{ plic }}}')).to eq({
79
+ expect(parser.parse("{{{ plic }}}")).to eq({
80
80
  block_items: [
81
- {replaced_safe_item: 'plic'}
81
+ {replaced_safe_item: "plic"}
82
82
  ]
83
83
  })
84
84
 
85
85
  end
86
86
 
87
- context 'helpers' do
88
- it 'simple' do
89
- expect(parser.parse('{{ capitalize plic }}')).to eq({
87
+ context "helpers" do
88
+ it "simple" do
89
+ expect(parser.parse("{{ capitalize plic }}")).to eq({
90
90
  block_items: [
91
91
  {
92
- unsafe_helper_name: 'capitalize',
93
- parameters: {parameter_name: 'plic'}
92
+ unsafe_helper_name: "capitalize",
93
+ parameters: {parameter_name: "plic"}
94
94
  }
95
95
  ]
96
96
  })
97
97
  end
98
98
 
99
- it 'with single-quoted string parameter' do
99
+ it "with single-quoted string parameter" do
100
100
  expect(parser.parse("{{ capitalize 'hi'}}")).to eq({
101
101
  block_items: [
102
102
  {
103
- unsafe_helper_name: 'capitalize',
104
- parameters: {parameter_name: {str_content: 'hi'}},
103
+ unsafe_helper_name: "capitalize",
104
+ parameters: {parameter_name: {str_content: "hi"}},
105
105
  }
106
106
  ]
107
107
  })
108
108
  end
109
109
 
110
- it 'with single-quoted empty string parameter' do
110
+ it "with single-quoted empty string parameter" do
111
111
  expect(parser.parse("{{ capitalize ''}}")).to eq({
112
112
  block_items: [
113
113
  {
114
- unsafe_helper_name: 'capitalize',
115
- parameters: {parameter_name: {str_content: ''}},
114
+ unsafe_helper_name: "capitalize",
115
+ parameters: {parameter_name: {str_content: ""}},
116
116
  }
117
117
  ]
118
118
  })
119
119
  end
120
120
 
121
- it 'with double-quoted string parameter' do
121
+ it "with double-quoted string parameter" do
122
122
  expect(parser.parse('{{ capitalize "hi"}}')).to eq({
123
123
  block_items: [
124
124
  {
125
- unsafe_helper_name: 'capitalize',
126
- parameters: {parameter_name: {str_content: 'hi'}},
125
+ unsafe_helper_name: "capitalize",
126
+ parameters: {parameter_name: {str_content: "hi"}},
127
127
  }
128
128
  ]
129
129
  })
130
130
  end
131
131
 
132
- it 'with double-quoted empty string parameter' do
132
+ it "with double-quoted empty string parameter" do
133
133
  expect(parser.parse('{{ capitalize ""}}')).to eq({
134
134
  block_items: [
135
135
  {
136
- unsafe_helper_name: 'capitalize',
137
- parameters: {parameter_name: {str_content: ''}},
136
+ unsafe_helper_name: "capitalize",
137
+ parameters: {parameter_name: {str_content: ""}},
138
138
  }
139
139
  ]
140
140
  })
141
141
  end
142
142
 
143
- it 'with multiple parameters' do
144
- expect(parser.parse('{{ concat plic ploc plouf }}')).to eq({
143
+ it "with multiple parameters" do
144
+ expect(parser.parse("{{ concat plic ploc plouf }}")).to eq({
145
145
  block_items: [
146
146
  {
147
- unsafe_helper_name: 'concat',
147
+ unsafe_helper_name: "concat",
148
148
  parameters: [
149
- {parameter_name: 'plic'},
150
- {parameter_name: 'ploc'},
151
- {parameter_name: 'plouf'}
149
+ {parameter_name: "plic"},
150
+ {parameter_name: "ploc"},
151
+ {parameter_name: "plouf"}
152
152
  ]
153
153
  }
154
154
  ]
155
155
  })
156
156
  end
157
157
 
158
- it 'block' do
159
- expect(parser.parse('{{#capitalize}}plic{{/capitalize}}')).to eq({
158
+ it "block" do
159
+ expect(parser.parse("{{#capitalize}}plic{{/capitalize}}")).to eq({
160
160
  block_items: [
161
161
  {
162
- helper_name: 'capitalize',
162
+ helper_name: "capitalize",
163
163
  block_items: [
164
- {template_content: 'plic'}
164
+ {template_content: "plic"}
165
165
  ]
166
166
  }
167
167
  ]
168
168
  })
169
169
  end
170
170
 
171
- it 'block with parameters' do
171
+ it "block with parameters" do
172
172
  expect(parser.parse('{{#comment "#"}}plic{{/comment}}')).to eq({
173
173
  block_items: [
174
174
  {
175
- helper_name: 'comment',
176
- parameters: {parameter_name: {str_content: '#'}},
175
+ helper_name: "comment",
176
+ parameters: {parameter_name: {str_content: "#"}},
177
177
  block_items: [
178
- {template_content: 'plic'}
178
+ {template_content: "plic"}
179
179
  ]
180
180
  }
181
181
  ]
182
182
  })
183
183
  end
184
184
 
185
- it 'imbricated blocks' do
185
+ it "imbricated blocks" do
186
186
  expect(parser.parse('{{#comment "#"}}plic {{#capitalize}}ploc{{/capitalize}} plouc{{/comment}}')).to eq({
187
187
  block_items: [
188
188
  {
189
- helper_name: 'comment',
190
- parameters: {parameter_name: {str_content: '#'}},
189
+ helper_name: "comment",
190
+ parameters: {parameter_name: {str_content: "#"}},
191
191
  block_items: [
192
- {template_content: 'plic '},
192
+ {template_content: "plic "},
193
193
  {
194
- helper_name: 'capitalize',
195
- block_items: [{template_content: 'ploc'}]
194
+ helper_name: "capitalize",
195
+ block_items: [{template_content: "ploc"}]
196
196
  },
197
- {template_content: ' plouc'},
197
+ {template_content: " plouc"},
198
198
  ]
199
199
  }
200
200
  ]
201
201
  })
202
202
  end
203
203
 
204
- it 'helpers as arguments' do
205
- expect(parser.parse('{{foo (bar baz)}}')).to eq({
204
+ it "helpers as arguments" do
205
+ expect(parser.parse("{{foo (bar baz)}}")).to eq({
206
206
  block_items: [
207
207
  {
208
- unsafe_helper_name: 'foo',
208
+ unsafe_helper_name: "foo",
209
209
  parameters: {
210
- safe_helper_name: 'bar',
211
- parameters: {parameter_name: 'baz'}
210
+ safe_helper_name: "bar",
211
+ parameters: {parameter_name: "baz"}
212
212
  }
213
213
  }
214
214
  ]
@@ -216,16 +216,16 @@ describe Handlebars::Parser do
216
216
  end
217
217
  end
218
218
 
219
- context 'as helpers' do
219
+ context "as helpers" do
220
220
  it 'recognizes the "as |...|" writing' do
221
- expect(parser.parse('{{#each items as |item|}}plic{{/each}}')).to eq({
221
+ expect(parser.parse("{{#each items as |item|}}plic{{/each}}")).to eq({
222
222
  block_items: [
223
223
  {
224
- helper_name: 'each',
225
- parameters: {parameter_name: 'items'},
226
- as_parameters: {parameter_name: 'item'},
224
+ helper_name: "each",
225
+ parameters: {parameter_name: "items"},
226
+ as_parameters: {parameter_name: "item"},
227
227
  block_items: [
228
- {template_content: 'plic'}
228
+ {template_content: "plic"}
229
229
  ]
230
230
  }
231
231
  ]
@@ -233,44 +233,44 @@ describe Handlebars::Parser do
233
233
  end
234
234
 
235
235
  it 'supports the "else" statement' do
236
- expect(parser.parse('{{#each items as |item|}}plic{{else}}Hummm, empty{{/each}}')).to eq({
236
+ expect(parser.parse("{{#each items as |item|}}plic{{else}}Hummm, empty{{/each}}")).to eq({
237
237
  block_items: [
238
238
  {
239
- helper_name: 'each',
240
- parameters: {parameter_name: 'items'},
241
- as_parameters: {parameter_name: 'item'},
239
+ helper_name: "each",
240
+ parameters: {parameter_name: "items"},
241
+ as_parameters: {parameter_name: "item"},
242
242
  block_items: [
243
- {template_content: 'plic'}
243
+ {template_content: "plic"}
244
244
  ],
245
245
  else_block_items: [
246
- {template_content: 'Hummm, empty'}
246
+ {template_content: "Hummm, empty"}
247
247
  ]
248
248
  }
249
249
  ]
250
250
  })
251
251
  end
252
252
 
253
- it 'can be imbricated' do
254
- expect(parser.parse('{{#each items as |item|}}{{#each item as |char index|}}show item{{/each}}{{else}}Hummm, empty{{/each}}')).to eq({
253
+ it "can be imbricated" do
254
+ expect(parser.parse("{{#each items as |item|}}{{#each item as |char index|}}show item{{/each}}{{else}}Hummm, empty{{/each}}")).to eq({
255
255
  block_items: [
256
256
  {
257
- helper_name: 'each',
258
- parameters: {parameter_name: 'items'},
259
- as_parameters: {parameter_name: 'item'},
257
+ helper_name: "each",
258
+ parameters: {parameter_name: "items"},
259
+ as_parameters: {parameter_name: "item"},
260
260
  block_items: [
261
261
  {
262
- helper_name: 'each',
263
- parameters: {parameter_name: 'item'},
262
+ helper_name: "each",
263
+ parameters: {parameter_name: "item"},
264
264
  as_parameters: [
265
- {parameter_name: 'char'},
266
- {parameter_name: 'index'}],
265
+ {parameter_name: "char"},
266
+ {parameter_name: "index"}],
267
267
  block_items: [
268
- {template_content: 'show item'}
268
+ {template_content: "show item"}
269
269
  ]
270
270
  }
271
271
  ],
272
272
  else_block_items: [
273
- {template_content: 'Hummm, empty'}
273
+ {template_content: "Hummm, empty"}
274
274
  ]
275
275
  }
276
276
  ]
@@ -278,61 +278,61 @@ describe Handlebars::Parser do
278
278
  end
279
279
  end
280
280
 
281
- context 'if block' do
282
- it 'simple' do
283
- expect(parser.parse('{{#if something}}show something else{{/if}}')).to eq({
281
+ context "if block" do
282
+ it "simple" do
283
+ expect(parser.parse("{{#if something}}show something else{{/if}}")).to eq({
284
284
  block_items: [
285
285
  {
286
- helper_name: 'if',
287
- parameters: {parameter_name: 'something'},
286
+ helper_name: "if",
287
+ parameters: {parameter_name: "something"},
288
288
  block_items: [
289
- {template_content: 'show something else'}
289
+ {template_content: "show something else"}
290
290
  ]
291
291
  }
292
292
  ]
293
293
  })
294
294
  end
295
295
 
296
- it 'with an else statement' do
297
- expect(parser.parse('{{#if something}}Ok{{else}}not ok{{/if}}')).to eq({
296
+ it "with an else statement" do
297
+ expect(parser.parse("{{#if something}}Ok{{else}}not ok{{/if}}")).to eq({
298
298
  block_items: [
299
299
  {
300
- helper_name: 'if',
301
- parameters: {parameter_name: 'something'},
300
+ helper_name: "if",
301
+ parameters: {parameter_name: "something"},
302
302
  block_items: [
303
- {template_content: 'Ok'}
303
+ {template_content: "Ok"}
304
304
  ],
305
305
  else_block_items: [
306
- {template_content: 'not ok'}
306
+ {template_content: "not ok"}
307
307
  ]
308
308
  }
309
309
  ]
310
310
  })
311
311
  end
312
312
 
313
- it 'imbricated' do
314
- expect(parser.parse('{{#if something}}{{#if another_thing}}Plic{{/if}}ploc{{/if}}')).to eq({
313
+ it "imbricated" do
314
+ expect(parser.parse("{{#if something}}{{#if another_thing}}Plic{{/if}}ploc{{/if}}")).to eq({
315
315
  block_items: [
316
316
  {
317
- helper_name: 'if',
318
- parameters: {parameter_name: 'something'},
317
+ helper_name: "if",
318
+ parameters: {parameter_name: "something"},
319
319
  block_items: [
320
320
  {
321
- helper_name: 'if',
322
- parameters: {parameter_name: 'another_thing'},
321
+ helper_name: "if",
322
+ parameters: {parameter_name: "another_thing"},
323
323
  block_items: [
324
- {template_content: 'Plic'}
324
+ {template_content: "Plic"}
325
325
  ]
326
326
  },
327
- {template_content: 'ploc'}
327
+ {template_content: "ploc"}
328
328
  ]
329
329
  }
330
330
  ]
331
331
  })
332
332
  end
333
333
 
334
- it 'imbricated block with elses' do
335
- expect(parser.parse('{{#if something}}{{#if another_thing}}Case 1{{else}}Case 2{{/if}}{{else}}{{#if another_thing}}Case 3{{else}}Case 4{{/if}}{{/if}}')).to eq({
334
+ it "imbricated block with elses" do
335
+ expect(parser.parse("{{#if something}}{{#if another_thing}}Case 1{{else}}Case 2{{/if}}{{else}}{{#if another_thing}}Case 3{{else}}Case 4{{/if}}{{/if}}")).to eq({
336
336
  block_items: [
337
337
  {
338
338
  helper_name: "if",
@@ -375,43 +375,43 @@ describe Handlebars::Parser do
375
375
  end
376
376
  end
377
377
 
378
- context 'each block' do
379
- it 'simple' do
380
- expect(parser.parse('{{#each people}} {{this.name}} {{/each}}')).to eq({
378
+ context "each block" do
379
+ it "simple" do
380
+ expect(parser.parse("{{#each people}} {{this.name}} {{/each}}")).to eq({
381
381
  block_items: [
382
382
  {
383
- helper_name: 'each',
384
- parameters: {parameter_name: 'people'},
383
+ helper_name: "each",
384
+ parameters: {parameter_name: "people"},
385
385
  block_items: [
386
- {template_content: ' '},
387
- {replaced_unsafe_item: 'this.name'},
388
- {template_content: ' '}
386
+ {template_content: " "},
387
+ {replaced_unsafe_item: "this.name"},
388
+ {template_content: " "}
389
389
  ]
390
390
  }
391
391
  ]
392
392
  })
393
393
  end
394
394
 
395
- it 'imbricated' do
396
- expect(parser.parse('{{#each people}} {{this.name}} <ul> {{#each this.contact}} <li>{{this}}</li> {{/each}}</ul>{{/each}}')).to eq({
395
+ it "imbricated" do
396
+ expect(parser.parse("{{#each people}} {{this.name}} <ul> {{#each this.contact}} <li>{{this}}</li> {{/each}}</ul>{{/each}}")).to eq({
397
397
  block_items: [
398
398
  {
399
- helper_name: 'each',
400
- parameters: {parameter_name: 'people'},
399
+ helper_name: "each",
400
+ parameters: {parameter_name: "people"},
401
401
  block_items: [
402
- {template_content: ' '},
403
- {replaced_unsafe_item: 'this.name'},
404
- {template_content: ' <ul> '},
402
+ {template_content: " "},
403
+ {replaced_unsafe_item: "this.name"},
404
+ {template_content: " <ul> "},
405
405
  {
406
- helper_name: 'each',
407
- parameters: {parameter_name: 'this.contact'},
406
+ helper_name: "each",
407
+ parameters: {parameter_name: "this.contact"},
408
408
  block_items: [
409
- {template_content: ' <li>'},
410
- {replaced_unsafe_item: 'this'},
411
- {template_content: '</li> '}
409
+ {template_content: " <li>"},
410
+ {replaced_unsafe_item: "this"},
411
+ {template_content: "</li> "}
412
412
  ]
413
413
  },
414
- {template_content: '</ul>'}
414
+ {template_content: "</ul>"}
415
415
  ]
416
416
  }
417
417
  ]
@@ -419,37 +419,45 @@ describe Handlebars::Parser do
419
419
  end
420
420
  end
421
421
 
422
- context 'templates with single curlies' do
423
- it 'works with loose curlies' do
424
- expect(parser.parse('} Hi { hey } {')).to eq({
422
+ context "templates with single curlies" do
423
+ it "works with loose curlies" do
424
+ expect(parser.parse("} Hi { hey } {")).to eq({
425
+ block_items: [
426
+ {template_content: "} Hi { hey } {"}
427
+ ]
428
+ })
429
+ end
430
+
431
+ it "works with groups of curlies" do
432
+ expect(parser.parse("{ Hi }{ hey }")).to eq({
425
433
  block_items: [
426
- {template_content: '} Hi { hey } {'}
434
+ {template_content: "{ Hi }{ hey }"}
427
435
  ]
428
436
  })
429
437
  end
430
438
 
431
- it 'works with groups of curlies' do
432
- expect(parser.parse('{ Hi }{ hey }')).to eq({
439
+ it "works with closing curly before value" do
440
+ expect(parser.parse("Hi }{{ hey }}")).to eq({
433
441
  block_items: [
434
- {template_content: '{ Hi }{ hey }'}
442
+ {template_content: "Hi }"},
443
+ {replaced_unsafe_item: "hey"}
435
444
  ]
436
445
  })
437
446
  end
438
447
 
439
- it 'works with closing curly before value' do
440
- expect(parser.parse('Hi }{{ hey }}')).to eq({
448
+ it "works with single empty curly pair" do
449
+ expect(parser.parse("Hi {} hey")).to eq({
441
450
  block_items: [
442
- {template_content: 'Hi }'},
443
- {replaced_unsafe_item: 'hey'}
451
+ {template_content: "Hi {} hey"}
444
452
  ]
445
453
  })
446
454
  end
447
455
 
448
- it 'works with closing curly before value at the start' do
449
- expect(parser.parse('}{{ hey }}')).to eq({
456
+ it "works with closing curly before value at the start" do
457
+ expect(parser.parse("}{{ hey }}")).to eq({
450
458
  block_items: [
451
- {template_content: '}'},
452
- {replaced_unsafe_item: 'hey'}
459
+ {template_content: "}"},
460
+ {replaced_unsafe_item: "hey"}
453
461
  ]
454
462
  })
455
463
  end