hamlit 1.6.3 → 1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/hamlit/concerns/indentable.rb +21 -2
- data/lib/hamlit/parser.rb +2 -1
- data/lib/hamlit/parsers/comment.rb +3 -0
- data/lib/hamlit/parsers/tag.rb +9 -0
- data/lib/hamlit/parsers/text.rb +13 -1
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/error_spec.rb +47 -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: cc6af6b57be662141cab0bb717a24bdaf2e2406f
|
4
|
+
data.tar.gz: 65ce818ede5672f94b126ec19cc3a210a28c705e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1e3e8153d7f4978de1ab3992d46b67dd00399d7bb789a93a8d2b6e7c6c91a20e7662d93d99369f7f7faf4f7f12b260b499d98c34dea286fede0177ee81548e0
|
7
|
+
data.tar.gz: 04d290e8d75dc51ecd31e5c0f404bdb200b7d42fb528f2612054a05efeb59f8fb09c37b9297c780bf22087de3174070a5e51d1febca667c2a45080fd73eec1b1
|
data/CHANGELOG.md
CHANGED
@@ -52,8 +52,9 @@ module Hamlit
|
|
52
52
|
@indent_space = @indent_logs.last
|
53
53
|
end
|
54
54
|
validate_indentation_consistency!(indent)
|
55
|
+
reject_too_deep_indentation!
|
55
56
|
|
56
|
-
next_indent
|
57
|
+
next_indent < @current_indent
|
57
58
|
end
|
58
59
|
|
59
60
|
def has_block?
|
@@ -70,12 +71,30 @@ module Hamlit
|
|
70
71
|
return false if indent.empty?
|
71
72
|
return false if !@indent_space || @indent_space.empty?
|
72
73
|
|
73
|
-
|
74
|
+
unless acceptable_indent?(indent)
|
74
75
|
syntax_error!("Inconsistent indentation: #{indent_label(indent)} used for indentation, "\
|
75
76
|
"but the rest of the document was indented using #{indent_label(@indent_space)}.")
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
80
|
+
def acceptable_indent?(indent)
|
81
|
+
indent = indent.dup
|
82
|
+
while indent.match(/^#{@indent_space}/)
|
83
|
+
indent.gsub!(/^#{@indent_space}/, '')
|
84
|
+
end
|
85
|
+
indent.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def reject_too_deep_indentation!
|
89
|
+
return if next_indent <= @current_indent
|
90
|
+
|
91
|
+
if @indent_logs.length == 1
|
92
|
+
syntax_error!('Indenting at the beginning of the document is illegal.')
|
93
|
+
else
|
94
|
+
syntax_error!("The line was indented #{next_indent - count_indent(current_line)} levels deeper than the previous line.")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
79
98
|
def indent_label(indent)
|
80
99
|
return %Q{"#{indent}"} if indent.include?(' ') && indent.include?("\t")
|
81
100
|
|
data/lib/hamlit/parser.rb
CHANGED
@@ -62,6 +62,7 @@ module Hamlit
|
|
62
62
|
end
|
63
63
|
ast
|
64
64
|
rescue => e
|
65
|
+
ast << [:newline]
|
65
66
|
ast << syntax_error(e.message)
|
66
67
|
ast
|
67
68
|
end
|
@@ -117,7 +118,7 @@ module Hamlit
|
|
117
118
|
when '=', '~'
|
118
119
|
parse_script(scanner)
|
119
120
|
else
|
120
|
-
parse_text(scanner, lstrip: true)
|
121
|
+
parse_text(scanner, lstrip: true, inline: inline)
|
121
122
|
end
|
122
123
|
end
|
123
124
|
|
@@ -16,6 +16,9 @@ module Hamlit
|
|
16
16
|
content = with_indented { parse_lines }
|
17
17
|
return ast << [:multi, [:static, "\n"], *content]
|
18
18
|
elsif !text.match(/\[.*\]/)
|
19
|
+
if has_block?
|
20
|
+
syntax_error!('Illegal nesting: nesting within a tag that already has content is illegal.')
|
21
|
+
end
|
19
22
|
return ast << [:static, " #{text} "]
|
20
23
|
end
|
21
24
|
|
data/lib/hamlit/parsers/tag.rb
CHANGED
@@ -32,6 +32,7 @@ module Hamlit
|
|
32
32
|
elsif scanner.match?(/\//)
|
33
33
|
return syntax_error("Illegal nesting: nesting within a self-closing tag is illegal.")
|
34
34
|
end
|
35
|
+
validate_content_existence!(tag, scanner)
|
35
36
|
|
36
37
|
content = [:multi, [:static, "\n"]]
|
37
38
|
if inner_removal || Helpers::DEFAULT_PRESERVE_TAGS.include?(tag)
|
@@ -64,6 +65,14 @@ module Hamlit
|
|
64
65
|
end
|
65
66
|
ast
|
66
67
|
end
|
68
|
+
|
69
|
+
def validate_content_existence!(tag, scanner)
|
70
|
+
scanner.scan(/ */)
|
71
|
+
|
72
|
+
if scanner.match?(/[^ ]/)
|
73
|
+
syntax_error!("Illegal nesting: content can't be both given on the same line as %#{tag} and nested within it.")
|
74
|
+
end
|
75
|
+
end
|
67
76
|
end
|
68
77
|
end
|
69
78
|
end
|
data/lib/hamlit/parsers/text.rb
CHANGED
@@ -5,12 +5,24 @@ module Hamlit
|
|
5
5
|
module Text
|
6
6
|
include Concerns::Error
|
7
7
|
|
8
|
-
def parse_text(scanner, lstrip: false, escape: true, scan: nil)
|
8
|
+
def parse_text(scanner, lstrip: false, escape: true, scan: nil, inline: true)
|
9
|
+
reject_text_nesting! unless inline
|
10
|
+
|
9
11
|
scanner.scan(scan) if scan
|
10
12
|
text = (scanner.scan(/.+/) || '')
|
11
13
|
text = text.lstrip if lstrip
|
12
14
|
[:haml, :text, text, escape]
|
13
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def reject_text_nesting!
|
20
|
+
return unless next_line
|
21
|
+
|
22
|
+
if next_indent > @current_indent
|
23
|
+
syntax_error!('Illegal nesting: nesting within plain text is illegal.')
|
24
|
+
end
|
25
|
+
end
|
14
26
|
end
|
15
27
|
end
|
16
28
|
end
|
data/lib/hamlit/version.rb
CHANGED
@@ -84,5 +84,52 @@ describe Hamlit::Engine do
|
|
84
84
|
HAML
|
85
85
|
to raise_error(Hamlit::SyntaxError, "Illegal nesting: nesting within a self-closing tag is illegal.")
|
86
86
|
end
|
87
|
+
|
88
|
+
it 'rejects illegal indentation' do
|
89
|
+
expect { render_string(<<-HAML.unindent) }.
|
90
|
+
hello
|
91
|
+
world
|
92
|
+
HAML
|
93
|
+
to raise_error(Hamlit::SyntaxError, 'Illegal nesting: nesting within plain text is illegal.')
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'rejects illegal indentation' do
|
97
|
+
expect { render_string(<<-HAML.unindent) }.
|
98
|
+
%span hello
|
99
|
+
world
|
100
|
+
HAML
|
101
|
+
to raise_error(Hamlit::SyntaxError, "Illegal nesting: content can't be both given on the same line as %span and nested within it.")
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'rejects illegal indentation' do
|
105
|
+
expect { render_string(<<-HAML.unindent) }.
|
106
|
+
/ hello
|
107
|
+
world
|
108
|
+
HAML
|
109
|
+
to raise_error(Hamlit::SyntaxError, 'Illegal nesting: nesting within a tag that already has content is illegal.')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'rejects illegal indentation' do
|
113
|
+
expect { render_string(<<-HAML.unindent) }.
|
114
|
+
%span
|
115
|
+
%span
|
116
|
+
%span
|
117
|
+
HAML
|
118
|
+
to raise_error(Hamlit::SyntaxError, 'The line was indented 2 levels deeper than the previous line.')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'rejects illegal indentation' do
|
122
|
+
expect { render_string(<<-HAML.unindent) }.
|
123
|
+
%span
|
124
|
+
%span
|
125
|
+
%span
|
126
|
+
HAML
|
127
|
+
to raise_error(Hamlit::SyntaxError, "Inconsistent indentation: 6 spaces used for indentation, but the rest of the document was indented using 4 spaces.")
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'rejects illegal indentation' do
|
131
|
+
expect { render_string(' hello') }.
|
132
|
+
to raise_error(Hamlit::SyntaxError, 'Indenting at the beginning of the document is illegal.')
|
133
|
+
end
|
87
134
|
end
|
88
135
|
end
|