haml 6.0.0.beta.1-java → 6.0.0.beta.2-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5feb4b8ca27e71d167aa046b5353353339df9c784356f6bce300f2335ae697ba
4
- data.tar.gz: 8ff61a08b2ecfd3d7a2c86c7ff97db2f184de2002f9e7ce076333bf4f83d87b0
3
+ metadata.gz: 2322a046f4730787bbca00088c2bd6068617768a1184a0e78c50d3062f011ac4
4
+ data.tar.gz: f68acb48034434b2da559fa0b2cfc0de158c26d9d6f73fa991345d12e5adb672
5
5
  SHA512:
6
- metadata.gz: d89d132f9d09b12d735150b31e0b2a15d440d540d79321044174dfbf0656bd2fd19d0c3414a356b9e1bda2c0f0ed26b3caeb414d1565c763f1b37dfd16c51141
7
- data.tar.gz: ba191a0b5b7af34040bc7ef50f11255b3f71b87e5d084c62c21b66c87ae2420d55a5ff18ce50a2a5e349758c30e66de163ebcfb76cc552ce815357244891b29c
6
+ metadata.gz: 1c4e60d1a78c55ff590ecb118c3f4f547499141717313cc86a7419199271c9284e433f38cd9f3f2675d865806c53fff32411376383dee9afbc167e0131d7e9f8
7
+ data.tar.gz: 0d73d345ce0a24282e735648089cf0435ebfac56a4dc1f9a2b8f6fd9586b121ef31cf0202eac9f16eaf41ecba5361c611cc61750ce22371c5a9000d99dd717b8
data/CHANGELOG.md CHANGED
@@ -8,6 +8,7 @@ Not released yet
8
8
  * Replace the implementation with Hamlit
9
9
  * Haml 6 is about 1.7x faster than Haml 5 in [this benchmark](benchmark/slim/run-benchmarks.rb).
10
10
  * The parser is kept as is, but everything else is replaced.
11
+ * The `haml` CLI interface was also replaced.
11
12
  * All Haml helpers except for `preserve` are removed.
12
13
  * Some legacy Rails integration is removed.
13
14
 
data/lib/haml/compiler.rb CHANGED
@@ -22,7 +22,7 @@ module Haml
22
22
  end
23
23
 
24
24
  def call(ast)
25
- return runtime_error(ast) if ast.is_a?(HamlError)
25
+ return runtime_error(ast) if ast.is_a?(Error)
26
26
  compile(ast)
27
27
  rescue Error => e
28
28
  runtime_error(e)
data/lib/haml/error.rb CHANGED
@@ -1,16 +1,66 @@
1
1
  # frozen_string_literal: true
2
2
  module Haml
3
- # TODO: unify Haml::Error (former Hamlit::Error) and Haml::HamlError (former Haml::Error)
4
3
  class Error < StandardError
4
+ MESSAGES = {
5
+ bad_script_indent: '"%s" is indented at wrong level: expected %d, but was at %d.',
6
+ cant_run_filter: 'Can\'t run "%s" filter; you must require its dependencies first',
7
+ cant_use_tabs_and_spaces: "Indentation can't use both tabs and spaces.",
8
+ deeper_indenting: "The line was indented %d levels deeper than the previous line.",
9
+ filter_not_defined: 'Filter "%s" is not defined.',
10
+ gem_install_filter_deps: '"%s" filter\'s %s dependency missing: try installing it or adding it to your Gemfile',
11
+ illegal_element: "Illegal element: classes and ids must have values.",
12
+ illegal_nesting_content: "Illegal nesting: nesting within a tag that already has content is illegal.",
13
+ illegal_nesting_header: "Illegal nesting: nesting within a header command is illegal.",
14
+ illegal_nesting_line: "Illegal nesting: content can't be both given on the same line as %%%s and nested within it.",
15
+ illegal_nesting_plain: "Illegal nesting: nesting within plain text is illegal.",
16
+ illegal_nesting_self_closing: "Illegal nesting: nesting within a self-closing tag is illegal.",
17
+ inconsistent_indentation: "Inconsistent indentation: %s used for indentation, but the rest of the document was indented using %s.",
18
+ indenting_at_start: "Indenting at the beginning of the document is illegal.",
19
+ install_haml_contrib: 'To use the "%s" filter, please install the haml-contrib gem.',
20
+ invalid_attribute_list: 'Invalid attribute list: %s.',
21
+ invalid_filter_name: 'Invalid filter name ":%s".',
22
+ invalid_tag: 'Invalid tag: "%s".',
23
+ missing_if: 'Got "%s" with no preceding "if"',
24
+ no_ruby_code: "There's no Ruby code for %s to evaluate.",
25
+ self_closing_content: "Self-closing tags can't have content.",
26
+ unbalanced_brackets: 'Unbalanced brackets.',
27
+ no_end: <<-END
28
+ You don't need to use "- end" in Haml. Un-indent to close a block:
29
+ - if foo?
30
+ %strong Foo!
31
+ - else
32
+ Not foo.
33
+ %p This line is un-indented, so it isn't part of the "if" block
34
+ END
35
+ }.freeze
36
+
37
+ def self.message(key, *args)
38
+ string = MESSAGES[key] or raise "[HAML BUG] No error messages for #{key}"
39
+ (args.empty? ? string : string % args).rstrip
40
+ end
41
+
42
+ # The line of the template on which the error occurred.
43
+ #
44
+ # @return [Fixnum]
5
45
  attr_reader :line
