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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9be0ee09a4585d8c871901afad043298e8eae2bc
4
- data.tar.gz: f1a8f5bbbdaa2994e209a959b4ba2a1162c76317
3
+ metadata.gz: 48c63183e137f6ac95b74b18913665a72dd93a10
4
+ data.tar.gz: aa406f516907e362b2f1746636ed9c06b5c81d92
5
5
  SHA512:
6
- metadata.gz: e2e3d51b40f28322634436597711f45d3dade9c5ad252302fb593bda6996bf27c8ab2b1b644054971606e5c79627a4df4768d4745987272597dec0e814b6b77b
7
- data.tar.gz: a3f96912395ad6b3ec047ae332e202b72c385fc28af8dcd7fac35488ba66175ca453ae2286a98b22afaf98dfa4d3132c3aedd22a0a8e73e34ee97e8aee26d835
6
+ metadata.gz: dd0f4d8ca9147def6ea19af310e42ef000626da8b08346644d47ffd38d30b894d6150837ed2a065e141a1b81db6525f6fc184a5dc542cf3653858a96914e5d9d
7
+ data.tar.gz: fdc76ab6d2b810b8c8b0b7c284bb36fefadbcba42cedd9fc1371bc26b96133342f157945827a7ae821213afdf31c28671954be054f0db8b4bbba81a987377104
@@ -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 escape_html option
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
- if str.ascii_only?
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
- [:multi, [:static, pre], escape_html([:dynamic, body]), on_haml_text(post)]
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)
@@ -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 '=', '~'
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Hamlit
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -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&lt;a&gt;
55
+ !aaa&lt;a&gt;
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") }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun