hamlit 1.4.1 → 1.4.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 +6 -1
- data/lib/hamlit/compilers/old_attribute.rb +1 -5
- data/lib/hamlit/compilers/text.rb +4 -2
- data/lib/hamlit/parser.rb +4 -2
- data/lib/hamlit/parsers/text.rb +12 -0
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/text_spec.rb +16 -0
- 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: 48c63183e137f6ac95b74b18913665a72dd93a10
|
4
|
+
data.tar.gz: aa406f516907e362b2f1746636ed9c06b5c81d92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd0f4d8ca9147def6ea19af310e42ef000626da8b08346644d47ffd38d30b894d6150837ed2a065e141a1b81db6525f6fc184a5dc542cf3653858a96914e5d9d
|
7
|
+
data.tar.gz: fdc76ab6d2b810b8c8b0b7c284bb36fefadbcba42cedd9fc1371bc26b96133342f157945827a7ae821213afdf31c28671954be054f0db8b4bbba81a987377104
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## v1.4.2
|
2
|
+
|
3
|
+
- Support `!` operator
|
4
|
+
- It disables html escaping for interpolated text
|
5
|
+
|
1
6
|
## v1.4.1
|
2
7
|
|
3
8
|
- Fix code mistake in 1.4.0
|
@@ -17,7 +22,7 @@
|
|
17
22
|
|
18
23
|
## v1.3.0
|
19
24
|
|
20
|
-
- Resurrect
|
25
|
+
- Resurrect escape\_html option
|
21
26
|
- Still enabled by default
|
22
27
|
- This has been dropped since v0.6.0
|
23
28
|
- https://github.com/k0kubun/hamlit/issues/25
|
@@ -152,11 +152,7 @@ module Hamlit
|
|
152
152
|
splitted = []
|
153
153
|
start_pos = 1
|
154
154
|
columns.each do |end_pos|
|
155
|
-
|
156
|
-
splitted << str[start_pos..(end_pos - 1)]
|
157
|
-
else
|
158
|
-
splitted << str.unpack("C*")[start_pos..(end_pos - 1)].pack("C*").force_encoding('utf-8')
|
159
|
-
end
|
155
|
+
splitted << str.byteslice(start_pos...end_pos)
|
160
156
|
start_pos = end_pos + 1
|
161
157
|
end
|
162
158
|
|
@@ -19,7 +19,7 @@ module Hamlit
|
|
19
19
|
|
20
20
|
# Return static and dynamic temple ast.
|
21
21
|
# It splits expression to optimize because string interpolation is slow.
|
22
|
-
def on_haml_text(exp)
|
22
|
+
def on_haml_text(exp, escape_html = true)
|
23
23
|
return static_text(exp) unless contains_interpolation?(exp)
|
24
24
|
|
25
25
|
marker = find_string_marker(exp)
|
@@ -31,7 +31,9 @@ module Hamlit
|
|
31
31
|
pre = exp.byteslice(0...open_pos)
|
32
32
|
body = exp.byteslice((open_pos + 2)...close_pos)
|
33
33
|
post = exp.byteslice((close_pos + 1)...exp.bytesize)
|
34
|
-
|
34
|
+
|
35
|
+
body_ast = escape_html ? escape_html([:dynamic, body]) : [:dynamic, body]
|
36
|
+
[:multi, [:static, pre], body_ast, on_haml_text(post)]
|
35
37
|
end
|
36
38
|
|
37
39
|
def find_interpolation(exp, marker)
|
data/lib/hamlit/parser.rb
CHANGED
@@ -87,15 +87,17 @@ module Hamlit
|
|
87
87
|
return parse_text(scanner)
|
88
88
|
elsif scanner.match?(/&=/)
|
89
89
|
return parse_script(scanner, force_escape: true)
|
90
|
+
elsif scanner.match?(/!!!/)
|
91
|
+
return parse_doctype(scanner)
|
90
92
|
elsif scanner.match?(/!=/)
|
91
93
|
return parse_script(scanner, disable_escape: true)
|
94
|
+
elsif scanner.match?(/! /)
|
95
|
+
return parse_unescaped_text(scanner)
|
92
96
|
elsif scanner.match?(/[.#](\Z|[^a-zA-Z0-9_-])/)
|
93
97
|
return parse_text(scanner)
|
94
98
|
end
|
95
99
|
|
96
100
|
case scanner.peek(1)
|
97
|
-
when '!'
|
98
|
-
parse_doctype(scanner)
|
99
101
|
when '%', '.', '#'
|
100
102
|
parse_tag(scanner)
|
101
103
|
when '=', '~'
|
data/lib/hamlit/parsers/text.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
|
+
require 'hamlit/concerns/error'
|
2
|
+
|
1
3
|
module Hamlit
|
2
4
|
module Parsers
|
3
5
|
module Text
|
6
|
+
include Concerns::Error
|
7
|
+
|
4
8
|
def parse_text(scanner)
|
5
9
|
ast = [:haml, :text]
|
6
10
|
ast << (scanner.scan(/.+/) || '')
|
7
11
|
ast
|
8
12
|
end
|
13
|
+
|
14
|
+
def parse_unescaped_text(scanner)
|
15
|
+
assert_scan!(scanner, /! /)
|
16
|
+
scanner.scan(/ +/)
|
17
|
+
|
18
|
+
text = (scanner.scan(/.+/) || '')
|
19
|
+
[:haml, :text, text, false]
|
20
|
+
end
|
9
21
|
end
|
10
22
|
end
|
11
23
|
end
|
data/lib/hamlit/version.rb
CHANGED
@@ -43,6 +43,22 @@ describe Hamlit::Engine do
|
|
43
43
|
expect(render_string('\ a')).to eq(" a\n")
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'renders ! operator' do
|
47
|
+
assert_render(<<-'HAML', <<-HTML)
|
48
|
+
aaa#{'<a>'}
|
49
|
+
!aaa#{'<a>'}
|
50
|
+
! aaa#{'<a>'}
|
51
|
+
! aaa#{'<a>'}
|
52
|
+
!!aa
|
53
|
+
HAML
|
54
|
+
aaa<a>
|
55
|
+
!aaa<a>
|
56
|
+
aaa<a>
|
57
|
+
aaa<a>
|
58
|
+
!!aa
|
59
|
+
HTML
|
60
|
+
end
|
61
|
+
|
46
62
|
describe 'string interpolation' do
|
47
63
|
specify { assert_render('#{}', "\n") }
|
48
64
|
specify { assert_render('1#{}', "1\n") }
|