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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/hamlit/concerns/indentable.rb +2 -3
- data/lib/hamlit/parser.rb +3 -4
- data/lib/hamlit/parsers/tag.rb +1 -1
- data/lib/hamlit/parsers/whitespace.rb +35 -2
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/tag_spec.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9176878aecdc9d91f66537557f147dc8978d5003
|
4
|
+
data.tar.gz: 117ba8f39ed072c6964536add0336be21c44d391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 172e4743255392ecf60944c2820173cc6fbbb3e1f539f91380a0490fce09bc62d62ad0a239422502190f15ec55e8870200d5b574dbdc92bf0895a87c8f542902
|
7
|
+
data.tar.gz: 5af7251fa167c35448565ff8612f4a5c175ab3b389f72e1f55c75f52d2d2acbb5447288211525f50ff19de470eb9bc80b5525cbd0df3c33dfc7327f54c016759
|
data/CHANGELOG.md
CHANGED
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
|
-
|
70
|
-
|
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
|
-
|
121
|
+
outer_remove?
|
123
122
|
end
|
124
123
|
|
125
124
|
def newline_skip_filter?(ast)
|
data/lib/hamlit/parsers/tag.rb
CHANGED
@@ -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(@
|
60
|
+
@outer_removal.add(@tag_indent)
|
32
61
|
else
|
33
|
-
@outer_removal.delete(@
|
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
|
data/lib/hamlit/version.rb
CHANGED
@@ -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
|