curlybars 1.7.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 +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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba4b2799fad2886edfd0bc1c4873d8da9ed80d8885a1868f4b0fa5797fb9e49c
4
- data.tar.gz: ee1bfc5d500f2ceee63675c5188d915227f507de7895c6ed2f08e89ddcae122e
3
+ metadata.gz: 1b3420bf9b68dbab653e2ead7d7802ffc7abf4312630a0fb328f79aaddca1a2d
4
+ data.tar.gz: b0e91d8dc8ccc8069d3543c204c907a2681f06a22ce586f162ef891ae3d70904
5
5
  SHA512:
6
- metadata.gz: 4233c4cd5ed833892d17603776a6db2abae2061cf72dfebe1add84bb7464e99b563cacee499fbcd447f59dd54a1ea3bf3b4aa18010526249aba2ed39a2310b96
7
- data.tar.gz: f78754a1adc25de66302116338dd2abf9b4e9f8c2ae3439d1f74beda9065bb634c8fae64c19f65767be4d7389f1362559c0537f36bb438969e151bb93a47612f
6
+ metadata.gz: bda5835f6f4cca77b09cf12ccca3b0c74ec30758743a45ae2ca76e703bfa8603e742c6c21b296ebf30fa849b13bc56b8187b6676272e9ba25bde218e7700b287
7
+ data.tar.gz: ff2a4169575055da7591aa9b0be580695f8776f2532f8c2308d49169e9892486eea7dd7688bff108f8b325966c921854875b8ac28f64dd3821253d2ae2373255
@@ -9,7 +9,7 @@ module Curlybars
9
9
 
10
10
  error_line = source.split("\n")[line_number - 1]
11
11
  before_error = error_line.first(line_offset).last(10)
12
- after_error = error_line[line_offset + 1..-1].first(10)
12
+ after_error = error_line[line_offset + 1..].first(10)
13
13
  error = error_line[line_offset]
14
14
 
15
15
  details = [before_error, error, after_error]
@@ -16,7 +16,7 @@ module Curlybars
16
16
 
17
17
  error_line = source.split("\n")[line_number - 1]
18
18
  before_error = error_line.first(line_offset).last(10)
19
- after_error = error_line[line_offset + length..-1].first(10)
19
+ after_error = error_line[line_offset + length..].first(10)
20
20
  error = error_line.slice(line_offset, length)
21
21
 
22
22
  details = [before_error, error, after_error]
@@ -109,20 +109,18 @@ module Curlybars
109
109
 
110
110
  offset_adjustment = 0
111
111
  dotted_path_side.split(/\./).map(&:to_sym).inject(base_tree) do |sub_tree, step|
112
- begin
113
- if step == :this
114
- next sub_tree
115
- elsif step == :length && (sub_tree.is_a?(Array) && sub_tree.first.is_a?(Hash))
116
- next nil # :length is synthesised leaf
117
- elsif !(sub_tree.is_a?(Hash) && sub_tree.key?(step))
118
- message = step.to_s == path ? "'#{path}' does not exist" : "not possible to access `#{step}` in `#{path}`"
119
- raise Curlybars::Error::Validate.new('unallowed_path', message, position, offset_adjustment, path: path, step: step)
120
- end
121
-
122
- sub_tree[step]
123
- ensure
124
- offset_adjustment += step.length + 1 # '1' is the length of the dot
112
+ if step == :this
113
+ next sub_tree
114
+ elsif step == :length && (sub_tree.is_a?(Array) && sub_tree.first.is_a?(Hash))
115
+ next nil # :length is synthesised leaf
116
+ elsif !(sub_tree.is_a?(Hash) && sub_tree.key?(step))
117
+ message = step.to_s == path ? "'#{path}' does not exist" : "not possible to access `#{step}` in `#{path}`"
118
+ raise Curlybars::Error::Validate.new('unallowed_path', message, position, offset_adjustment, path: path, step: step)
125
119
  end
