fast_haml 0.1.3 → 0.1.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 +4 -0
- data/lib/fast_haml/ast.rb +14 -27
- data/lib/fast_haml/compiler.rb +22 -28
- data/lib/fast_haml/parser.rb +6 -1
- data/lib/fast_haml/version.rb +1 -1
- data/spec/compiler_newline_spec.rb +24 -0
- data/spec/render/filters/preserve_spec.rb +0 -1
- 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: e6d99c4413e3858045374b49a571cd49b41a6bdd
|
4
|
+
data.tar.gz: 9cca499f18f80fbd21e45fc661feafdf133342a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7823392fa8c824f2658a6f2e565cc0c31a142e0dcff1e7e087f290248ff1775f1898ba8afcf33ca762c595f608f32ca29960f821be97841b515e4d23fd17ad0
|
7
|
+
data.tar.gz: 445518be81a78566281badd2336ec90f6c2a7b9cd1b515f2276bf32d8e285f9d7a8380634116fd3aee58d654064f04059075d4f322598f525534d410b59f8a9b
|
data/CHANGELOG.md
CHANGED
data/lib/fast_haml/ast.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
1
|
module FastHaml
|
2
2
|
module Ast
|
3
|
-
module LineCounter
|
4
|
-
def initialize(*)
|
5
|
-
super
|
6
|
-
@trailing_empty_lines = 0
|
7
|
-
end
|
8
|
-
|
9
|
-
def trailing_empty_lines
|
10
|
-
@trailing_empty_lines
|
11
|
-
end
|
12
|
-
|
13
|
-
def increment_trailing_empty_lines
|
14
|
-
@trailing_empty_lines += 1
|
15
|
-
nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
3
|
module HasChildren
|
20
4
|
def initialize(*)
|
21
5
|
super
|
@@ -28,12 +12,21 @@ module FastHaml
|
|
28
12
|
end
|
29
13
|
|
30
14
|
class Root < Struct.new(:children)
|
31
|
-
include LineCounter
|
32
15
|
include HasChildren
|
16
|
+
attr_reader :leading_empty_lines
|
17
|
+
|
18
|
+
def initialize(*)
|
19
|
+
super
|
20
|
+
@leading_empty_lines = 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def increment_leading_empty_lines
|
24
|
+
@leading_empty_lines +=1
|
25
|
+
nil
|
26
|
+
end
|
33
27
|
end
|
34
28
|
|
35
29
|
class Doctype < Struct.new(:doctype)
|
36
|
-
include LineCounter
|
37
30
|
end
|
38
31
|
|
39
32
|
class Element < Struct.new(
|
@@ -47,7 +40,6 @@ module FastHaml
|
|
47
40
|
:nuke_inner_whitespace,
|
48
41
|
:nuke_outer_whitespace,
|
49
42
|
)
|
50
|
-
include LineCounter
|
51
43
|
include HasChildren
|
52
44
|
|
53
45
|
def initialize(*)
|
@@ -68,7 +60,6 @@ module FastHaml
|
|
68
60
|
:preserve,
|
69
61
|
:mid_block_keyword,
|
70
62
|
)
|
71
|
-
include LineCounter
|
72
63
|
include HasChildren
|
73
64
|
|
74
65
|
def initialize(*)
|
@@ -86,7 +77,6 @@ module FastHaml
|
|
86
77
|
end
|
87
78
|
|
88
79
|
class SilentScript < Struct.new(:children, :script, :mid_block_keyword)
|
89
|
-
include LineCounter
|
90
80
|
include HasChildren
|
91
81
|
|
92
82
|
def initialize(*)
|
@@ -98,7 +88,6 @@ module FastHaml
|
|
98
88
|
end
|
99
89
|
|
100
90
|
class HtmlComment < Struct.new(:children, :comment, :conditional)
|
101
|
-
include LineCounter
|
102
91
|
include HasChildren
|
103
92
|
|
104
93
|
def initialize(*)
|
@@ -109,13 +98,10 @@ module FastHaml
|
|
109
98
|
end
|
110
99
|
|
111
100
|
class HamlComment < Struct.new(:children)
|
112
|
-
include LineCounter
|
113
101
|
include HasChildren
|
114
102
|
end
|
115
103
|
|
116
104
|
class Text < Struct.new(:text, :escape_html)
|
117
|
-
include LineCounter
|
118
|
-
|
119
105
|
def initialize(*)
|
120
106
|
super
|
121
107
|
if self.escape_html.nil?
|
@@ -125,12 +111,13 @@ module FastHaml
|
|
125
111
|
end
|
126
112
|
|
127
113
|
class Filter < Struct.new(:name, :texts)
|
128
|
-
include LineCounter
|
129
|
-
|
130
114
|
def initialize(*)
|
131
115
|
super
|
132
116
|
self.texts ||= []
|
133
117
|
end
|
134
118
|
end
|
119
|
+
|
120
|
+
class Empty
|
121
|
+
end
|
135
122
|
end
|
136
123
|
end
|
data/lib/fast_haml/compiler.rb
CHANGED
@@ -44,39 +44,33 @@ module FastHaml
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def compile(ast)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
compile_filter(ast)
|
67
|
-
else
|
68
|
-
raise "InternalError: Unknown AST node #{ast.class}: #{ast.inspect}"
|
69
|
-
end
|
70
|
-
|
71
|
-
if ast.trailing_empty_lines > 0
|
72
|
-
[:multi, temple].concat([[:newline]] * ast.trailing_empty_lines)
|
47
|
+
case ast
|
48
|
+
when Ast::Root
|
49
|
+
compile_root(ast)
|
50
|
+
when Ast::Doctype
|
51
|
+
compile_doctype(ast)
|
52
|
+
when Ast::HtmlComment
|
53
|
+
compile_html_comment(ast)
|
54
|
+
when Ast::HamlComment, Ast::Empty
|
55
|
+
[:multi]
|
56
|
+
when Ast::Element
|
57
|
+
compile_element(ast)
|
58
|
+
when Ast::Script
|
59
|
+
compile_script(ast)
|
60
|
+
when Ast::SilentScript
|
61
|
+
compile_silent_script(ast)
|
62
|
+
when Ast::Text
|
63
|
+
compile_text(ast)
|
64
|
+
when Ast::Filter
|
65
|
+
compile_filter(ast)
|
73
66
|
else
|
74
|
-
|
67
|
+
raise "InternalError: Unknown AST node #{ast.class}: #{ast.inspect}"
|
75
68
|
end
|
76
69
|
end
|
77
70
|
|
78
71
|
def compile_root(ast)
|
79
72
|
[:multi].tap do |temple|
|
73
|
+
temple.concat([[:newline]] * ast.leading_empty_lines)
|
80
74
|
compile_children(ast, temple)
|
81
75
|
end
|
82
76
|
end
|
@@ -118,7 +112,7 @@ module FastHaml
|
|
118
112
|
case child
|
119
113
|
when Ast::Script
|
120
114
|
child.children.empty?
|
121
|
-
when Ast::SilentScript, Ast::HamlComment
|
115
|
+
when Ast::SilentScript, Ast::HamlComment, Ast::Empty
|
122
116
|
false
|
123
117
|
when Ast::Element
|
124
118
|
!child.nuke_outer_whitespace
|
data/lib/fast_haml/parser.rb
CHANGED
@@ -59,7 +59,7 @@ module FastHaml
|
|
59
59
|
text, indent = @indent_tracker.process(line, @line_parser.lineno)
|
60
60
|
|
61
61
|
if text.empty?
|
62
|
-
@ast.
|
62
|
+
@ast << Ast::Empty.new
|
63
63
|
return
|
64
64
|
end
|
65
65
|
|
@@ -200,8 +200,13 @@ module FastHaml
|
|
200
200
|
end
|
201
201
|
|
202
202
|
def indent_enter(_, text)
|
203
|
+
empty_lines = []
|
204
|
+
while @ast.children.last.is_a?(Ast::Empty)
|
205
|
+
empty_lines << @ast.children.pop
|
206
|
+
end
|
203
207
|
@stack.push(@ast)
|
204
208
|
@ast = @ast.children.last
|
209
|
+
@ast.children = empty_lines
|
205
210
|
if @ast.is_a?(Ast::Element) && @ast.self_closing
|
206
211
|
syntax_error!('Illegal nesting: nesting within a self-closing tag is illegal')
|
207
212
|
end
|
data/lib/fast_haml/version.rb
CHANGED
@@ -41,6 +41,30 @@ HAML
|
|
41
41
|
%span hello
|
42
42
|
%span #{raise LineVerifier}
|
43
43
|
%span world
|
44
|
+
HAML
|
45
|
+
end
|
46
|
+
|
47
|
+
it do
|
48
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(2))
|
49
|
+
|
50
|
+
%div= raise LineVerifier
|
51
|
+
HAML
|
52
|
+
end
|
53
|
+
|
54
|
+
it do
|
55
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(4))
|
56
|
+
%div
|
57
|
+
%span= 1
|
58
|
+
|
59
|
+
%span= raise LineVerifier
|
60
|
+
HAML
|
61
|
+
end
|
62
|
+
|
63
|
+
it do
|
64
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(3))
|
65
|
+
%div
|
66
|
+
|
67
|
+
%span= raise LineVerifier
|
44
68
|
HAML
|
45
69
|
end
|
46
70
|
end
|
@@ -3,7 +3,6 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe 'Preserve filter rendering', type: :render do
|
4
4
|
it 'renders preserve filter' do
|
5
5
|
expect(render_string(<<'HAML')).to eq("<span>start</span>\nhello
 <p>wor
ld</p>
<span>hello</span>\n<span>end</span>\n")
|
6
|
-
|
7
6
|
%span start
|
8
7
|
:preserve
|
9
8
|
hello
|