hamlit 2.10.0-java → 2.13.1-java

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/.github/workflows/test.yml +30 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +52 -1
  5. data/Gemfile +1 -7
  6. data/LICENSE.txt +26 -23
  7. data/README.md +8 -8
  8. data/REFERENCE.md +13 -4
  9. data/benchmark/graph/graph.key +0 -0
  10. data/benchmark/graph/graph.png +0 -0
  11. data/bin/bench +2 -2
  12. data/bin/update-haml +125 -0
  13. data/ext/hamlit/hamlit.c +0 -1
  14. data/hamlit.gemspec +1 -1
  15. data/lib/hamlit/attribute_builder.rb +2 -2
  16. data/lib/hamlit/attribute_compiler.rb +3 -3
  17. data/lib/hamlit/compiler/children_compiler.rb +18 -4
  18. data/lib/hamlit/compiler/comment_compiler.rb +8 -5
  19. data/lib/hamlit/filters/escaped.rb +1 -1
  20. data/lib/hamlit/filters/markdown.rb +1 -0
  21. data/lib/hamlit/filters/preserve.rb +1 -1
  22. data/lib/hamlit/filters/text_base.rb +1 -1
  23. data/lib/hamlit/filters/tilt_base.rb +1 -1
  24. data/lib/hamlit/html.rb +8 -0
  25. data/lib/hamlit/parser.rb +6 -2
  26. data/lib/hamlit/parser/haml_attribute_builder.rb +164 -0
  27. data/lib/hamlit/parser/haml_buffer.rb +20 -130
  28. data/lib/hamlit/parser/haml_compiler.rb +1 -553
  29. data/lib/hamlit/parser/haml_error.rb +29 -25
  30. data/lib/hamlit/parser/haml_escapable.rb +1 -0
  31. data/lib/hamlit/parser/haml_generator.rb +1 -0
  32. data/lib/hamlit/parser/haml_helpers.rb +41 -59
  33. data/lib/hamlit/parser/{haml_xss_mods.rb → haml_helpers/xss_mods.rb} +20 -15
  34. data/lib/hamlit/parser/haml_options.rb +53 -66
  35. data/lib/hamlit/parser/haml_parser.rb +133 -73
  36. data/lib/hamlit/parser/haml_temple_engine.rb +123 -0
  37. data/lib/hamlit/parser/haml_util.rb +10 -40
  38. data/lib/hamlit/rails_template.rb +1 -1
  39. data/lib/hamlit/string_splitter.rb +1 -0
  40. data/lib/hamlit/template.rb +1 -1
  41. data/lib/hamlit/temple_line_counter.rb +31 -0
  42. data/lib/hamlit/version.rb +1 -1
  43. metadata +32 -27
  44. data/.travis.yml +0 -47
  45. data/lib/hamlit/parser/MIT-LICENSE +0 -20
  46. data/lib/hamlit/parser/README.md +0 -30
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temple'
4
+ require 'hamlit/parser/haml_escapable'
5
+ require 'hamlit/parser/haml_generator'
6
+
7
+ module Hamlit
8
+ class HamlTempleEngine < Temple::Engine
9
+ define_options(
10
+ attr_wrapper: "'",
11
+ autoclose: %w(area base basefont br col command embed frame
12
+ hr img input isindex keygen link menuitem meta
13
+ param source track wbr),
14
+ encoding: nil,
15
+ escape_attrs: true,
16
+ escape_html: false,
17
+ escape_filter_interpolations: nil,
18
+ filename: '(haml)',
19
+ format: :html5,
20
+ hyphenate_data_attrs: true,
21
+ line: 1,
22
+ mime_type: 'text/html',
23
+ preserve: %w(textarea pre code),
24
+ remove_whitespace: false,
25
+ suppress_eval: false,
26
+ cdata: false,
27
+ parser_class: ::Hamlit::HamlParser,
28
+ compiler_class: ::Hamlit::HamlCompiler,
29
+ trace: false,
30
+ filters: {},
31
+ )
32
+
33
+ use :Parser, -> { options[:parser_class] }
34
+ use :Compiler, -> { options[:compiler_class] }
35
+ use HamlEscapable
36
+ filter :ControlFlow
37
+ filter :MultiFlattener
38
+ filter :StaticMerger
39
+ use HamlGenerator
40
+
41
+ def compile(template)
42
+ initialize_encoding(template, options[:encoding])
43
+ @precompiled = call(template)
44
+ end
45
+
46
+ # The source code that is evaluated to produce the Haml document.
47
+ #
48
+ # This is automatically converted to the correct encoding
49
+ # (see {file:REFERENCE.md#encodings the `:encoding` option}).
50
+ #
51
+ # @return [String]
52
+ def precompiled
53
+ encoding = Encoding.find(@encoding || '')
54
+ return @precompiled.dup.force_encoding(encoding) if encoding == Encoding::ASCII_8BIT
55
+ return @precompiled.encode(encoding)
56
+ end
57
+
58
+ def precompiled_with_return_value
59
+ "#{precompiled};#{precompiled_method_return_value}".dup
60
+ end
61
+
62
+ # The source code that is evaluated to produce the Haml document.
63
+ #
64
+ # This is automatically converted to the correct encoding
65
+ # (see {file:REFERENCE.md#encodings the `:encoding` option}).
66
+ #
67
+ # @return [String]
68
+ def precompiled_with_ambles(local_names, after_preamble: '')
69
+ preamble = <<END.tr("\n", ';')
70
+ begin
71
+ extend Hamlit::HamlHelpers
72
+ _hamlout = @haml_buffer = Hamlit::HamlBuffer.new(haml_buffer, #{HamlOptions.new(options).for_buffer.inspect})
73
+ _erbout = _hamlout.buffer
74
+ #{after_preamble}
75
+ END
76
+ postamble = <<END.tr("\n", ';')
77
+ #{precompiled_method_return_value}
78
+ ensure
79
+ @haml_buffer = @haml_buffer.upper if @haml_buffer
80
+ end
81
+ END
82
+ "#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}".dup
83
+ end
84
+
85
+ private
86
+
87
+ def initialize_encoding(template, given_value)
88
+ if given_value
89
+ @encoding = given_value
90
+ else
91
+ @encoding = Encoding.default_internal || template.encoding
92
+ end
93
+ end
94
+
95
+ # Returns the string used as the return value of the precompiled method.
96
+ # This method exists so it can be monkeypatched to return modified values.
97
+ def precompiled_method_return_value
98
+ "_erbout"
99
+ end
100
+
101
+ def locals_code(names)
102
+ names = names.keys if Hash === names
103
+
104
+ names.map do |name|
105
+ # Can't use || because someone might explicitly pass in false with a symbol
106
+ sym_local = "_haml_locals[#{inspect_obj(name.to_sym)}]"
107
+ str_local = "_haml_locals[#{inspect_obj(name.to_s)}]"
108
+ "#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local};"
109
+ end.join
110
+ end
111
+
112
+ def inspect_obj(obj)
113
+ case obj
114
+ when String
115
+ %Q!"#{obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]}}"!
116
+ when Symbol
117
+ ":#{inspect_obj(obj.to_s)}"
118
+ else
119
+ obj.inspect
120
+ end
121
+ end
122
+ end
123
+ end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  begin
4
4
  require 'erubis/tiny'
@@ -126,7 +126,7 @@ MSG
126
126
  def inspect_obj(obj)
127
127
  case obj
128
128
  when String
129
- %Q!"#{obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]}}"!
129
+ %Q!"#{obj.gsub(/[\x00-\x7F]+/) {|s| s.dump[1...-1]}}"!
130
130
  when Symbol
131
131
  ":#{inspect_obj(obj.to_s)}"
132
132
  else
@@ -166,7 +166,7 @@ MSG
166
166
  # and the rest of the string.
167
167
  # `["Foo (Bar (Baz bang) bop)", " (Bang (bop bip))"]` in the example above.
168
168
  def balance(scanner, start, finish, count = 0)
169
- str = ''
169
+ str = ''.dup
170
170
  scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
171
171
  regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
172
172
  while scanner.scan(regexp)
@@ -198,12 +198,9 @@ MSG
198
198
  /#[\{$@]/ === str
199
199
  end
200
200
 
201
- # Original Haml::Util.unescape_interpolation
202
- # ex) slow_unescape_interpolation('foo#{bar}baz"', escape_html: true)
203
- # #=> "\"foo\#{::Hamlit::HamlHelpers.html_escape((bar))}baz\\\"\""
204
- def slow_unescape_interpolation(str, escape_html = nil)
205
- res = ''
206
- rest = ::Hamlit::HamlUtil.handle_interpolation str.dump do |scan|
201
+ def unescape_interpolation(str, escape_html = nil)
202
+ res = ''.dup
203
+ rest = Hamlit::HamlUtil.handle_interpolation str.dump do |scan|
207
204
  escapes = (scan[2].size - 1) / 2
208
205
  char = scan[3] # '{', '@' or '$'
209
206
  res << scan.matched[0...-3 - escapes]
@@ -215,36 +212,9 @@ MSG
215
212
  else
216
213
  scan.scan(/\w+/)
217
214
  end
218
- content = eval('"' + interpolated + '"')
219
- content.prepend(char) if char == '@' || char == '$'
220
- content = "::Hamlit::HamlHelpers.html_escape((#{content}))" if escape_html
221
-
222
- res << "\#{#{content}}"
223
- end
224
- end
225
- res + rest
226
- end
227
-
228
- # Customized Haml::Util.unescape_interpolation to handle escape by Hamlit.
229
- # It wraps double quotes to given `str` with escaping `"`.
230
- #
231
- # ex) unescape_interpolation('foo#{bar}baz"') #=> "\"foo\#{bar}baz\\\"\""
232
- def unescape_interpolation(str)
233
- res = ''
234
- rest = ::Hamlit::HamlUtil.handle_interpolation str.dump do |scan|
235
- escapes = (scan[2].size - 1) / 2
236
- char = scan[3] # '{', '@' or '$'
237
- res << scan.matched[0...-3 - escapes]
238
- if escapes % 2 == 1
239
- res << "\##{char}"
240
- else
241
- interpolated = if char == '{'
242
- balance(scan, ?{, ?}, 1)[0][0...-1]
243
- else
244
- scan.scan(/\w+/)
245
- end
246
- content = eval('"' + interpolated + '"')
247
- content.prepend(char) if char == '@' || char == '$'
215
+ content = eval("\"#{interpolated}\"")
216
+ content = "#{char}#{content}" if char == '@' || char == '$'
217
+ content = "Hamlit::HamlHelpers.html_escape((#{content}))" if escape_html
248
218
 
249
219
  res << "\#{#{content}}"
250
220
  end
@@ -264,7 +234,7 @@ MSG
264
234
  scanner = StringScanner.new(str.dup.force_encoding(Encoding::ASCII_8BIT))
265
235
  bom = scanner.scan(/\xEF\xBB\xBF/n)
266
236
  return bom unless scanner.scan(/-\s*#\s*/n)
267
- if coding = try_parse_haml_emacs_magic_comment(scanner)
237
+ if (coding = try_parse_haml_emacs_magic_comment(scanner))
268
238
  return bom, coding
269
239
  end
270
240
 
@@ -44,7 +44,7 @@ module Hamlit
44
44
 
45
45
  # https://github.com/haml/haml/blob/4.0.7/lib/haml/template.rb
46
46
  module HamlHelpers
47
- require 'hamlit/parser/haml_xss_mods'
47
+ require 'hamlit/parser/haml_helpers/xss_mods'
48
48
  include Hamlit::HamlHelpers::XssMods
49
49
  end
50
50
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'ripper'
2
3
  require 'hamlit/ruby_expression'
3
4
 
@@ -14,7 +14,7 @@ end
14
14
  module Hamlit
15
15
  Template = Temple::Templates::Tilt.create(
16
16
  Hamlit::Engine,
17
- register_as: :haml,
17
+ register_as: [:haml, :hamlit],
18
18
  )
19
19
 
20
20
  module TemplateExtension
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ module Hamlit
3
+ # A module to count lines of expected code. This would be faster than actual code generation
4
+ # and counting newlines in it.
5
+ module TempleLineCounter
6
+ class UnexpectedExpression < StandardError; end
7
+
8
+ def self.count_lines(exp)
9
+ type, *args = exp
10
+ case type
11
+ when :multi
12
+ args.map { |a| count_lines(a) }.reduce(:+) || 0
13
+ when :dynamic, :code
14
+ args.first.count("\n")
15
+ when :static
16
+ 0 # It has not real newline "\n" but escaped "\\n".
17
+ when :case
18
+ arg, *cases = args
19
+ arg.count("\n") + cases.map do |cond, e|
20
+ (cond == :else ? 0 : cond.count("\n")) + count_lines(e)
21
+ end.reduce(:+)
22
+ when :escape
23
+ count_lines(args[1])
24
+ when :newline
25
+ 1
26
+ else
27
+ raise UnexpectedExpression.new("[HAML BUG] Unexpected Temple expression '#{type}' is given!")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hamlit
3
- VERSION = '2.10.0'
3
+ VERSION = '2.13.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.13.1
5
5
  platform: java
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-15 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -17,8 +17,8 @@ dependencies:
17
17
  - !ruby/object:Gem::Version
18
18
  version: 0.8.2
19
19
  name: temple
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
@@ -31,8 +31,8 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
33
  name: thor
34
- prerelease: false
35
34
  type: :runtime
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
@@ -45,8 +45,8 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  name: tilt
48
- prerelease: false
49
48
  type: :runtime
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
@@ -59,8 +59,8 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  name: benchmark_driver
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
@@ -73,8 +73,8 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  name: bundler
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
@@ -87,8 +87,8 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  name: coffee-script
90
- prerelease: false
91
90
  type: :development
91
+ prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
@@ -101,8 +101,8 @@ dependencies:
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  name: erubi
104
- prerelease: false
105
104
  type: :development
105
+ prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
@@ -115,8 +115,8 @@ dependencies:
115
115
  - !ruby/object:Gem::Version
116
116
  version: '5'
117
117
  name: haml
118
- prerelease: false
119
118
  type: :development
119
+ prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
@@ -129,8 +129,8 @@ dependencies:
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  name: less
132
- prerelease: false
133
132
  type: :development
133
+ prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
@@ -143,8 +143,8 @@ dependencies:
143
143
  - !ruby/object:Gem::Version
144
144
  version: '1.1'
145
145
  name: minitest-reporters
146
- prerelease: false
147
146
  type: :development
147
+ prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
@@ -155,15 +155,15 @@ dependencies:
155
155
  requirements:
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: 4.0.0
158
+ version: '4.0'
159
159
  name: rails
160
- prerelease: false
161
160
  type: :development
161
+ prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: 4.0.0
166
+ version: '4.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  requirement: !ruby/object:Gem::Requirement
169
169
  requirements:
@@ -171,8 +171,8 @@ dependencies:
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  name: rake
174
- prerelease: false
175
174
  type: :development
175
+ prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
@@ -185,8 +185,8 @@ dependencies:
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  name: rake-compiler
188
- prerelease: false
189
188
  type: :development
189
+ prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - ">="
@@ -199,8 +199,8 @@ dependencies:
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
201
  name: sass
202
- prerelease: false
203
202
  type: :development
203
+ prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
@@ -213,8 +213,8 @@ dependencies:
213
213
  - !ruby/object:Gem::Version
214
214
  version: '0'
215
215
  name: slim
216
- prerelease: false
217
216
  type: :development
217
+ prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - ">="
@@ -227,8 +227,8 @@ dependencies:
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  name: string_template
230
- prerelease: false
231
230
  type: :development
231
+ prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - ">="
@@ -241,8 +241,8 @@ dependencies:
241
241
  - !ruby/object:Gem::Version
242
242
  version: '0'
243
243
  name: unindent
244
- prerelease: false
245
244
  type: :development
245
+ prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - ">="
@@ -256,8 +256,8 @@ executables:
256
256
  extensions: []
257
257
  extra_rdoc_files: []
258
258
  files:
259
+ - ".github/workflows/test.yml"
259
260
  - ".gitignore"
260
- - ".travis.yml"
261
261
  - CHANGELOG.md
262
262
  - Gemfile
263
263
  - LICENSE.txt
@@ -286,6 +286,8 @@ files:
286
286
  - benchmark/etc/tags_loop.haml
287
287
  - benchmark/ext/build_data.rb
288
288
  - benchmark/ext/build_id.rb
289
+ - benchmark/graph/graph.key
290
+ - benchmark/graph/graph.png
289
291
  - benchmark/id_attribute.haml
290
292
  - benchmark/plain.haml
291
293
  - benchmark/script.haml
@@ -302,6 +304,7 @@ files:
302
304
  - bin/setup
303
305
  - bin/stackprof
304
306
  - bin/test
307
+ - bin/update-haml
305
308
  - exe/hamlit
306
309
  - ext/hamlit/extconf.rb
307
310
  - ext/hamlit/hamlit.c
@@ -347,22 +350,25 @@ files:
347
350
  - lib/hamlit/identity.rb
348
351
  - lib/hamlit/object_ref.rb
349
352
  - lib/hamlit/parser.rb
350
- - lib/hamlit/parser/MIT-LICENSE
351
- - lib/hamlit/parser/README.md
353
+ - lib/hamlit/parser/haml_attribute_builder.rb
352
354
  - lib/hamlit/parser/haml_buffer.rb
353
355
  - lib/hamlit/parser/haml_compiler.rb
354
356
  - lib/hamlit/parser/haml_error.rb
357
+ - lib/hamlit/parser/haml_escapable.rb
358
+ - lib/hamlit/parser/haml_generator.rb
355
359
  - lib/hamlit/parser/haml_helpers.rb
360
+ - lib/hamlit/parser/haml_helpers/xss_mods.rb
356
361
  - lib/hamlit/parser/haml_options.rb
357
362
  - lib/hamlit/parser/haml_parser.rb
363
+ - lib/hamlit/parser/haml_temple_engine.rb
358
364
  - lib/hamlit/parser/haml_util.rb
359
- - lib/hamlit/parser/haml_xss_mods.rb
360
365
  - lib/hamlit/rails_helpers.rb
361
366
  - lib/hamlit/rails_template.rb
362
367
  - lib/hamlit/railtie.rb
363
368
  - lib/hamlit/ruby_expression.rb
364
369
  - lib/hamlit/string_splitter.rb
365
370
  - lib/hamlit/template.rb
371
+ - lib/hamlit/temple_line_counter.rb
366
372
  - lib/hamlit/utils.rb
367
373
  - lib/hamlit/version.rb
368
374
  homepage: https://github.com/k0kubun/hamlit
@@ -384,8 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
384
390
  - !ruby/object:Gem::Version
385
391
  version: '0'
386
392
  requirements: []
387
- rubyforge_project:
388
- rubygems_version: 2.7.9
393
+ rubygems_version: 3.0.6
389
394
  signing_key:
390
395
  specification_version: 4
391
396
  summary: High Performance Haml Implementation