better_html 1.0.6 → 1.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbf85413b0af66cc73a928d1b37c0ba104c848ae
4
- data.tar.gz: e934a9efa924f0647128517985f66d4dbd97f0de
3
+ metadata.gz: dc67cce938ef29fb5f95f18d17e4c5be3f94013a
4
+ data.tar.gz: 01b068c022c1ecb3057cdced0f4a4841e50e341e
5
5
  SHA512:
6
- metadata.gz: eb4ecf3184328d0388000db860f9126edad2e4a438c6c97623dbd29776d8f6a623fcbc5a24989c5fe47f0a92617eb0222738e28e5cae732d403a3bb805d3eb99
7
- data.tar.gz: 5843b4928f2983d53e36e44053423b21286daf6b20cc1d7d5ddab3e3ceffe5f3c16f71a6849205732cd4c9e8776e4d86c299ca1603751da5a4056044eb653369
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}|%)?(.*?)()?%>([ \t]*\r?\n)?/m
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
- _, ltrim_or_comment, code, rtrim = *STMT_TRIM_MATCHER.match(code)
32
- ltrim = ltrim_or_comment if ltrim_or_comment == '-'
33
- indicator = ltrim_or_comment if ltrim_or_comment == '#'
34
- add_erb_tokens(ltrim, indicator, code, rtrim)
35
- append("<%#{ltrim}#{indicator}#{code}#{rtrim}%>")
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)
@@ -1,3 +1,3 @@
1
1
  module BetterHtml
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
@@ -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.6
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-08 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast