hamlit 1.4.7 → 1.5.0

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
  SHA1:
3
- metadata.gz: 3045e96b4ecfe58f815e7d1fd326c1794b03c66f
4
- data.tar.gz: e5c45da5f9a6a2ccfab6e102c47f1d9927098d65
3
+ metadata.gz: 9176878aecdc9d91f66537557f147dc8978d5003
4
+ data.tar.gz: 117ba8f39ed072c6964536add0336be21c44d391
5
5
  SHA512:
6
- metadata.gz: 1d80b09e16c7707191fede2b060cc6c7a3f1db422ddaad0be03f3e8cbaa9b395ac04f74f4d396a781de11616bad672a61221501cac3f2d184c4be9453e6af89c
7
- data.tar.gz: 45e2ee5c7d2f955f15e3093f0f1f87db2783e78b4baf9f1cdedcafb84568e4d5f78c85563461f845f254db80524600f6ceede60a8313d2817af3de248ab2ec79
6
+ metadata.gz: 172e4743255392ecf60944c2820173cc6fbbb3e1f539f91380a0490fce09bc62d62ad0a239422502190f15ec55e8870200d5b574dbdc92bf0895a87c8f542902
7
+ data.tar.gz: 5af7251fa167c35448565ff8612f4a5c175ab3b389f72e1f55c75f52d2d2acbb5447288211525f50ff19de470eb9bc80b5525cbd0df3c33dfc7327f54c016759
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v1.5.0
2
+
3
+ - Remake implementation of outer whitespace removal
4
+
1
5
  ## v1.4.7
2
6
 
3
7
  - Sort static old attributes by name
@@ -23,10 +23,9 @@ module Hamlit
23
23
 
24
24
  def with_indented(&block)
25
25
  @current_indent += 1
26
- result = block.call
26
+ block.call
27
+ ensure
27
28
  @current_indent -= 1
28
-
29
- result
30
29
  end
31
30
 
32
31
  def count_indent(line, strict: false)
data/lib/hamlit/parser.rb CHANGED
@@ -66,9 +66,8 @@ module Hamlit
66
66
 
67
67
  @current_lineno += 1
68
68
  node = parse_line(current_line)
69
- if @outer_removal.include?(@current_indent) && ast.last == [:static, "\n"]
70
- ast.delete_at(-1)
71
- end
69
+ remove_last_outer_space!(ast) if outer_remove?
70
+
72
71
  ast << [:newline] if @current_indent > 0
73
72
  ast << node
74
73
  ast << [:newline] if @current_indent == 0
@@ -119,7 +118,7 @@ module Hamlit
119
118
  SKIP_NEWLINE_EXPS.include?(ast.first) ||
120
119
  (ast[0..1] == [:haml, :doctype]) ||
121
120
  newline_skip_filter?(ast) ||
122
- @outer_removal.include?(@current_indent)
121
+ outer_remove?
123
122
  end
124
123
 
125
124
  def newline_skip_filter?(ast)
@@ -39,7 +39,7 @@ module Hamlit
39
39
  if inner_removal || Helpers::DEFAULT_PRESERVE_TAGS.include?(tag)
40
40
  content[0, 1] = [:haml, :strip]
41
41
  end
42
- content += with_indented { parse_lines }
42
+ content += with_tag_nested { parse_lines }
43
43
  ast << content
44
44
  ast
45
45
  end
@@ -16,10 +16,39 @@ module Hamlit
16
16
  inner_removal
17
17
  end
18
18
 
19
+ def remove_last_outer_space!(ast)
20
+ index = find_last_newline_index(ast)
21
+ return unless index
22
+
23
+ ast.delete_at(index)
24
+ end
25
+
19
26
  private
20
27
 
28
+ # Find [:static, "\n"]'s position ignoring [:code].
29
+ # If it is not found, return nil.
30
+ def find_last_newline_index(ast)
31
+ ast.reverse_each.with_index do |node, index|
32
+ sexp, *args = node
33
+ next if sexp == :code
34
+ return if node != [:static, "\n"]
35
+
36
+ return ast.length - index - 1
37
+ end
38
+ nil
39
+ end
40
+
21
41
  def reset_outer_removal
22
42
  @outer_removal = Set.new
43
+ @tag_indent = 0
44
+ end
45
+
46
+ def with_tag_nested(&block)
47
+ @tag_indent += 1
48
+ with_indented { block.call }
49
+ ensure
50
+ @outer_removal.delete(@tag_indent)
51
+ @tag_indent -= 1
23
52
  end
24
53
 
25
54
  def parse_inner_removal(scanner)
@@ -28,11 +57,15 @@ module Hamlit
28
57
 
29
58
  def parse_outer_removal(scanner)
30
59
  if scanner.scan(/>/)
31
- @outer_removal.add(@current_indent)
60
+ @outer_removal.add(@tag_indent)
32
61
  else
33
- @outer_removal.delete(@current_indent)
62
+ @outer_removal.delete(@tag_indent)
34
63
  end
35
64
  end
65
+
66
+ def outer_remove?
67
+ @outer_removal.include?(@tag_indent)
68
+ end
36
69
  end
37
70
  end
38
71
  end
@@ -1,3 +1,3 @@
1
1
  module Hamlit
2
- VERSION = "1.4.7"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -206,5 +206,22 @@ describe Hamlit::Engine do
206
206
  <span>f</span>
207
207
  HTML
208
208
  end
209
+
210
+ it 'removes outer whitespace by > from inside of block' do
211
+ assert_render(<<-HAML, <<-HTML)
212
+ %span a
213
+ - if true
214
+ %span>
215
+ b
216
+ %span
217
+ c
218
+ HAML
219
+ <span>a</span><span>
220
+ b
221
+ </span><span>
222
+ c
223
+ </span>
224
+ HTML
225
+ end
209
226
  end
210
227
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.7
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun