curlybars 1.16.1.pre.3 → 1.17.0.pre

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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/exe/curlybars-indent-lint +2 -0
  3. data/lib/curlybars/configuration.rb +5 -1
  4. data/lib/curlybars/dependency_tracker.rb +2 -0
  5. data/lib/curlybars/error/base.rb +2 -0
  6. data/lib/curlybars/error/compile.rb +2 -0
  7. data/lib/curlybars/error/lex.rb +2 -0
  8. data/lib/curlybars/error/parse.rb +4 -0
  9. data/lib/curlybars/error/presenter/not_found.rb +2 -0
  10. data/lib/curlybars/error/render.rb +2 -0
  11. data/lib/curlybars/error/validate.rb +2 -0
  12. data/lib/curlybars/generic.rb +2 -0
  13. data/lib/curlybars/lexer.rb +159 -53
  14. data/lib/curlybars/method_whitelist.rb +2 -0
  15. data/lib/curlybars/node/block_helper_else.rb +2 -0
  16. data/lib/curlybars/node/each_else.rb +3 -0
  17. data/lib/curlybars/node/if_else.rb +2 -0
  18. data/lib/curlybars/node/item.rb +2 -0
  19. data/lib/curlybars/node/literal.rb +2 -0
  20. data/lib/curlybars/node/option.rb +2 -0
  21. data/lib/curlybars/node/output.rb +2 -0
  22. data/lib/curlybars/node/partial.rb +2 -0
  23. data/lib/curlybars/node/path.rb +2 -5
  24. data/lib/curlybars/node/root.rb +2 -0
  25. data/lib/curlybars/node/sub_expression.rb +10 -11
  26. data/lib/curlybars/node/template.rb +2 -5
  27. data/lib/curlybars/node/text.rb +2 -0
  28. data/lib/curlybars/node/unless_else.rb +2 -0
  29. data/lib/curlybars/node/variable.rb +2 -0
  30. data/lib/curlybars/node/with_else.rb +3 -0
  31. data/lib/curlybars/parser.rb +247 -146
  32. data/lib/curlybars/partial_presenter.rb +2 -0
  33. data/lib/curlybars/path_finder.rb +3 -2
  34. data/lib/curlybars/position.rb +2 -0
  35. data/lib/curlybars/presenter.rb +2 -0
  36. data/lib/curlybars/processor/token_factory.rb +3 -1
  37. data/lib/curlybars/railtie.rb +2 -0
  38. data/lib/curlybars/rendering_support.rb +16 -1
  39. data/lib/curlybars/safe_buffer.rb +2 -0
  40. data/lib/curlybars/serialization_guard.rb +2 -0
  41. data/lib/curlybars/template_handler.rb +2 -0
  42. data/lib/curlybars/token.rb +28 -0
  43. data/lib/curlybars/validation_context.rb +2 -0
  44. data/lib/curlybars/version.rb +1 -1
  45. data/lib/curlybars/visitor.rb +2 -0
  46. data/lib/curlybars.rb +16 -10
  47. metadata +3 -33
  48. data/lib/curlybars/node/boolean.rb +0 -24
  49. data/lib/curlybars/node/string.rb +0 -24
  50. data/lib/curlybars/processor/tilde.rb +0 -34
data/lib/curlybars.rb CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest'
2
4
  require 'active_support/cache'
5
+ require 'active_support/notifications'
3
6
  require 'active_support/core_ext/object/json'
4
7
  require 'curlybars/version'
5
8
 
@@ -29,7 +32,7 @@ module Curlybars
29
32
  cache_key = ["Curlybars.compile", Curlybars::VERSION, identifier, Digest::SHA256.hexdigest(source)]
30
33
 
31
34
  cache.fetch(cache_key) do
32
- ast(transformed_source(source), identifier, run_processors: true).compile
35
+ ast(transformed_source(source, identifier), identifier, run_processors: true).compile
33
36
  end
34
37
  end
35
38
 
