haml 6.0.3-java → 6.0.5-java

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 196f2dd507a61ecf4a14268a46d390e3f48e38f1c9ceaa1aaa6a037d43084451
4
- data.tar.gz: 7068d203e0d6204b8738a24ef871b54bb3b8ce531b04587d88dacabd2364ed31
3
+ metadata.gz: e590841334e96540c2233dcb64895ca41527d57a4563b25a6ad8454e3efdfc6e
4
+ data.tar.gz: 42901be1be77d381f5b2823249c39adf9f19712bd367be8e97046abe97baaada
5
5
  SHA512:
6
- metadata.gz: 0b5de12ac87b362b9c9cf601311a8dd61e7bb5d36d6747f8d2de70a43994f91ca4bc0fd0624dd1f10099ea8f941f6f4d01af8d52301792d6c0664dccfb56b6b7
7
- data.tar.gz: e3bb884257de118bb129dbcb49ce309921afbeb6a0a730bae9fa419c2a6b04fb67c0214d0548e6f394171a9366da04acae7be5aaee524e66349d9b5c3dae835e
6
+ metadata.gz: 2d3d0c153a75ccccea17416c4edd1d8fe6519e618c620d4a5be013bea97094fd262e9075b3b0b725060fd23c59aca21269b89ac7b4564bcdc5734523a9f1397f
7
+ data.tar.gz: 3e072c029afc62da06302b6e2faf404afc5f5f22d49c324966e39be622e2693a912d4f671084336fabf1f45141a4e56e645b081a8e3790613dfdf3a1fcdb396a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 6.0.5
4
+
5
+ * Resurrect `#haml_object_ref` support in an object reference [#1097](https://github.com/haml/haml/issues/1097)
6
+ * This was removed in 6.0.0, and added back in this version.
7
+ * Stop warning `remove_whitespace: true` option.
8
+
9
+ ## 6.0.4
10
+
11
+ Released on October 2, 2022
12
+ ([diff](https://github.com/haml/haml/compare/v6.0.3...v6.0.4)).
13
+
14
+ * Fix a parse failure of `%` in attributes [#1096](https://github.com/haml/haml/issues/1096)
15
+ * Add another fallback from C to Ruby for Wasm.
16
+
3
17
  ## 6.0.3
4
18
 
5
19
  Released on September 28, 2022
@@ -34,8 +48,15 @@ Released on September 21, 2022
34
48
  * The `haml` CLI interface was also replaced.
35
49
  * The interface of `Haml::Engine` is changed. `Haml::Template` is most likely what you need now.
36
50
  * Most Haml helpers are removed.
37
- * On Rails, only `find_and_reserve`, `preserve`, `surround`, `precede`, `succeed`, and `capture_haml` are left.
38
- * On Tilt, only `preserve` is left.
51
+ * Rails:
52
+ * Kept: `find_and_reserve`, `preserve`, `surround`, `precede`, `succeed`, `capture_haml`
53
+ * Removed: `block_is_haml?`, `flatten`, `haml_concat`, `haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`,
54
+ `html_escape`, `init_haml_helpers`, `is_haml?`, `list_of`, `non_haml`, `tab_down`, `tab_up`, `with_tabs`
55
+ * Tilt:
56
+ * Kept: `preserve`
57
+ * Removed: `block_is_haml?`, `capture_haml`, `escape_once`, `find_and_preserve`, `flatten`, `haml_concat`,
58
+ `haml_indent`, `haml_tag`, `haml_tag_if`, `html_attrs`, `html_escape`, `init_haml_helpers`, `is_haml?`,
59
+ `list_of`, `non_haml`, `precede`, `succeed`, `surround`, `tab_down`, `tab_up`, `with_tabs`
39
60
  * Only the attributes in [`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb)
40
61
  are handled as boolean attributes.
41
62
  * Some legacy Rails integration is removed.
data/REFERENCE.md CHANGED
@@ -81,6 +81,32 @@ You can then use it by including the `haml` gem in Ruby code, and using
81
81
  engine = Haml::Template.new { "%p Haml code!" }
82
82
  engine.render #=> "<p>Haml code!</p>\n"
83
83
 
84
+ ### Options
85
+
86
+ Haml understands various configuration options that affect its performance and
87
+ output.
88
+
89
+ In Rails, options can be set by using `Haml::RailsTemplate.set_options` in an initializer:
90
+
91
+ ```ruby
92
+ # config/initializers/haml.rb
93
+ Haml::RailsTemplate.set_options(escape_html: false)
94
+ ```
95
+
96
+ Outside Rails, you can set them by configuring them globally in `Haml::Template.options`:
97
+
98
+ ```ruby
99
+ Haml::Template.options[:escape_html] = false
100
+ ```
101
+
102
+ In sinatra specifically, you can set them in global config with:
103
+ ```ruby
104
+ set :haml, { escape_html: false }
105
+ ```
106
+
107
+ Finally, you can also set them by passing an options hash to `Haml::Engine.new` or `Haml::Template.new`.
108
+ For the complete list of available options, please see `Haml::Engine`.
109
+
84
110
  ## Plain Text
85
111
 
86
112
  A substantial portion of any HTML document is its content, which is plain old
@@ -294,7 +320,19 @@ or using `true` and `false`:
294
320
  %input(selected=true)
295
321
 
296
322
  This feature works only for attributes that are included in
297
- [`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb).
323
+ [`Haml::AttributeBuilder::BOOLEAN_ATTRIBUTES`](lib/haml/attribute_builder.rb),
324
+ as well as `data-` and `aria-` attributes.
325
+
326
+ %input{'data-hidden' => false}
327
+ %input{'aria-hidden' => false}
328
+ %input{'xyz-hidden' => false}
329
+
330
+ will render as:
331
+
332
+ <input>
333
+ <input>
334
+ <input xyz-hidden='false'>
335
+
298
336
 
299
337
  <!-- The title to the next section (Prefixed Attributes) has changed. This
300
338
  <a> tag is so old links to here still work. -->
data/Rakefile CHANGED
@@ -35,72 +35,14 @@ end
35
35
 
36
36
  Dir['benchmark/*.rake'].each { |b| import(b) }
37
37
 
38
- namespace :haml do
39
- Rake::TestTask.new do |t|
40
- t.libs << 'lib' << 'test'
41
- files = Dir['test/haml/*_test.rb']
42
- files << 'test/haml/haml-spec/*_test.rb'
43
- t.ruby_opts = %w[-rtest_helper]
44
- t.test_files = files
45
- t.verbose = true
46
- end
47
- end
48
-
49
- namespace :hamlit do
50
- Rake::TestTask.new do |t|
51
- t.libs << 'lib' << 'test'
52
- t.ruby_opts = %w[-rtest_helper]
53
- t.test_files = Dir['test/hamlit/**/*_test.rb']
54
- t.verbose = true
55
- end
56
- end
57
-
58
- namespace :test do
59
- Rake::TestTask.new(:all) do |t|
60
- t.libs << 'lib' << 'test'
61
- files = Dir['test/hamlit/**/*_test.rb']
62
- files += Dir['test/haml/*_test.rb']
63
- files << 'test/haml/haml-spec/*_test.rb'
64
- t.ruby_opts = %w[-rtest_helper]
65
- t.test_files = files
66
- t.verbose = true
67
- end
68
-
69
- Rake::TestTask.new(:spec) do |t|
70
- t.libs << 'lib' << 'test'
71
- t.ruby_opts = %w[-rtest_helper]
72
- t.test_files = %w[test/haml/haml-spec/ugly_test.rb test/haml/haml-spec/pretty_test.rb]
73
- t.verbose = true
74
- end
75
-
76
- Rake::TestTask.new(:engine) do |t|
77
- t.libs << 'lib' << 'test'
78
- t.ruby_opts = %w[-rtest_helper]
79
- t.test_files = %w[test/haml/engine_test.rb]
80
- t.verbose = true
81
- end
82
-
83
- Rake::TestTask.new(:filters) do |t|
84
- t.libs << 'lib' << 'test'
85
- t.ruby_opts = %w[-rtest_helper]
86
- t.test_files = %w[test/haml/filters_test.rb]
87
- t.verbose = true
88
- end
89
-
90
- Rake::TestTask.new(:helper) do |t|
91
- t.libs << 'lib' << 'test'
92
- t.ruby_opts = %w[-rtest_helper]
93
- t.test_files = %w[test/haml/helper_test.rb]
94
- t.verbose = true
95
- end
96
-
97
- Rake::TestTask.new(:template) do |t|
98
- t.libs << 'lib' << 'test'
99
- t.ruby_opts = %w[-rtest_helper]
100
- t.test_files = %w[test/haml/template_test.rb]
101
- t.verbose = true
102
- end
38
+ Rake::TestTask.new do |t|
39
+ t.libs << 'lib' << 'test'
40
+ files = Dir['test/haml/**/*_test.rb']
41
+ t.ruby_opts = %w[-rtest_helper]
42
+ t.test_files = files
43
+ t.verbose = true
103
44
  end
45
+ task test: :compile
104
46
 
105
47
  desc 'bench task for CI'
106
48
  task bench: :compile do
@@ -137,5 +79,4 @@ task(:doc => 'doc:sass') {sh "yard"}
137
79
  desc "Generate documentation incrementally"
138
80
  task(:redoc) {sh "yard -c"}
139
81
 
140
- task default: %w[compile hamlit:test]
141
- task test: %w[compile test:all]
82
+ task default: %w[compile test]
data/lib/haml/engine.rb CHANGED
@@ -3,6 +3,7 @@ require 'temple'
3
3
  require 'haml/parser'
4
4
  require 'haml/compiler'
5
5
  require 'haml/html'
6
+ require 'haml/string_splitter'
6
7
  require 'haml/escapable'
7
8
  require 'haml/force_escapable'
8
9
  require 'haml/dynamic_merger'
@@ -22,12 +23,13 @@ module Haml
22
23
  param source track wbr),
23
24
  filename: "",
24
25
  disable_capture: false,
26
+ remove_whitespace: false,
25
27
  )
26
28
 
27
29
  use Parser
28
30
  use Compiler
29
31
  use HTML
30
- filter :StringSplitter
32
+ use StringSplitter
31
33
  filter :StaticAnalyzer
32
34
  use Escapable
33
35
  use ForceEscapable
@@ -6,7 +6,12 @@ module Haml
6
6
  object, prefix = args
7
7
  return {} unless object
8
8
 
9
- suffix = underscore(object.class)
9
+ suffix =
10
+ if object.respond_to?(:haml_object_ref)
11
+ object.haml_object_ref
12
+ else
13
+ underscore(object.class)
14
+ end
10
15
  {
11
16
  'class' => [prefix, suffix].compact.join('_'),
12
17
  'id' => [prefix, suffix, object.id || 'new'].compact.join('_'),
@@ -1,19 +1,139 @@
1
1
  # frozen_string_literal: true
2
- require 'ripper'
3
- require 'haml/ruby_expression'
2
+ begin
3
+ require 'ripper'
4
+ rescue LoadError
5
+ end
4
6
 
5
7
  module Haml
6
- module StringSplitter
7
- # `code` param must be valid string literal
8
- def self.compile(code)
9
- unless Ripper.respond_to?(:lex) # truffleruby doesn't have Ripper.lex
10
- return [[:dynamic, code]]
8
+ # Compile [:dynamic, "foo#{bar}"] to [:multi, [:static, 'foo'], [:dynamic, 'bar']]
9
+ class StringSplitter < Temple::Filter
10
+ if defined?(Ripper) && RUBY_VERSION >= "2.0.0" && Ripper.respond_to?(:lex)
11
+ class << self
12
+ # `code` param must be valid string literal
13
+ def compile(code)
14
+ [].tap do |exps|
15
+ tokens = Ripper.lex(code.strip)
16
+ tokens.pop while tokens.last && [:on_comment, :on_sp].include?(tokens.last[1])
17
+
18
+ if tokens.size < 2
19
+ raise(Haml::InternalError, "Expected token size >= 2 but got: #{tokens.size}")
20
+ end
21
+ compile_tokens!(exps, tokens)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def strip_quotes!(tokens)
28
+ _, type, beg_str = tokens.shift
29
+ if type != :on_tstring_beg
30
+ raise(Haml::InternalError, "Expected :on_tstring_beg but got: #{type}")
31
+ end
32
+
33
+ _, type, end_str = tokens.pop
34
+ if type != :on_tstring_end
35
+ raise(Haml::InternalError, "Expected :on_tstring_end but got: #{type}")
36
+ end
37
+
38
+ [beg_str, end_str]
39
+ end
40
+
41
+ def compile_tokens!(exps, tokens)
42
+ beg_str, end_str = strip_quotes!(tokens)
43
+
44
+ until tokens.empty?
45
+ _, type, str = tokens.shift
46
+
47
+ case type
48
+ when :on_tstring_content
49
+ beg_str, end_str = escape_quotes(beg_str, end_str)
50
+ exps << [:static, eval("#{beg_str}#{str}#{end_str}").to_s]
51
+ when :on_embexpr_beg
52
+ embedded = shift_balanced_embexpr(tokens)
53
+ exps << [:dynamic, embedded] unless embedded.empty?
54
+ end
55
+ end
56
+ end
57
+
58
+ # Some quotes are split-unsafe. Replace such quotes with null characters.
59
+ def escape_quotes(beg_str, end_str)
60
+ case [beg_str[-1], end_str]
61
+ when ['(', ')'], ['[', ']'], ['{', '}']
62
+ [beg_str.sub(/.\z/) { "\0" }, "\0"]
63
+ else
64
+ [beg_str, end_str]
65
+ end
66
+ end
67
+
68
+ def shift_balanced_embexpr(tokens)
69
+ String.new.tap do |embedded|
70
+ embexpr_open = 1
71
+
72
+ until tokens.empty?
73
+ _, type, str = tokens.shift
74
+ case type
75
+ when :on_embexpr_beg
76
+ embexpr_open += 1
77
+ when :on_embexpr_end
78
+ embexpr_open -= 1
79
+ break if embexpr_open == 0
80
+ end
81
+
82
+ embedded << str
83
+ end
84
+ end
85
+ end
11
86
  end
12
87
 
13
- begin
14
- Temple::Filters::StringSplitter.compile(code)
15
- rescue Temple::FilterError => e
16
- raise Haml::InternalError.new(e.message)
88
+ def on_dynamic(code)
89
+ return [:dynamic, code] unless string_literal?(code)
90
+ return [:dynamic, code] if code.include?("\n")
91
+
92
+ temple = [:multi]
93
+ StringSplitter.compile(code).each do |type, content|
94
+ case type
95
+ when :static
96
+ temple << [:static, content]
97
+ when :dynamic
98
+ temple << on_dynamic(content)
99
+ end
100
+ end
101
+ temple
102
+ end
103
+
104
+ private
105
+
106
+ def string_literal?(code)
107
+ return false if SyntaxChecker.syntax_error?(code)
108
+
109
+ type, instructions = Ripper.sexp(code)
110
+ return false if type != :program
111
+ return false if instructions.size > 1
112
+
113
+ type, _ = instructions.first
114
+ type == :string_literal
115
+ end
116
+
117
+ class SyntaxChecker < Ripper
118
+ class ParseError < StandardError; end
119
+
120
+ def self.syntax_error?(code)
121
+ self.new(code).parse
122
+ false
123
+ rescue ParseError
124
+ true
125
+ end
126
+
127
+ private
128
+
129
+ def on_parse_error(*)
130
+ raise ParseError
131
+ end
132
+ end
133
+ else
134
+ # Do nothing if ripper is unavailable
135
+ def call(ast)
136
+ ast
17
137
  end
18
138
  end
19
139
  end
data/lib/haml/util.rb CHANGED
@@ -14,16 +14,15 @@ module Haml
14
14
  module Util
15
15
  extend self
16
16
 
17
- # Java extension is not implemented for JRuby yet.
18
- # TruffleRuby does not implement `rb_ary_sort_bang`, etc.
19
- if /java/ === RUBY_PLATFORM || RUBY_ENGINE == 'truffleruby'
17
+ begin
18
+ require 'haml/haml' # Haml::Util.escape_html
19
+ rescue LoadError
20
+ # For JRuby and Wasm, fallback to Ruby implementation when C extension is not available.
20
21
  require 'cgi/escape'
21
22
 
22
23
  def self.escape_html(html)
23
24
  CGI.escapeHTML(html.to_s)
24
25
  end
25
- else
26
- require 'haml/haml' # Haml::Util.escape_html
27
26
  end
28
27
 
29
28
  # TODO: Remove unescape_interpolation's workaround and get rid of `respond_to?`.
data/lib/haml/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Haml
3
- VERSION = '6.0.3'
3
+ VERSION = '6.0.5'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.3
4
+ version: 6.0.5
5
5
  platform: java
6
6
  authors:
7
7
  - Natalie Weizenbaum
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2022-09-28 00:00:00.000000000 Z
15
+ date: 2022-10-05 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement