haml-edge 2.3.57 → 2.3.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/EDGE_GEM_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/haml/html/erb.rb +76 -6
- data/lib/haml/html.rb +4 -1
- metadata +10 -10
data/EDGE_GEM_VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.3.
|
|
1
|
+
2.3.58
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.3.
|
|
1
|
+
2.3.58
|
data/lib/haml/html/erb.rb
CHANGED
|
@@ -4,62 +4,132 @@ require 'ruby_parser'
|
|
|
4
4
|
|
|
5
5
|
module Haml
|
|
6
6
|
class HTML
|
|
7
|
+
# A class for converting ERB code into a format that's easier
|
|
8
|
+
# for the {Haml::HTML} Hpricot-based parser to understand.
|
|
9
|
+
#
|
|
10
|
+
# Uses [Erubis](http://www.kuwata-lab.com/erubis)'s extensible parsing powers
|
|
11
|
+
# to parse the ERB in a reliable way,
|
|
12
|
+
# and [ruby_parser](http://parsetree.rubyforge.org/)'s Ruby knowledge
|
|
13
|
+
# to figure out whether a given chunk of Ruby code starts a block or not.
|
|
14
|
+
#
|
|
15
|
+
# The ERB tags are converted to HTML tags in the following way.
|
|
16
|
+
# `<% ... %>` is converted into `<haml:silent> ... </haml:silent>`.
|
|
17
|
+
# `<%= ... %>` is converted into `<haml:loud> ... </haml:loud>`.
|
|
18
|
+
# Finally, if either of these opens a Ruby block,
|
|
19
|
+
# `<haml:block> ... </haml:block>` will wrap the entire contents of the block -
|
|
20
|
+
# that is, everything that should be indented beneath the previous silent or loud tag.
|
|
7
21
|
class ERB < Erubis::Basic::Engine
|
|
22
|
+
# Compiles an ERB template into a HTML document containing `haml:` tags.
|
|
23
|
+
#
|
|
24
|
+
# @param template [String] The ERB template
|
|
25
|
+
# @return [String] The output document
|
|
26
|
+
# @see {Haml::HTML::ERB}
|
|
8
27
|
def self.compile(template)
|
|
9
28
|
new(template).src
|
|
10
29
|
end
|
|
11
30
|
|
|
31
|
+
# `html2haml` doesn't support HTML-escaped expressions.
|
|
12
32
|
def escaped_expr(code)
|
|
13
33
|
raise "html2haml doesn't support escaped expressions."
|
|
14
34
|
end
|
|
15
35
|
|
|
36
|
+
# The ERB-to-Hamlized-HTML conversion has no preamble.
|
|
16
37
|
def add_preamble(src); end
|
|
38
|
+
|
|
39
|
+
# The ERB-to-Hamlized-HTML conversion has no postamble.
|
|
17
40
|
def add_postamble(src); end
|
|
18
41
|
|
|
42
|
+
# Concatenates the text onto the source buffer.
|
|
43
|
+
#
|
|
44
|
+
# @param src [String] The source buffer
|
|
45
|
+
# @param text [String] The raw text to add to the buffer
|
|
19
46
|
def add_text(src, text)
|
|
20
47
|
src << text
|
|
21
48
|
end
|
|
22
49
|
|
|
50
|
+
# Concatenates a silent Ruby statement onto the source buffer.
|
|
51
|
+
# This uses the `<haml:silent>` tag,
|
|
52
|
+
# and may close and/or open a Ruby block with the `<haml:block>` tag.
|
|
53
|
+
#
|
|
54
|
+
# In particular, a block is closed if this statement is some form of `end`,
|
|
55
|
+
# opened if it's a block opener like `do`, `if`, or `begin`,
|
|
56
|
+
# and both closed and opened if it's a mid-block keyword
|
|
57
|
+
# like `else` or `when`.
|
|
58
|
+
#
|
|
59
|
+
# @param src [String] The source buffer
|
|
60
|
+
# @param code [String] The Ruby statement to add to the buffer
|
|
23
61
|
def add_stmt(src, code)
|
|
24
62
|
src << '</haml:block>' if block_closer?(code) || mid_block?(code)
|
|
25
63
|
src << '<haml:silent>' << h(code) << '</haml:silent>' unless code.strip == "end"
|
|
26
64
|
src << '<haml:block>' if block_opener?(code) || mid_block?(code)
|
|
27
65
|
end
|
|
28
66
|
|
|
67
|
+
# Concatenates a Ruby expression that's printed to the document
|
|
68
|
+
# onto the source buffer.
|
|
69
|
+
# This uses the `<haml:silent>` tag,
|
|
70
|
+
# and may open a Ruby block with the `<haml:block>` tag.
|
|
71
|
+
# An expression never closes a block.
|
|
72
|
+
#
|
|
73
|
+
# @param src [String] The source buffer
|
|
74
|
+
# @param code [String] The Ruby expression to add to the buffer
|
|
29
75
|
def add_expr_literal(src, code)
|
|
30
76
|
src << '<haml:loud>' << h(code) << '</haml:loud>'
|
|
31
77
|
src << '<haml:block>' if block_opener?(code)
|
|
32
78
|
end
|
|
33
79
|
|
|
80
|
+
# `html2haml` doesn't support debugging expressions.
|
|
34
81
|
def add_expr_debug(src, code)
|
|
35
82
|
raise "html2haml doesn't support debugging expressions."
|
|
36
83
|
end
|
|
37
84
|
|
|
38
85
|
private
|
|
39
86
|
|
|
40
|
-
|
|
41
|
-
|
|
87
|
+
# HTML-escaped some text (in practice, always Ruby code).
|
|
88
|
+
# A utility method.
|
|
89
|
+
#
|
|
90
|
+
# @param text [String] The text to escape
|
|
91
|
+
# @return [String] The escaped text
|
|
92
|
+
def h(text)
|
|
93
|
+
CGI.escapeHTML(text)
|
|
42
94
|
end
|
|
43
95
|
|
|
44
|
-
# Returns whether the code is valid Ruby code on its own
|
|
96
|
+
# Returns whether the code is valid Ruby code on its own.
|
|
97
|
+
#
|
|
98
|
+
# @param code [String] Ruby code to check
|
|
99
|
+
# @return [Boolean]
|
|
45
100
|
def valid_ruby?(code)
|
|
46
101
|
RubyParser.new.parse(code)
|
|
47
102
|
rescue Racc::ParseError => e
|
|
48
103
|
false
|
|
49
104
|
end
|
|
50
105
|
|
|
51
|
-
# Checks if
|
|
106
|
+
# Checks if a string of Ruby code opens a block.
|
|
107
|
+
# This could either be something like `foo do |a|`
|
|
108
|
+
# or a keyword that requires a matching `end`
|
|
109
|
+
# like `if`, `begin`, or `case`.
|
|
110
|
+
#
|
|
111
|
+
# @param code [String] Ruby code to check
|
|
112
|
+
# @return [Boolean]
|
|
52
113
|
def block_opener?(code)
|
|
53
114
|
valid_ruby?(code + "\nend") ||
|
|
54
115
|
valid_ruby?(code + "\nwhen foo\nend")
|
|
55
116
|
end
|
|
56
117
|
|
|
57
|
-
# Checks if
|
|
118
|
+
# Checks if a string of Ruby code closes a block.
|
|
119
|
+
# This is always `end` followed optionally by some method calls.
|
|
120
|
+
#
|
|
121
|
+
# @param code [String] Ruby code to check
|
|
122
|
+
# @return [Boolean]
|
|
58
123
|
def block_closer?(code)
|
|
59
124
|
valid_ruby?("begin\n" + code)
|
|
60
125
|
end
|
|
61
126
|
|
|
62
|
-
# Checks if
|
|
127
|
+
# Checks if a string of Ruby code comes in the middle of a block.
|
|
128
|
+
# This could be a keyword like `else`, `rescue`, or `when`,
|
|
129
|
+
# or even `end` with a method call that takes a block.
|
|
130
|
+
#
|
|
131
|
+
# @param code [String] Ruby code to check
|
|
132
|
+
# @return [Boolean]
|
|
63
133
|
def mid_block?(code)
|
|
64
134
|
return if valid_ruby?(code)
|
|
65
135
|
valid_ruby?("if foo\n#{code}\nend") || # else, elsif
|
data/lib/haml/html.rb
CHANGED
|
@@ -97,7 +97,10 @@ require 'hpricot'
|
|
|
97
97
|
|
|
98
98
|
module Haml
|
|
99
99
|
# Converts HTML documents into Haml templates.
|
|
100
|
-
# Depends on [Hpricot](http://
|
|
100
|
+
# Depends on [Hpricot](http://github.com/whymirror/hpricot) for HTML parsing.
|
|
101
|
+
# If ERB conversion is being used, also depends on
|
|
102
|
+
# [Erubis](http://www.kuwata-lab.com/erubis) to parse the ERB
|
|
103
|
+
# and [ruby_parser](http://parsetree.rubyforge.org/) to parse the Ruby code.
|
|
101
104
|
#
|
|
102
105
|
# Example usage:
|
|
103
106
|
#
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: haml-edge
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.3.
|
|
4
|
+
version: 2.3.58
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Weizenbaum
|
|
@@ -65,6 +65,8 @@ files:
|
|
|
65
65
|
- lib/haml/helpers/action_view_mods.rb
|
|
66
66
|
- lib/haml/helpers/xss_mods.rb
|
|
67
67
|
- lib/haml/html.rb
|
|
68
|
+
- lib/haml/html
|
|
69
|
+
- lib/haml/html/erb.rb
|
|
68
70
|
- lib/haml/precompiler.rb
|
|
69
71
|
- lib/haml/shared.rb
|
|
70
72
|
- lib/haml/template.rb
|
|
@@ -73,8 +75,6 @@ files:
|
|
|
73
75
|
- lib/haml/template/plugin.rb
|
|
74
76
|
- lib/haml/util.rb
|
|
75
77
|
- lib/haml/version.rb
|
|
76
|
-
- lib/haml/html
|
|
77
|
-
- lib/haml/html/erb.rb
|
|
78
78
|
- lib/sass.rb
|
|
79
79
|
- lib/sass
|
|
80
80
|
- lib/sass/css.rb
|
|
@@ -124,6 +124,11 @@ files:
|
|
|
124
124
|
- test/benchmark.rb
|
|
125
125
|
- test/haml
|
|
126
126
|
- test/haml/engine_test.rb
|
|
127
|
+
- test/haml/erb
|
|
128
|
+
- test/haml/erb/_av_partial_1.erb
|
|
129
|
+
- test/haml/erb/_av_partial_2.erb
|
|
130
|
+
- test/haml/erb/action_view.erb
|
|
131
|
+
- test/haml/erb/standard.rhtml
|
|
127
132
|
- test/haml/helper_test.rb
|
|
128
133
|
- test/haml/html2haml_test.rb
|
|
129
134
|
- test/haml/markaby
|
|
@@ -150,11 +155,7 @@ files:
|
|
|
150
155
|
- test/haml/results/very_basic.xhtml
|
|
151
156
|
- test/haml/results/whitespace_handling.xhtml
|
|
152
157
|
- test/haml/spec
|
|
153
|
-
- test/haml/
|
|
154
|
-
- test/haml/erb/_av_partial_1.erb
|
|
155
|
-
- test/haml/erb/_av_partial_2.erb
|
|
156
|
-
- test/haml/erb/action_view.erb
|
|
157
|
-
- test/haml/erb/standard.rhtml
|
|
158
|
+
- test/haml/spec_test.rb
|
|
158
159
|
- test/haml/template_test.rb
|
|
159
160
|
- test/haml/templates
|
|
160
161
|
- test/haml/templates/_av_partial_1.haml
|
|
@@ -189,7 +190,6 @@ files:
|
|
|
189
190
|
- test/haml/templates/very_basic.haml
|
|
190
191
|
- test/haml/templates/whitespace_handling.haml
|
|
191
192
|
- test/haml/util_test.rb
|
|
192
|
-
- test/haml/spec_test.rb
|
|
193
193
|
- test/linked_rails.rb
|
|
194
194
|
- test/sass
|
|
195
195
|
- test/sass/css2sass_test.rb
|
|
@@ -303,9 +303,9 @@ test_files:
|
|
|
303
303
|
- test/haml/engine_test.rb
|
|
304
304
|
- test/haml/helper_test.rb
|
|
305
305
|
- test/haml/html2haml_test.rb
|
|
306
|
+
- test/haml/spec_test.rb
|
|
306
307
|
- test/haml/template_test.rb
|
|
307
308
|
- test/haml/util_test.rb
|
|
308
|
-
- test/haml/spec_test.rb
|
|
309
309
|
- test/sass/css2sass_test.rb
|
|
310
310
|
- test/sass/engine_test.rb
|
|
311
311
|
- test/sass/functions_test.rb
|