@@ -76,7 +79,7 @@ module Curlybars
76
79
  # source - The source HBS String used to generate an AST.
77
80
  # identifier - The the file name of the template being checked (defaults to `nil`).
78
81
  def visit(visitor, source, identifier = nil)
79
- tree = ast(transformed_source(source), identifier, run_processors: true)
82
+ tree = ast(transformed_source(source, identifier), identifier, run_processors: true)
80
83
  visitor.accept(tree)
81
84
  end
82
85
 
@@ -99,7 +102,7 @@ module Curlybars
99
102
  #
100
103
  # Returns an Array of Curlybars::Node::Path instances that match the target path.
101
104
  def find(target_path, source, identifier = nil, role: nil)
102
- tree = ast(transformed_source(source), identifier, run_processors: true)
105
+ tree = ast(transformed_source(source, identifier), identifier, run_processors: true)
103
106
  finder = Curlybars::PathFinder.new(tree)
104
107
  finder.find(target_path, role: role)
105
108
  end
@@ -127,7 +130,7 @@ module Curlybars
127
130
 
128
131
  private
129
132
 
130
- def transformed_source(source)
133
+ def transformed_source(source, identifier)
131
134
  transformers = Curlybars.configuration.compiler_transformers
132
135
  transformers.inject(source) do |memo, transformer|
133
136
  transformer.transform(memo, identifier)
@@ -137,18 +140,22 @@ module Curlybars
137
140
  def ast(source, identifier, run_processors:)
138
141
  tokens = Curlybars::Lexer.lex(source, identifier)
139
142
 
140
- Curlybars::Processor::Tilde.process!(tokens, identifier)
141
-
142
143
  if run_processors
143
144
  Curlybars.configuration.custom_processors.each do |processor|
144
145
  processor.process!(tokens, identifier)
145
146
  end
146
147
  end
147
148
 
148
- Curlybars::Parser.parse(tokens)
149
- rescue RLTK::LexingError => lexing_error
149
+ parser = Curlybars::Parser.new(tokens, depth_limit: configuration.parse_depth_limit)
150
+ payload = { identifier: identifier, depth_limit: parser.depth_limit }
151
+ ActiveSupport::Notifications.instrument("parse.curlybars", payload) do
152
+ parser.parse
153
+ ensure
154
+ payload[:max_depth] = parser.max_depth
155
+ end
156
+ rescue Curlybars::Lexer::Error => lexing_error
150
157
  raise Curlybars::Error::Lex.new(source, identifier, lexing_error)
151
- rescue RLTK::NotInLanguage => not_in_language_error
158
+ rescue Curlybars::Parser::Error => not_in_language_error
152
159
  raise Curlybars::Error::Parse.new(source, not_in_language_error)
153
160
  end
154
161
  end
@@ -163,7 +170,6 @@ require 'curlybars/position'
163
170
  require 'curlybars/generic'
164
171
  require 'curlybars/lexer'
165
172
  require 'curlybars/processor/token_factory'
166
- require 'curlybars/processor/tilde'
167
173
  require 'curlybars/error/lex'
168
174
  require 'curlybars/error/parse'
169
175
  require 'curlybars/error/compile'
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.16.1.pre.3
4
+ version: 1.17.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Libo Cannici
@@ -44,34 +44,6 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '7.2'
47
- - !ruby/object:Gem::Dependency
48
- name: ffi
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- - !ruby/object:Gem::Dependency
62
- name: rltk
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- type: :runtime
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '0'
75
47
  description: |-
76
48
  A view layer for your Rails apps that separates structure and logic, using Handlebars templates.
77
49
  Strongly inspired by Curly Template gem by Daniel Schierbeck.
@@ -96,7 +68,6 @@ files:
96
68
  - lib/curlybars/lexer.rb
97
69
  - lib/curlybars/method_whitelist.rb
98
70
  - lib/curlybars/node/block_helper_else.rb
99
- - lib/curlybars/node/boolean.rb
100
71
  - lib/curlybars/node/each_else.rb
101
72
  - lib/curlybars/node/if_else.rb
102
73
  - lib/curlybars/node/item.rb
@@ -106,7 +77,6 @@ files:
106
77
  - lib/curlybars/node/partial.rb
107
78
  - lib/curlybars/node/path.rb
108
79
  - lib/curlybars/node/root.rb
109
- - lib/curlybars/node/string.rb
110
80
  - lib/curlybars/node/sub_expression.rb
111
81
  - lib/curlybars/node/template.rb
112
82
  - lib/curlybars/node/text.rb
@@ -118,13 +88,13 @@ files:
118
88
  - lib/curlybars/path_finder.rb
119
89
  - lib/curlybars/position.rb
120
90
  - lib/curlybars/presenter.rb
121
- - lib/curlybars/processor/tilde.rb
122
91
  - lib/curlybars/processor/token_factory.rb
123
92
  - lib/curlybars/railtie.rb
124
93
  - lib/curlybars/rendering_support.rb
125
94
  - lib/curlybars/safe_buffer.rb
126
95
  - lib/curlybars/serialization_guard.rb
127
96
  - lib/curlybars/template_handler.rb
97
+ - lib/curlybars/token.rb
128
98
  - lib/curlybars/validation_context.rb
129
99
  - lib/curlybars/version.rb
130
100
  - lib/curlybars/visitor.rb
@@ -140,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
110
  requirements:
141
111
  - - ">="
142
112
  - !ruby/object:Gem::Version
143
- version: '3.2'
113
+ version: '3.3'
144
114
  required_rubygems_version: !ruby/object:Gem::Requirement
145
115
  requirements:
146
116
  - - ">="
@@ -1,24 +0,0 @@
1
- module Curlybars
2
- module Node
3
- Boolean = Struct.new(:boolean) do
4
- def compile
5
- # NOTE: the following is a heredoc string, representing the ruby code fragment
6
- # outputted by this node.
7
- <<-RUBY
8
- ->() { #{boolean} }
9
- RUBY
10
- end
11
-
12
- def validate(branches, context: nil)
13
- # Nothing to validate here.
14
- end
15
-
16
- def cache_key
17
- [
18
- boolean.to_s,
19
- self.class.name
20
- ].join("/")
21
- end
22
- end
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- module Curlybars
2
- module Node
3
- String = Struct.new(:string) do
4
- def compile
5
- # NOTE: the following is a heredoc string, representing the ruby code fragment
6
- # outputted by this node.
7
- <<-RUBY
8
- ->() { #{string.inspect} }
9
- RUBY
10
- end
11
-
12
- def validate(branches, context: nil)
13
- # Nothing to validate here.
14
- end
15
-
16
- def cache_key
17
- [
18
- string,
19
- self.class.name
20
- ].join("/")
21
- end
22
- end
23
- end
24
- end
@@ -1,34 +0,0 @@
1
- module Curlybars
2
- module Processor
3
- class Tilde
4
- extend TokenFactory
5
-
6
- class << self
7
- def process!(tokens, identifier)
8
- tokens.each_with_index do |token, index|
9
- case token.type
10
- when :TILDE_START
11
- tokens[index] = create_token(:START, token.value, token.position)
12
- next if index == 0
13
-
14
- strip_token_if_text(tokens, index - 1, :rstrip)
15
- when :TILDE_END
16
- tokens[index] = create_token(:END, token.value, token.position)
17
- next if index == (tokens.length - 1)
18
-
19
- strip_token_if_text(tokens, index + 1, :lstrip)
20
- end
21
- end
22
- end
23
-
24
- def strip_token_if_text(tokens, index, strip_method)
25
- token = tokens[index]
26
- return if token.type != :TEXT
27
-
28
- stripped_value = token.value.public_send(strip_method)
29
- tokens[index] = create_token(token.type, stripped_value, token.position)
30
- end
31
- end
32
- end
33
- end
34
- end