6
46
 
47
+ # @param message [String] The error message
48
+ # @param line [Fixnum] See \{#line}
7
49
  def initialize(message = nil, line = nil)
8
50
  super(message)
9
51
  @line = line
10
52
  end
11
53
  end
12
54
 
55
+ # SyntaxError is the type of exception raised when Haml encounters an
56
+ # ill-formatted document.
57
+ # It's not particularly interesting,
58
+ # except in that it's a subclass of {Haml::Error}.
13
59
  class SyntaxError < Error; end
14
- class InternalError < Error; end
60
+
61
+ # An invalid filter name was used.
15
62
  class FilterNotFound < Error; end
63
+
64
+ # InternalError means that you hit a bug of Haml itself.
65
+ class InternalError < Error; end
16
66
  end
data/lib/haml/parser.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'ripper'
4
4
  require 'strscan'
5
- require 'haml/haml_error'
5
+ require 'haml/error'
6
6
  require 'haml/util'
7
7
 
8
8
  module Haml
@@ -103,6 +103,10 @@ module Haml
103
103
  @script_level_stack = []
104
104
  @template_index = 0
105
105
  @template_tabs = 0
106
+ # When used in Haml::Engine, which gives options[:generator] to every filter
107
+ # in the engine, including Haml::Parser, we don't want to throw exceptions.
108
+ # However, when Haml::Parser is used as a library, we want to throw exceptions.
109
+ @raise_error = !options.key?(:generator)
106
110
  end
107
111
 
108
112
  def call(template)
@@ -125,7 +129,7 @@ module Haml
125
129
  @indentation = nil
126
130
  @line = next_line
127
131
 
128
- raise HamlSyntaxError.new(HamlError.message(:indenting_at_start), @line.index) if @line.tabs != 0
132
+ raise SyntaxError.new(Error.message(:indenting_at_start), @line.index) if @line.tabs != 0
129
133
 
130
134
  loop do
131
135
  next_line
@@ -148,7 +152,7 @@ module Haml
148
152
  end
149
153
 
150
154
  if !flat? && @next_line.tabs - @line.tabs > 1
151
- raise HamlSyntaxError.new(HamlError.message(:deeper_indenting, @next_line.tabs - @line.tabs), @next_line.index)
155
+ raise SyntaxError.new(Error.message(:deeper_indenting, @next_line.tabs - @line.tabs), @next_line.index)
152
156
  end
153
157
 
154
158
  @line = @next_line
@@ -156,8 +160,9 @@ module Haml
156
160
  # Close all the open tags
157
161
  close until @parent.type == :root
158
162
  @root
159
- rescue Haml::HamlError => e
163
+ rescue Haml::Error => e
160
164
  e.backtrace.unshift "#{@options.filename}:#{(e.line ? e.line + 1 : @line.index + 1) + @options.line - 1}"
165
+ raise if @raise_error
161
166
  error_with_lineno(e)
162
167
  end
163
168
 
@@ -168,7 +173,7 @@ module Haml
168
173
  @indentation = line.whitespace
169
174
 
170
175
  if @indentation.include?(?\s) && @indentation.include?(?\t)
171
- raise HamlSyntaxError.new(HamlError.message(:cant_use_tabs_and_spaces), line.index)
176
+ raise SyntaxError.new(Error.message(:cant_use_tabs_and_spaces), line.index)
172
177
  end
173
178
 
174
179
  @flat_spaces = @indentation * (@template_tabs+1) if flat?
@@ -179,11 +184,11 @@ module Haml
179
184
  return tabs if line.whitespace == @indentation * tabs
180
185
  return @template_tabs + 1 if flat? && line.whitespace =~ /^#{@flat_spaces}/
181
186
 
182
- message = HamlError.message(:inconsistent_indentation,
187
+ message = Error.message(:inconsistent_indentation,
183
188
  human_indentation(line.whitespace),
184
189
  human_indentation(@indentation)
185
190
  )
186
- raise HamlSyntaxError.new(message, line.index)
191
+ raise SyntaxError.new(message, line.index)
187
192
  end
188
193
 
189
194
  private
@@ -195,7 +200,7 @@ module Haml
195
200
  return error unless trace
196
201
 
197
202
  line = trace.match(/\d+\z/).to_s.to_i
198
- HamlSyntaxError.new(error.message, line)
203
+ SyntaxError.new(error.message, line)
199
204
  end
200
205
 
201
206
  # @private
@@ -320,7 +325,7 @@ module Haml
320
325
 
321
326
  def plain(line, escape_html = nil)
322
327
  if block_opened?
323
- raise HamlSyntaxError.new(HamlError.message(:illegal_nesting_plain), @next_line.index)
328
+ raise SyntaxError.new(Error.message(:illegal_nesting_plain), @next_line.index)
324
329
  end
325
330
 
326
331
  unless Util.contains_interpolation?(line.text)
@@ -333,7 +338,7 @@ module Haml
333
338
  end
334
339
 
335
340
  def script(line, escape_html = nil, preserve = false)
336
- raise HamlSyntaxError.new(HamlError.message(:no_ruby_code, '=')) if line.text.empty?
341
+ raise SyntaxError.new(Error.message(:no_ruby_code, '=')) if line.text.empty?
337
342
  line = handle_ruby_multiline(line)
338
343
  escape_html = @options.escape_html if escape_html.nil?
339
344
 
@@ -345,12 +350,12 @@ module Haml
345
350
  end
346
351
 
347
352
  def flat_script(line, escape_html = nil)
348
- raise HamlSyntaxError.new(HamlError.message(:no_ruby_code, '~')) if line.text.empty?
353
+ raise SyntaxError.new(Error.message(:no_ruby_code, '~')) if line.text.empty?
349
354
  script(line, escape_html, :preserve)
350
355
  end
351
356
 
352
357
  def silent_script(line)
353
- raise HamlSyntaxError.new(HamlError.message(:no_end), line.index) if line.text[1..-1].strip == 'end'
358
+ raise SyntaxError.new(Error.message(:no_end), line.index) if line.text[1..-1].strip == 'end'
354
359
 
355
360
  line = handle_ruby_multiline(line)
356
361
  keyword = block_keyword(line.text)
@@ -359,7 +364,7 @@ module Haml
359
364
 
360
365
  if ["else", "elsif", "when"].include?(keyword)
361
366
  if @script_level_stack.empty?
362
- raise Haml::HamlSyntaxError.new(HamlError.message(:missing_if, keyword), @line.index)
367
+ raise Haml::SyntaxError.new(Error.message(:missing_if, keyword), @line.index)
363
368
  end
364
369
 
365
370
  if keyword == 'when' and !@script_level_stack.last[2]
@@ -370,8 +375,8 @@ module Haml
370
375
  end
371
376
 
372
377
  if @script_level_stack.last[1] != @line.tabs
373
- message = HamlError.message(:bad_script_indent, keyword, @script_level_stack.last[1], @line.tabs)
374
- raise Haml::HamlSyntaxError.new(message, @line.index)
378
+ message = Error.message(:bad_script_indent, keyword, @script_level_stack.last[1], @line.tabs)
379
+ raise Haml::SyntaxError.new(message, @line.index)
375
380
  end
376
381
  end
377
382
 
@@ -460,12 +465,12 @@ module Haml
460
465
  dynamic_attributes.old = attributes_hashes[:old] unless static_attributes || @options.suppress_eval
461
466
  end
462
467
 
463
- raise HamlSyntaxError.new(HamlError.message(:illegal_nesting_self_closing), @next_line.index) if block_opened? && self_closing
464
- raise HamlSyntaxError.new(HamlError.message(:no_ruby_code, action), last_line - 1) if parse && value.empty?
465
- raise HamlSyntaxError.new(HamlError.message(:self_closing_content), last_line - 1) if self_closing && !value.empty?
468
+ raise SyntaxError.new(Error.message(:illegal_nesting_self_closing), @next_line.index) if block_opened? && self_closing
469
+ raise SyntaxError.new(Error.message(:no_ruby_code, action), last_line - 1) if parse && value.empty?
470
+ raise SyntaxError.new(Error.message(:self_closing_content), last_line - 1) if self_closing && !value.empty?
466
471
 
467
472
  if block_opened? && !value.empty? && !is_ruby_multiline?(value)
468
- raise HamlSyntaxError.new(HamlError.message(:illegal_nesting_line, tag_name), @next_line.index)
473
+ raise SyntaxError.new(Error.message(:illegal_nesting_line, tag_name), @next_line.index)
469
474
  end
470
475
 
471
476
  self_closing ||= !!(!block_opened? && value.empty? && @options.autoclose.any? {|t| t === tag_name})
@@ -509,7 +514,7 @@ module Haml
509
514
  end
510
515
 
511
516
  if block_opened? && !text.empty?
512
- raise HamlSyntaxError.new(Haml::HamlError.message(:illegal_nesting_content), @next_line.index)
517
+ raise SyntaxError.new(Haml::Error.message(:illegal_nesting_content), @next_line.index)
513
518
  end
514
519
 
515
520
  ParseNode.new(:comment, @line.index + 1, :conditional => conditional, :text => text, :revealed => revealed, :parse => parse)
@@ -517,13 +522,13 @@ module Haml
517
522
 
518
523
  # Renders an XHTML doctype or XML shebang.
519
524
  def doctype(text)
520
- raise HamlSyntaxError.new(HamlError.message(:illegal_nesting_header), @next_line.index) if block_opened?
525
+ raise SyntaxError.new(Error.message(:illegal_nesting_header), @next_line.index) if block_opened?
521
526
  version, type, encoding = text[3..-1].strip.downcase.scan(DOCTYPE_REGEX)[0]
522
527
  ParseNode.new(:doctype, @line.index + 1, :version => version, :type => type, :encoding => encoding)
523
528
  end
524
529
 
525
530
  def filter(name)
526
- raise HamlError.new(HamlError.message(:invalid_filter_name, name)) unless name =~ /^\w+$/
531
+ raise Error.new(Error.message(:invalid_filter_name, name)) unless name =~ /^\w+$/
527
532
 
528
533
  if filter_opened?
529
534
  @flat = true
@@ -621,12 +626,12 @@ module Haml
621
626
  # Parses a line into tag_name, attributes, attributes_hash, object_ref, action, value
622
627
  def parse_tag(text)
623
628
  match = text.scan(/%([-:\w]+)([-:\w.#\@]*)(.+)?/)[0]
624
- raise HamlSyntaxError.new(HamlError.message(:invalid_tag, text)) unless match
629
+ raise SyntaxError.new(Error.message(:invalid_tag, text)) unless match
625
630
 
626
631
  tag_name, attributes, rest = match
627
632
 
628
633
  if !attributes.empty? && (attributes =~ /[.#](\.|#|\z)/)
629
- raise HamlSyntaxError.new(HamlError.message(:illegal_element))
634
+ raise SyntaxError.new(Error.message(:illegal_element))
630
635
  end
631
636
 
632
637
  new_attributes_hash = old_attributes_hash = last_line = nil
@@ -685,8 +690,8 @@ module Haml
685
690
  # 1 more :on_embexpr_end (the last '}') than :on_embexpr_beg, and resurrects '{' afterwards.
686
691
  balanced, rest = balance_tokens(text.sub(?{, METHOD_CALL_PREFIX), :on_embexpr_beg, :on_embexpr_end, count: 1)
687
692
  attributes_hash = balanced.sub(METHOD_CALL_PREFIX, ?{)
688
- rescue HamlSyntaxError => e
689
- if e.message == HamlError.message(:unbalanced_brackets) && !@template.empty?
693
+ rescue SyntaxError => e
694
+ if e.message == Error.message(:unbalanced_brackets) && !@template.empty?
690
695
  text << "\n#{@next_line.text}"
691
696
  last_line += 1
692
697
  next_line
@@ -715,7 +720,7 @@ module Haml
715
720
  if name == false
716
721
  scanned = Haml::Util.balance(text, ?(, ?))
717
722
  text = scanned ? scanned.first : text
718
- raise Haml::HamlSyntaxError.new(HamlError.message(:invalid_attribute_list, text.inspect), last_line - 1)
723
+ raise Haml::SyntaxError.new(Error.message(:invalid_attribute_list, text.inspect), last_line - 1)
719
724
  end
720
725
  attributes[name] = value
721
726
  scanner.scan(/\s*/)
@@ -837,7 +842,7 @@ module Haml
837
842
  end
838
843
 
839
844
  def balance(*args)
840
- Haml::Util.balance(*args) or raise(HamlSyntaxError.new(HamlError.message(:unbalanced_brackets)))
845
+ Haml::Util.balance(*args) or raise(SyntaxError.new(Error.message(:unbalanced_brackets)))
841
846
  end
842
847
 
843
848
  # Unlike #balance, this balances Ripper tokens to balance something like `{ a: "}" }` correctly.
@@ -856,7 +861,7 @@ module Haml
856
861
  return text, buf.sub(text, '')
857
862
  end
858
863
  end
859
- raise HamlSyntaxError.new(HamlError.message(:unbalanced_brackets))
864
+ raise SyntaxError.new(Error.message(:unbalanced_brackets))
860
865
  end
861
866
 
862
867
  def block_opened?
data/lib/haml/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Haml
3
- VERSION = '6.0.0.beta.1'
3
+ VERSION = '6.0.0.beta.2'
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.0.beta.1
4
+ version: 6.0.0.beta.2
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-08-20 00:00:00.000000000 Z
15
+ date: 2022-08-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement
@@ -318,7 +318,6 @@ files:
318
318
  - lib/haml/filters/text_base.rb
319
319
  - lib/haml/filters/tilt_base.rb
320
320
  - lib/haml/force_escapable.rb
321
- - lib/haml/haml_error.rb
322
321
  - lib/haml/helpers.rb
323
322
  - lib/haml/html.rb
324
323
  - lib/haml/identity.rb
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Haml
4
- # An exception raised by Haml code.
5
- # TODO: unify Haml::Error (former Hamlit::Error) and Haml::HamlError (former Haml::Error)
6
- class HamlError < StandardError
7
-
8
- MESSAGES = {
9
- bad_script_indent: '"%s" is indented at wrong level: expected %d, but was at %d.',
10
- cant_run_filter: 'Can\'t run "%s" filter; you must require its dependencies first',
11
- cant_use_tabs_and_spaces: "Indentation can't use both tabs and spaces.",
12
- deeper_indenting: "The line was indented %d levels deeper than the previous line.",
13
- filter_not_defined: 'Filter "%s" is not defined.',
14
- gem_install_filter_deps: '"%s" filter\'s %s dependency missing: try installing it or adding it to your Gemfile',
15
- illegal_element: "Illegal element: classes and ids must have values.",
16
- illegal_nesting_content: "Illegal nesting: nesting within a tag that already has content is illegal.",
17
- illegal_nesting_header: "Illegal nesting: nesting within a header command is illegal.",
18
- illegal_nesting_line: "Illegal nesting: content can't be both given on the same line as %%%s and nested within it.",
19
- illegal_nesting_plain: "Illegal nesting: nesting within plain text is illegal.",
20
- illegal_nesting_self_closing: "Illegal nesting: nesting within a self-closing tag is illegal.",
21
- inconsistent_indentation: "Inconsistent indentation: %s used for indentation, but the rest of the document was indented using %s.",
22
- indenting_at_start: "Indenting at the beginning of the document is illegal.",
23
- install_haml_contrib: 'To use the "%s" filter, please install the haml-contrib gem.',
24
- invalid_attribute_list: 'Invalid attribute list: %s.',
25
- invalid_filter_name: 'Invalid filter name ":%s".',
26
- invalid_tag: 'Invalid tag: "%s".',
27
- missing_if: 'Got "%s" with no preceding "if"',
28
- no_ruby_code: "There's no Ruby code for %s to evaluate.",
29
- self_closing_content: "Self-closing tags can't have content.",
30
- unbalanced_brackets: 'Unbalanced brackets.',
31
- no_end: <<-END
32
- You don't need to use "- end" in Haml. Un-indent to close a block:
33
- - if foo?
34
- %strong Foo!
35
- - else
36
- Not foo.
37
- %p This line is un-indented, so it isn't part of the "if" block
38
- END
39
- }.freeze
40
-
41
- def self.message(key, *args)
42
- string = MESSAGES[key] or raise "[HAML BUG] No error messages for #{key}"
43
- (args.empty? ? string : string % args).rstrip
44
- end
45
-
46
- # The line of the template on which the error occurred.
47
- #
48
- # @return [Fixnum]
49
- attr_reader :line
50
-
51
- # @param message [String] The error message
52
- # @param line [Fixnum] See \{#line}
53
- def initialize(message = nil, line = nil)
54
- super(message)
55
- @line = line
56
- end
57
- end
58
-
59
- # SyntaxError is the type of exception raised when Haml encounters an
60
- # ill-formatted document.
61
- # It's not particularly interesting,
62
- # except in that it's a subclass of {Haml::HamlError}.
63
- class HamlSyntaxError < HamlError; end
64
-
65
- class HamlInvalidAttributeNameError < HamlSyntaxError; end
66
- end