120
+
121
+ sub_tree[step]
122
+ ensure
123
+ offset_adjustment += step.length + 1 # '1' is the length of the dot
126
124
  end
127
125
  end
128
126
  end
@@ -276,8 +276,8 @@ module Curlybars
276
276
  # Delegates private method calls to the current view context.
277
277
  #
278
278
  # The view context, an instance of ActionView::Base, is set by Rails.
279
- def method_missing(method, *args, &block)
280
- @_context.public_send(method, *args, &block)
279
+ def method_missing(method, *args, **kwargs, &block)
280
+ @_context.public_send(method, *args, **kwargs, &block)
281
281
  end
282
282
 
283
283
  # Tells ruby (and developers) what methods we can accept.
@@ -13,17 +13,9 @@ module Curlybars
13
13
  # template - The ActionView::Template template that should be compiled.
14
14
  #
15
15
  # Returns a String containing the Ruby code representing the template.
16
- if ActionView::VERSION::MAJOR < 6
17
- def call(template)
18
- instrument(template) do
19
- compile_for_actionview5(template)
20
- end
21
- end
22
- else
23
- def call(template, source)
24
- instrument(template) do
25
- compile(template, source)
26
- end
16
+ def call(template, source)
17
+ instrument(template) do
18
+ compile(template, source)
27
19
  end
28
20
  end
29
21
 
@@ -1,3 +1,3 @@
1
1
  module Curlybars
2
- VERSION = '1.7.0'.freeze
2
+ VERSION = '1.9.0'.freeze
3
3
  end
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.7.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Libo Cannici
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2021-02-17 00:00:00.000000000 Z
18
+ date: 2023-04-18 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: actionpack
@@ -23,40 +23,40 @@ dependencies:
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '6.0'
27
27
  - - "<"
28
28
  - !ruby/object:Gem::Version
29
- version: '6.2'
29
+ version: '7.1'
30
30
  type: :runtime
31
31
  prerelease: false
32
32
  version_requirements: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: '4.2'
36
+ version: '6.0'
37
37
  - - "<"
38
38
  - !ruby/object:Gem::Version
39
- version: '6.2'
39
+ version: '7.1'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: activesupport
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '4.2'
46
+ version: '6.0'
47
47
  - - "<"
48
48
  - !ruby/object:Gem::Version
49
- version: '6.2'
49
+ version: '7.1'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '4.2'
56
+ version: '6.0'
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
- version: '6.2'
59
+ version: '7.1'
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: ffi
62
62
  requirement: !ruby/object:Gem::Requirement
@@ -119,20 +119,20 @@ dependencies:
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: '4.2'
122
+ version: '6.0'
123
123
  - - "<"
124
124
  - !ruby/object:Gem::Version
125
- version: '6.2'
125
+ version: '7.1'
126
126
  type: :development
127
127
  prerelease: false
128
128
  version_requirements: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: '4.2'
132
+ version: '6.0'
133
133
  - - "<"
134
134
  - !ruby/object:Gem::Version
135
- version: '6.2'
135
+ version: '7.1'
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: rake
138
138
  requirement: !ruby/object:Gem::Requirement
@@ -267,44 +267,6 @@ files:
267
267
  - lib/curlybars/template_handler.rb
268
268
  - lib/curlybars/version.rb
269
269
  - lib/curlybars/visitor.rb
270
- - spec/acceptance/application_layout_spec.rb
271
- - spec/acceptance/collection_blocks_spec.rb
272
- - spec/acceptance/global_helper_spec.rb
273
- - spec/curlybars/configuration_spec.rb
274
- - spec/curlybars/error/base_spec.rb
275
- - spec/curlybars/error/compile_spec.rb
276
- - spec/curlybars/error/lex_spec.rb
277
- - spec/curlybars/error/parse_spec.rb
278
- - spec/curlybars/error/render_spec.rb
279
- - spec/curlybars/error/validate_spec.rb
280
- - spec/curlybars/lexer_spec.rb
281
- - spec/curlybars/method_whitelist_spec.rb
282
- - spec/curlybars/processor/tilde_spec.rb
283
- - spec/curlybars/rendering_support_spec.rb
284
- - spec/curlybars/safe_buffer_spec.rb
285
- - spec/curlybars/template_handler_spec.rb
286
- - spec/integration/cache_spec.rb
287
- - spec/integration/comment_spec.rb
288
- - spec/integration/exception_spec.rb
289
- - spec/integration/node/block_helper_else_spec.rb
290
- - spec/integration/node/each_else_spec.rb
291
- - spec/integration/node/each_spec.rb
292
- - spec/integration/node/escape_spec.rb
293
- - spec/integration/node/helper_spec.rb
294
- - spec/integration/node/if_else_spec.rb
295
- - spec/integration/node/if_spec.rb
296
- - spec/integration/node/output_spec.rb
297
- - spec/integration/node/partial_spec.rb
298
- - spec/integration/node/path_spec.rb
299
- - spec/integration/node/root_spec.rb
300
- - spec/integration/node/sub_expression_spec.rb
301
- - spec/integration/node/template_spec.rb
302
- - spec/integration/node/unless_else_spec.rb
303
- - spec/integration/node/unless_spec.rb
304
- - spec/integration/node/with_spec.rb
305
- - spec/integration/processor/tilde_spec.rb
306
- - spec/integration/processors_spec.rb
307
- - spec/integration/visitor_spec.rb
308
270
  homepage: https://github.com/zendesk/curlybars
309
271
  licenses:
310
272
  - Apache-2.0
@@ -318,53 +280,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
318
280
  requirements:
319
281
  - - ">="
320
282
  - !ruby/object:Gem::Version
321
- version: '2.4'
283
+ version: '3.0'
322
284
  required_rubygems_version: !ruby/object:Gem::Requirement
323
285
  requirements:
324
286
  - - ">="
325
287
  - !ruby/object:Gem::Version
326
288
  version: '0'
327
289
  requirements: []
328
- rubygems_version: 3.1.4
290
+ rubygems_version: 3.0.3.1
329
291
  signing_key:
330
292
  specification_version: 4
331
293
  summary: Create your views using Handlebars templates!
332
- test_files:
333
- - spec/curlybars/rendering_support_spec.rb
334
- - spec/curlybars/method_whitelist_spec.rb
335
- - spec/curlybars/configuration_spec.rb
336
- - spec/curlybars/processor/tilde_spec.rb
337
- - spec/curlybars/template_handler_spec.rb
338
- - spec/curlybars/error/compile_spec.rb
339
- - spec/curlybars/error/render_spec.rb
340
- - spec/curlybars/error/parse_spec.rb
341
- - spec/curlybars/error/validate_spec.rb
342
- - spec/curlybars/error/lex_spec.rb
343
- - spec/curlybars/error/base_spec.rb
344
- - spec/curlybars/safe_buffer_spec.rb
345
- - spec/curlybars/lexer_spec.rb
346
- - spec/integration/processor/tilde_spec.rb
347
- - spec/integration/exception_spec.rb
348
- - spec/integration/processors_spec.rb
349
- - spec/integration/visitor_spec.rb
350
- - spec/integration/node/escape_spec.rb
351
- - spec/integration/node/unless_else_spec.rb
352
- - spec/integration/node/output_spec.rb
353
- - spec/integration/node/if_spec.rb
354
- - spec/integration/node/sub_expression_spec.rb
355
- - spec/integration/node/unless_spec.rb
356
- - spec/integration/node/with_spec.rb
357
- - spec/integration/node/partial_spec.rb
358
- - spec/integration/node/block_helper_else_spec.rb
359
- - spec/integration/node/root_spec.rb
360
- - spec/integration/node/template_spec.rb
361
- - spec/integration/node/each_spec.rb
362
- - spec/integration/node/each_else_spec.rb
363
- - spec/integration/node/helper_spec.rb
364
- - spec/integration/node/path_spec.rb
365
- - spec/integration/node/if_else_spec.rb
366
- - spec/integration/comment_spec.rb
367
- - spec/integration/cache_spec.rb
368
- - spec/acceptance/collection_blocks_spec.rb
369
- - spec/acceptance/global_helper_spec.rb
370
- - spec/acceptance/application_layout_spec.rb
294
+ test_files: []
@@ -1,60 +0,0 @@
1
- describe "Using Curlybars for the application layout", type: :request do
2
- example "A simple layout view in Curlybars" do
3
- get '/'
4
-
5
- expect(body).to eq(<<~HTML)
6
- <html>
7
- <head>
8
- <title>Dummy app</title>
9
- </head>
10
- <body>
11
- <h1>Dashboard</h1>
12
- <p>Hello, World!</p>
13
- <p>Welcome!</p>
14
-
15
- </body>
16
- </html>
17
- HTML
18
- end
19
-
20
- describe "Curlybars" do
21
- before do
22
- Curlybars.configure do |config|
23
- config.presenters_namespace = 'curlybars_presenters'
24
- end
25
- end
26
-
27
- after do
28
- Curlybars.reset
29
- end
30
-
31
- example "A simple layout view in Curlybars with html safe logic" do
32
- get '/articles/1'
33
-
34
- expect(body).to eq(<<~HTML)
35
- <html>
36
- <head>
37
- <title>Dummy app</title>
38
- </head>
39
- <body>
40
- <p>Hi Admin</p>
41
-
42
- <h1>Article: The Prince</h1>
43
-
44
- <p>This is <strong>important</strong>!</p>
45
-
46
- <p>&lt;script&gt;alert(&#39;bad&#39;)&lt;/script&gt;</p>
47
-
48
-
49
- <p>
50
- author Nicolò
51
- <img src="http://example.com/foo.png" />
52
- </p>
53
-
54
-
55
- </body>
56
- </html>
57
- HTML
58
- end
59
- end
60
- end
@@ -1,28 +0,0 @@
1
- describe "Collection blocks", type: :request do
2
- before do
3
- Curlybars.configure do |config|
4
- config.presenters_namespace = 'curlybars_presenters'
5
- end
6
- end
7
-
8
- example "Rendering collections" do
9
- get '/categories'
10
-
11
- expect(body).to eq(<<~HTML)
12
- <html>
13
- <head>
14
- <title>Dummy app</title>
15
- </head>
16
- <body>
17
-
18
- <h1>This are the categories</h1>
19
-
20
- <p>One</p>
21
- <p>Two</p>
22
-
23
-
24
- </body>
25
- </html>
26
- HTML
27
- end
28
- end
@@ -1,25 +0,0 @@
1
- describe "Collection blocks", type: :request do
2
- before do
3
- Curlybars.configure do |config|
4
- config.presenters_namespace = 'curlybars_presenters'
5
- config.global_helpers_provider_classes = [GlobalHelpers]
6
- end
7
- end
8
-
9
- example "Render a global helper" do
10
- get '/welcome'
11
-
12
- expect(body).to eq(<<~HTML)
13
- <html>
14
- <head>
15
- <title>Dummy app</title>
16
- </head>
17
- <body>
18
- Login as: Admin
19
- Account: Testing
20
-
21
- </body>
22
- </html>
23
- HTML
24
- end
25
- end
@@ -1,57 +0,0 @@
1
- describe Curlybars::Configuration do
2
- after do
3
- Curlybars.reset
4
- end
5
-
6
- describe "#presenters_namespace" do
7
- it "defaults to an empty string" do
8
- presenters_namespace = Curlybars::Configuration.new.presenters_namespace
9
-
10
- expect(presenters_namespace).to eq('')
11
- end
12
- end
13
-
14
- describe "#presenters_namespace=" do
15
- it "can set value" do
16
- config = Curlybars::Configuration.new
17
- config.presenters_namespace = 'foo'
18
- expect(config.presenters_namespace).to eq('foo')
19
- end
20
- end
21
-
22
- describe "#custom_processors" do
23
- it "can set value" do
24
- config = Curlybars::Configuration.new
25
- config.custom_processors = ['test']
26
- expect(config.custom_processors).to eq(['test'])
27
- end
28
- end
29
-
30
- describe ".configure" do
31
- before do
32
- Curlybars.configure do |config|
33
- config.presenters_namespace = 'bar'
34
- end
35
- end
36
-
37
- it "returns correct value for presenters_namespace" do
38
- presenters_namespace = Curlybars.configuration.presenters_namespace
39
-
40
- expect(presenters_namespace).to eq('bar')
41
- end
42
- end
43
-
44
- describe ".reset" do
45
- it "resets the configuration to default value" do
46
- Curlybars.configure do |config|
47
- config.presenters_namespace = 'foobarbaz'
48
- end
49
-
50
- Curlybars.reset
51
-
52
- presenters_namespace = Curlybars.configuration.presenters_namespace
53
-
54
- expect(presenters_namespace).to eq('')
55
- end
56
- end
57
- end
@@ -1,41 +0,0 @@
1
- describe Curlybars::Error::Base do
2
- let(:position) do
3
- OpenStruct.new(line_number: 1, line_offset: 0)
4
- end
5
-
6
- it "creates an exception with the given message" do
7
- message = "message"
8
-
9
- exception = Curlybars::Error::Base.new('id', message, position)
10
-
11
- expect(exception.message).to be message
12
- end
13
-
14
- it "doesn't change the backtrace for nil position.file_name" do
15
- exception = Curlybars::Error::Base.new('id', 'message', position)
16
-
17
- expect(exception.backtrace).to be nil
18
- end
19
-
20
- it "sets the right backtrace for non-nil position.file_name" do
21
- position.file_name = 'template.hbs'
22
-
23
- exception = Curlybars::Error::Base.new('id', 'message', position)
24
-
25
- expect(exception.backtrace).not_to be nil
26
- end
27
-
28
- it "sets the position as an instance varaible" do
29
- exception = Curlybars::Error::Base.new('id', 'message', position)
30
-
31
- expect(exception.position).to be position
32
- end
33
-
34
- it "sets the id as an instance varaible" do
35
- id = 'id'
36
-
37
- exception = Curlybars::Error::Base.new(id, 'message', position)
38
-
39
- expect(exception.id).to be id
40
- end
41
- end
@@ -1,19 +0,0 @@
1
- describe Curlybars::Error::Compile do
2
- let(:position) do
3
- OpenStruct.new(
4
- line_number: 2,
5
- line_offset: 3,
6
- stream_offset: 14,
7
- length: 3,
8
- file_name: 'template.hbs'
9
- )
10
- end
11
-
12
- it "prefixes the id with `compile.`" do
13
- id = 'id'
14
-
15
- exception = Curlybars::Error::Compile.new(id, 'message', position)
16
-
17
- expect(exception.id).to eq 'compile.%s' % id
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- describe Curlybars::Error::Lex do
2
- let(:file_name) { 'template.hbs' }
3
-
4
- let(:source) { "first_line\n0123456789\nthird_line" }
5
-
6
- let(:exception) do
7
- OpenStruct.new(line_number: 2, line_offset: 2)
8
- end
9
-
10
- it "creates an exception with a meaningful message" do
11
- message = ".. 01 `2` 3456789 .. is not permitted symbol in this context"
12
-
13
- lex_exception = Curlybars::Error::Lex.new(source, file_name, exception)
14
-
15
- expect(lex_exception.message).to eq message
16
- end
17
-
18
- it "figures out a position from the exception" do
19
- backtrace = "%s:%d:%d" % [file_name, exception.line_number, exception.line_offset]
20
-
21
- lex_exception = Curlybars::Error::Lex.new(source, file_name, exception)
22
-
23
- expect(lex_exception.backtrace).to eq [backtrace]
24
- end
25
- end
@@ -1,74 +0,0 @@
1
- describe Curlybars::Error::Parse do
2
- let(:source) { "first_line\n0123456789\nthird_line" }
3
-
4
- describe "with current token not being EOS" do
5
- let(:position) do
6
- OpenStruct.new(
7
- line_number: 2,
8
- line_offset: 3,
9
- length: 3,
10
- file_name: 'template.hbs'
11
- )
12
- end
13
-
14
- let(:exception) do
15
- current = double(:current, position: position, type: :type)
16
- double(:exception, current: current)
17
- end
18
-
19
- it "creates an exception with a meaningful message" do
20
- message = ".. 012 `345` 6789 .. is not permitted in this context"
21
-
22
- lex_exception = Curlybars::Error::Parse.new(source, exception)
23
-
24
- expect(lex_exception.message).to eq message
25
- end
26
-
27
- it "figures out a position from the exception" do
28
- backtrace = "%s:%d:%d" % [position.file_name, position.line_number, position.line_offset]
29
-
30
- lex_exception = Curlybars::Error::Parse.new(source, exception)
31
-
32
- expect(lex_exception.backtrace).to eq [backtrace]
33
- end
34
- end
35
-
36
- describe "with current token being EOS" do
37
- let(:exception) do
38
- current = double(:current, position: nil, type: :EOS)
39
- double(:exception, current: current)
40
- end
41
-
42
- it "creates an exception with a meaningful message" do
43
- message = "A block helper hasn't been closed properly"
44
-
45
- lex_exception = Curlybars::Error::Parse.new(source, exception)
46
-
47
- expect(lex_exception.message).to eq message
48
- end
49
-
50
- it "creates an exception whose position contains the right line_number" do
51
- lex_exception = Curlybars::Error::Parse.new(source, exception)
52
-
53
- expect(lex_exception.position.line_number).to be 3
54
- end
55
-
56
- it "creates an exception whose position contains the right line_offset" do
57
- lex_exception = Curlybars::Error::Parse.new(source, exception)
58
-
59
- expect(lex_exception.position.line_offset).to be_zero
60
- end
61
-
62
- it "creates an exception whose position contains the right length" do
63
- lex_exception = Curlybars::Error::Parse.new(source, exception)
64
-
65
- expect(lex_exception.position.length).to be 'third_line'.length
66
- end
67
-
68
- it "creates an exception whose position contains a nil file_name" do
69
- lex_exception = Curlybars::Error::Parse.new(source, exception)
70
-
71
- expect(lex_exception.position.file_name).to be_nil
72
- end
73
- end
74
- end
@@ -1,19 +0,0 @@
1
- describe Curlybars::Error::Render do
2
- let(:position) do
3
- OpenStruct.new(
4
- line_number: 2,
5
- line_offset: 3,
6
- stream_offset: 14,
7
- length: 3,
8
- file_name: 'template.hbs'
9
- )
10
- end
11
-
12
- it "prefixes the id with `render.`" do
13
- id = 'id'
14
-
15
- exception = Curlybars::Error::Render.new(id, 'message', position)
16
-
17
- expect(exception.id).to eq 'render.%s' % id
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- describe Curlybars::Error::Validate do
2
- let(:position) do
3
- OpenStruct.new(
4
- line_number: 2,
5
- line_offset: 3,
6
- stream_offset: 14,
7
- length: 3,
8
- file_name: 'template.hbs'
9
- )
10
- end
11
-
12
- it "prefixes the id with `validate.`" do
13
- id = 'id'
14
-
15
- exception = Curlybars::Error::Validate.new(id, 'message', position)
16
-
17
- expect(exception.id).to eq 'validate.%s' % id
18
- end
19
- end