fast_haml 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/fast_haml/ast.rb +25 -1
- data/lib/fast_haml/compiler.rb +37 -22
- data/lib/fast_haml/filter_compilers/base.rb +1 -1
- data/lib/fast_haml/filter_compilers/plain.rb +1 -1
- data/lib/fast_haml/filter_compilers/preserve.rb +1 -0
- data/lib/fast_haml/parser.rb +1 -0
- data/lib/fast_haml/railtie.rb +0 -5
- data/lib/fast_haml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e396fc6a76d932fc231a39783109c56be41fd5d2
|
4
|
+
data.tar.gz: 637ffb6b8faa7caf60cf8be200826740da3d521a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a9bbe7b0da60b072fb9c5eab60d8292e549e5b78989b6ff5e109de846e0321dd5425f5f92bcb85c534a3153e2889953950384d68d896cad01db5d73d362976c
|
7
|
+
data.tar.gz: fcb46c42e9801024c85e1232c92222f079c37c60694796b4ec682c4dd72a97499508aef4fc4584348b9dba9f71c6902b01a2b098871e552cc6bd79b7bd224aab
|
data/CHANGELOG.md
CHANGED
data/lib/fast_haml/ast.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
module FastHaml
|
2
2
|
module Ast
|
3
|
-
module
|
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
|
4
17
|
end
|
5
18
|
|
6
19
|
module HasChildren
|
@@ -15,10 +28,12 @@ module FastHaml
|
|
15
28
|
end
|
16
29
|
|
17
30
|
class Root < Struct.new(:children)
|
31
|
+
include LineCounter
|
18
32
|
include HasChildren
|
19
33
|
end
|
20
34
|
|
21
35
|
class Doctype < Struct.new(:doctype)
|
36
|
+
include LineCounter
|
22
37
|
end
|
23
38
|
|
24
39
|
class Element < Struct.new(
|
@@ -32,6 +47,7 @@ module FastHaml
|
|
32
47
|
:nuke_inner_whitespace,
|
33
48
|
:nuke_outer_whitespace,
|
34
49
|
)
|
50
|
+
include LineCounter
|
35
51
|
include HasChildren
|
36
52
|
|
37
53
|
def initialize(*)
|
@@ -52,6 +68,7 @@ module FastHaml
|
|
52
68
|
:preserve,
|
53
69
|
:mid_block_keyword,
|
54
70
|
)
|
71
|
+
include LineCounter
|
55
72
|
include HasChildren
|
56
73
|
|
57
74
|
def initialize(*)
|
@@ -69,6 +86,7 @@ module FastHaml
|
|
69
86
|
end
|
70
87
|
|
71
88
|
class SilentScript < Struct.new(:children, :script, :mid_block_keyword)
|
89
|
+
include LineCounter
|
72
90
|
include HasChildren
|
73
91
|
|
74
92
|
def initialize(*)
|
@@ -80,6 +98,7 @@ module FastHaml
|
|
80
98
|
end
|
81
99
|
|
82
100
|
class HtmlComment < Struct.new(:children, :comment, :conditional)
|
101
|
+
include LineCounter
|
83
102
|
include HasChildren
|
84
103
|
|
85
104
|
def initialize(*)
|
@@ -90,10 +109,13 @@ module FastHaml
|
|
90
109
|
end
|
91
110
|
|
92
111
|
class HamlComment < Struct.new(:children)
|
112
|
+
include LineCounter
|
93
113
|
include HasChildren
|
94
114
|
end
|
95
115
|
|
96
116
|
class Text < Struct.new(:text, :escape_html)
|
117
|
+
include LineCounter
|
118
|
+
|
97
119
|
def initialize(*)
|
98
120
|
super
|
99
121
|
if self.escape_html.nil?
|
@@ -103,6 +125,8 @@ module FastHaml
|
|
103
125
|
end
|
104
126
|
|
105
127
|
class Filter < Struct.new(:name, :texts)
|
128
|
+
include LineCounter
|
129
|
+
|
106
130
|
def initialize(*)
|
107
131
|
super
|
108
132
|
self.texts ||= []
|
data/lib/fast_haml/compiler.rb
CHANGED
@@ -44,32 +44,39 @@ 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
|
-
|
47
|
+
temple =
|
48
|
+
case ast
|
49
|
+
when Ast::Root
|
50
|
+
compile_root(ast)
|
51
|
+
when Ast::Doctype
|
52
|
+
compile_doctype(ast)
|
53
|
+
when Ast::HtmlComment
|
54
|
+
compile_html_comment(ast)
|
55
|
+
when Ast::HamlComment
|
56
|
+
[:multi]
|
57
|
+
when Ast::Element
|
58
|
+
compile_element(ast)
|
59
|
+
when Ast::Script
|
60
|
+
compile_script(ast)
|
61
|
+
when Ast::SilentScript
|
62
|
+
compile_silent_script(ast)
|
63
|
+
when Ast::Text
|
64
|
+
compile_text(ast)
|
65
|
+
when Ast::Filter
|
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)
|
66
73
|
else
|
67
|
-
|
74
|
+
temple
|
68
75
|
end
|
69
76
|
end
|
70
77
|
|
71
78
|
def compile_root(ast)
|
72
|
-
[:multi
|
79
|
+
[:multi].tap do |temple|
|
73
80
|
compile_children(ast, temple)
|
74
81
|
end
|
75
82
|
end
|
@@ -87,10 +94,15 @@ module FastHaml
|
|
87
94
|
if x != [:static, "\n"]
|
88
95
|
raise "InternalError: Unexpected pop (expected [:static, newline]): #{x}"
|
89
96
|
end
|
97
|
+
unless suppress_code_newline?(c.oneline_child)
|
98
|
+
temple << [:newline]
|
99
|
+
end
|
90
100
|
end
|
91
101
|
temple << compile(c)
|
92
102
|
if was_newline = need_newline?(ast, c)
|
93
103
|
temple << [:static, "\n"]
|
104
|
+
end
|
105
|
+
unless suppress_code_newline?(c)
|
94
106
|
temple << [:newline]
|
95
107
|
end
|
96
108
|
end
|
@@ -112,6 +124,10 @@ module FastHaml
|
|
112
124
|
end
|
113
125
|
end
|
114
126
|
|
127
|
+
def suppress_code_newline?(ast)
|
128
|
+
ast.is_a?(Ast::Script) || ast.is_a?(Ast::SilentScript) || (ast.is_a?(Ast::Element) && suppress_code_newline?(ast.oneline_child))
|
129
|
+
end
|
130
|
+
|
115
131
|
def compile_text(ast)
|
116
132
|
@text_compiler.compile(ast.text, escape_html: ast.escape_html)
|
117
133
|
end
|
@@ -169,7 +185,6 @@ module FastHaml
|
|
169
185
|
unless nuke_inner_whitespace?(ast)
|
170
186
|
children << [:static, "\n"]
|
171
187
|
end
|
172
|
-
children << [:newline]
|
173
188
|
compile_children(ast, children)
|
174
189
|
temple << children
|
175
190
|
end
|
@@ -8,7 +8,7 @@ module FastHaml
|
|
8
8
|
def compile_texts(temple, texts, tab_width: 0)
|
9
9
|
tabs = ' ' * tab_width
|
10
10
|
texts.each do |text|
|
11
|
-
temple << [:static, tabs] << text_compiler.compile(text) << [:static, "\n"]
|
11
|
+
temple << [:static, tabs] << text_compiler.compile(text) << [:static, "\n"] << [:newline]
|
12
12
|
end
|
13
13
|
nil
|
14
14
|
end
|
data/lib/fast_haml/parser.rb
CHANGED
data/lib/fast_haml/railtie.rb
CHANGED
@@ -2,11 +2,6 @@ module FastHaml
|
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
3
|
initializer :fast_haml do |app|
|
4
4
|
require 'fast_haml/rails_handler'
|
5
|
-
begin
|
6
|
-
# Load Haml::Plugin earlier to overwrite template handler with fast_haml.
|
7
|
-
require 'haml/plugin'
|
8
|
-
rescue LoadError
|
9
|
-
end
|
10
5
|
ActionView::Template.register_template_handler(:haml, FastHaml::RailsHandler.new)
|
11
6
|
end
|
12
7
|
end
|
data/lib/fast_haml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|