hamlit 1.5.2 → 1.5.3
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 +20 -1
- data/lib/hamlit/concerns/line_reader.rb +1 -0
- data/lib/hamlit/parser.rb +39 -32
- data/lib/hamlit/parsers/script.rb +0 -4
- data/lib/hamlit/parsers/tag.rb +4 -11
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/tag_spec.rb +62 -0
- metadata +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b37fdbe2260e2bb676c56133ab5c61fb5064900
|
4
|
+
data.tar.gz: ae2188f3122c3a02bff15888f0d9891368bd388b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ae27755753ed242c704eac31eb066f702f2383b12851fda96accbcc2a20b3887a0c12f87a73fe45154f152e744f8248137dd8930ab2b78db660347544dea17e
|
7
|
+
data.tar.gz: 00af5e2645cf488be39c75708d70e2f14fb23c6f6778b38d74ce82a4d4931e2e010506b53868a260f80ab91a57ec36a36a3a3d28f3439f3b07b6c508d74eae09
|
data/CHANGELOG.md
CHANGED
@@ -48,8 +48,23 @@ module Hamlit
|
|
48
48
|
count_indent(line) == @current_indent
|
49
49
|
end
|
50
50
|
|
51
|
+
# Validate current line's indentation
|
52
|
+
def validate_indentation!(ast)
|
53
|
+
width = next_width
|
54
|
+
return false if width == @current_indent * 2
|
55
|
+
|
56
|
+
if width != Hamlit::EOF && (width > @current_indent * 2 || width.odd?)
|
57
|
+
ast << [:newline]
|
58
|
+
ast << syntax_error(
|
59
|
+
"inconsistent indentation: #{2 * @current_indent} spaces used for indentation, "\
|
60
|
+
"but the rest of the document was indented using #{width} spaces"
|
61
|
+
)
|
62
|
+
end
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
51
66
|
# Validate the template is using consitent indentation, 2 spaces or a tab.
|
52
|
-
def
|
67
|
+
def validate_indentation_consistency!(template)
|
53
68
|
last_indent = ''
|
54
69
|
|
55
70
|
indents = template.scan(/^[ \t]+/)
|
@@ -82,6 +97,10 @@ module Hamlit
|
|
82
97
|
end
|
83
98
|
lines.join
|
84
99
|
end
|
100
|
+
|
101
|
+
def has_block?
|
102
|
+
next_indent > @current_indent
|
103
|
+
end
|
85
104
|
end
|
86
105
|
end
|
87
106
|
end
|
data/lib/hamlit/parser.rb
CHANGED
@@ -39,7 +39,7 @@ module Hamlit
|
|
39
39
|
|
40
40
|
# Reset the parser state.
|
41
41
|
def reset(template)
|
42
|
-
|
42
|
+
validate_indentation_consistency!(template)
|
43
43
|
template = replace_hard_tabs(template)
|
44
44
|
template = preprocess_multilines(template)
|
45
45
|
|
@@ -52,17 +52,7 @@ module Hamlit
|
|
52
52
|
def parse_lines
|
53
53
|
ast = []
|
54
54
|
loop do
|
55
|
-
|
56
|
-
if width != @current_indent * 2
|
57
|
-
if width != Hamlit::EOF && (width > @current_indent * 2 || width.odd?)
|
58
|
-
ast << [:newline]
|
59
|
-
ast << syntax_error(
|
60
|
-
"inconsistent indentation: #{2 * @current_indent} spaces used for indentation, "\
|
61
|
-
"but the rest of the document was indented using #{width} spaces"
|
62
|
-
)
|
63
|
-
end
|
64
|
-
break
|
65
|
-
end
|
55
|
+
break if validate_indentation!(ast)
|
66
56
|
|
67
57
|
@current_lineno += 1
|
68
58
|
node = parse_line(current_line)
|
@@ -77,38 +67,50 @@ module Hamlit
|
|
77
67
|
end
|
78
68
|
|
79
69
|
# Parse current line and return AST.
|
80
|
-
def parse_line(line)
|
70
|
+
def parse_line(line, inline: false)
|
81
71
|
return [:multi] if empty_line?(line)
|
82
72
|
|
83
|
-
scanner =
|
73
|
+
scanner = wrap_scanner(line)
|
84
74
|
scanner.scan(/ +/)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
return
|
89
|
-
elsif scanner.match?(/!!!/)
|
90
|
-
return parse_doctype(scanner)
|
91
|
-
elsif scanner.scan(/!( |==)/)
|
92
|
-
return parse_text(scanner, lstrip: true, escape: false)
|
93
|
-
elsif scanner.match?(/!=/)
|
94
|
-
return parse_script(scanner, disable_escape: true)
|
95
|
-
elsif scanner.scan(/==/)
|
96
|
-
return parse_text(scanner, lstrip: true)
|
97
|
-
elsif scanner.match?(/[.#](\Z|[^a-zA-Z0-9_-])/)
|
98
|
-
return parse_text(scanner)
|
75
|
+
|
76
|
+
unless inline
|
77
|
+
ast = parse_outer_line(scanner)
|
78
|
+
return ast if ast
|
99
79
|
end
|
100
80
|
|
81
|
+
parse_inner_line(scanner, inline: inline)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Parse a line and return ast if it is acceptable outside an inline tag
|
85
|
+
def parse_outer_line(scanner)
|
86
|
+
return parse_text(scanner) if scanner.scan(/\\/)
|
87
|
+
return parse_text(scanner) if scanner.match?(/\#{/)
|
88
|
+
return parse_text(scanner) if scanner.match?(/[.#]($|[^a-zA-Z0-9_-])/)
|
89
|
+
return parse_doctype(scanner) if scanner.match?(/!!!/)
|
90
|
+
|
101
91
|
case scanner.peek(1)
|
102
92
|
when '%', '.', '#'
|
103
93
|
parse_tag(scanner)
|
104
|
-
when '=', '~'
|
105
|
-
parse_script(scanner)
|
106
|
-
when '-'
|
107
|
-
parse_silent_script(scanner)
|
108
94
|
when '/'
|
109
95
|
parse_comment(scanner)
|
110
96
|
when ':'
|
111
97
|
parse_filter(scanner)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Parse a line and return ast which is acceptable inside an inline tag
|
102
|
+
def parse_inner_line(scanner, inline: false)
|
103
|
+
return parse_text(scanner, lstrip: true) if scanner.scan(/==/)
|
104
|
+
return parse_text(scanner, lstrip: true, escape: false) if scanner.scan(/!( |==)/)
|
105
|
+
return parse_script(scanner, force_escape: true) if scanner.match?(/&=/)
|
106
|
+
return parse_script(scanner, disable_escape: true) if scanner.match?(/!=/)
|
107
|
+
return parse_text(scanner, lstrip: true, escape: false) if inline && scanner.scan(/!/)
|
108
|
+
|
109
|
+
case scanner.peek(1)
|
110
|
+
when '=', '~'
|
111
|
+
parse_script(scanner)
|
112
|
+
when '-'
|
113
|
+
parse_silent_script(scanner)
|
112
114
|
else
|
113
115
|
parse_text(scanner)
|
114
116
|
end
|
@@ -124,5 +126,10 @@ module Hamlit
|
|
124
126
|
def newline_skip_filter?(ast)
|
125
127
|
ast[0..1] == [:haml, :filter] && SKIP_NEWLINE_FILTERS.include?(ast[2])
|
126
128
|
end
|
129
|
+
|
130
|
+
def wrap_scanner(str)
|
131
|
+
return str if str.is_a?(StringScanner)
|
132
|
+
StringScanner.new(str)
|
133
|
+
end
|
127
134
|
end
|
128
135
|
end
|
data/lib/hamlit/parsers/tag.rb
CHANGED
@@ -20,19 +20,12 @@ module Hamlit
|
|
20
20
|
attrs += parse_tag_id_and_class(scanner)
|
21
21
|
attrs += parse_attributes(scanner)
|
22
22
|
|
23
|
-
inner_removal = parse_whitespace_removal(scanner)
|
24
23
|
ast = [:html, :tag, tag, attrs]
|
24
|
+
inner_removal = parse_whitespace_removal(scanner)
|
25
25
|
|
26
|
-
|
27
|
-
ast
|
28
|
-
return ast
|
29
|
-
elsif scanner.scan(/\//)
|
30
|
-
return ast
|
31
|
-
elsif scanner.rest.match(/[^ ]/)
|
32
|
-
ast << parse_text(scanner, lstrip: true)
|
33
|
-
return ast
|
34
|
-
elsif next_indent <= @current_indent
|
35
|
-
return ast << [:multi]
|
26
|
+
unless has_block?
|
27
|
+
return ast if scanner.scan(/\//)
|
28
|
+
return ast << parse_line(scanner, inline: true)
|
36
29
|
end
|
37
30
|
|
38
31
|
content = [:multi, [:static, "\n"]]
|
data/lib/hamlit/version.rb
CHANGED
@@ -186,6 +186,68 @@ describe Hamlit::Engine do
|
|
186
186
|
HTML
|
187
187
|
end
|
188
188
|
|
189
|
+
describe 'inline operator' do
|
190
|
+
it 'does not accept backslash operator' do
|
191
|
+
assert_render(<<-'HAML', <<-'HTML')
|
192
|
+
%span\ foo
|
193
|
+
HAML
|
194
|
+
<span>\ foo</span>
|
195
|
+
HTML
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'accepts != operator' do
|
199
|
+
assert_render(<<-'HAML', <<-'HTML')
|
200
|
+
%span!= '<nyaa>'
|
201
|
+
HAML
|
202
|
+
<span><nyaa></span>
|
203
|
+
HTML
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'accepts !== operator' do
|
207
|
+
assert_render(<<-'HAML', <<-'HTML')
|
208
|
+
%span!==#{'<nyaa>'}
|
209
|
+
%span!== #{'<nyaa>'}
|
210
|
+
!==#{'<nyaa>'}
|
211
|
+
!== #{'<nyaa>'}
|
212
|
+
HAML
|
213
|
+
<span><nyaa></span>
|
214
|
+
<span><nyaa></span>
|
215
|
+
<nyaa>
|
216
|
+
<nyaa>
|
217
|
+
HTML
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'accepts &= operator' do
|
221
|
+
assert_render(<<-'HAML', <<-'HTML', escape_html: false)
|
222
|
+
%span&= '<nyaa>'
|
223
|
+
HAML
|
224
|
+
<span><nyaa></span>
|
225
|
+
HTML
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'accepts ! operator' do
|
229
|
+
assert_render(<<-'HAML', <<-'HTML')
|
230
|
+
%span!#{'<nyaa>'}
|
231
|
+
%span! #{'<nyaa>'}
|
232
|
+
!#{'<nyaa>'}
|
233
|
+
! #{'<nyaa>'}
|
234
|
+
HAML
|
235
|
+
<span><nyaa></span>
|
236
|
+
<span><nyaa></span>
|
237
|
+
!<nyaa>
|
238
|
+
<nyaa>
|
239
|
+
HTML
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'accepts ~ operator' do
|
243
|
+
assert_render(<<-HAML, <<-HTML, escape_html: false)
|
244
|
+
%span~ 1
|
245
|
+
HAML
|
246
|
+
<span>1</span>
|
247
|
+
HTML
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
189
251
|
describe 'whitespace removal' do
|
190
252
|
it 'removes outer whitespace by >' do
|
191
253
|
assert_render(<<-HAML, <<-HTML)
|
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.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
@@ -571,4 +571,3 @@ test_files:
|
|
571
571
|
- spec/rails/vendor/assets/javascripts/.keep
|
572
572
|
- spec/rails/vendor/assets/stylesheets/.keep
|
573
573
|
- spec/spec_helper.rb
|
574
|
-
has_rdoc:
|