better_html 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/better_html/tokenizer/base_erb.rb +10 -6
- data/lib/better_html/version.rb +1 -1
- data/test/better_html/tokenizer/html_erb_test.rb +17 -0
- 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: dc67cce938ef29fb5f95f18d17e4c5be3f94013a
|
4
|
+
data.tar.gz: 01b068c022c1ecb3057cdced0f4a4841e50e341e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 222276cb0ffab3e5cd1dbaf9d05bf342f2e43ce2f39fd603bbbe7af93a7786780466eeb4c1f0568432a99399cc739b4a66e9d1b8a2603025f1cfac2cc2ac4789
|
7
|
+
data.tar.gz: ab87770d24442d8b175efdf07d1d2856053fcd1107a3ee2104037212c5b2833d6855d7ea86d2f9d14797894d4fafed0b12cd8da85f3d3dc7c683f3d7fced52d3
|
@@ -6,7 +6,7 @@ require 'parser/source/buffer'
|
|
6
6
|
module BetterHtml
|
7
7
|
module Tokenizer
|
8
8
|
class BaseErb < ::Erubi::Engine
|
9
|
-
REGEXP_WITHOUT_TRIM = /<%(={1,2}
|
9
|
+
REGEXP_WITHOUT_TRIM = /<%(={1,2})?(.*?)()?%>([ \t]*\r?\n)?/m
|
10
10
|
STMT_TRIM_MATCHER = /\A(-|#)?(.*?)([-=])?\z/m
|
11
11
|
EXPR_TRIM_MATCHER = /\A(.*?)(-)?\z/m
|
12
12
|
|
@@ -28,11 +28,15 @@ module BetterHtml
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def add_code(code)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
if code[0] == '%'
|
32
|
+
add_text("<%#{code}%>")
|
33
|
+
else
|
34
|
+
_, ltrim_or_comment, code, rtrim = *STMT_TRIM_MATCHER.match(code)
|
35
|
+
ltrim = ltrim_or_comment if ltrim_or_comment == '-'
|
36
|
+
indicator = ltrim_or_comment if ltrim_or_comment == '#'
|
37
|
+
add_erb_tokens(ltrim, indicator, code, rtrim)
|
38
|
+
append("<%#{ltrim}#{indicator}#{code}#{rtrim}%>")
|
39
|
+
end
|
36
40
|
end
|
37
41
|
|
38
42
|
def add_expression(indicator, code)
|
data/lib/better_html/version.rb
CHANGED
@@ -150,6 +150,23 @@ module BetterHtml
|
|
150
150
|
assert_attributes ({ type: :text, loc: { line: 3, source: "after" } }), scanner.tokens[6]
|
151
151
|
end
|
152
152
|
|
153
|
+
test "escaped opening ERB tag <%%" do
|
154
|
+
scanner = HtmlErb.new(buffer("just some <%%= text %> no erb"))
|
155
|
+
assert_equal 11, scanner.tokens.size
|
156
|
+
|
157
|
+
assert_attributes ({ type: :text, loc: { line: 1, source: "just some " } }), scanner.tokens[0]
|
158
|
+
assert_attributes ({ type: :tag_start, loc: { line: 1, source: '<' } }), scanner.tokens[1]
|
159
|
+
assert_attributes ({ type: :tag_name, loc: { line: 1, source: '%%=' } }), scanner.tokens[2]
|
160
|
+
assert_attributes ({ type: :whitespace, loc: { line: 1, source: " " } }), scanner.tokens[3]
|
161
|
+
assert_attributes ({ type: :attribute_name, loc: { line: 1, source: "text" } }), scanner.tokens[4]
|
162
|
+
assert_attributes ({ type: :whitespace, loc: { line: 1, source: " " } }), scanner.tokens[5]
|
163
|
+
assert_attributes ({ type: :malformed, loc: { line: 1, source: "%>" } }), scanner.tokens[6]
|
164
|
+
assert_attributes ({ type: :whitespace, loc: { line: 1, source: " " } }), scanner.tokens[7]
|
165
|
+
assert_attributes ({ type: :attribute_name, loc: { line: 1, source: "no" } }), scanner.tokens[8]
|
166
|
+
assert_attributes ({ type: :whitespace, loc: { line: 1, source: " " } }), scanner.tokens[9]
|
167
|
+
assert_attributes ({ type: :attribute_name, loc: { line: 1, source: "erb" } }), scanner.tokens[10]
|
168
|
+
end
|
169
|
+
|
153
170
|
private
|
154
171
|
|
155
172
|
def assert_attributes(attributes, token)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francois Chagnon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02
|
11
|
+
date: 2018-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|