hamlit 1.5.4 → 1.5.5

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.
@@ -0,0 +1,62 @@
1
+ # [sass\_spec.rb:3](https://github.com/k0kubun/hamlit/blob/master/spec/hamlit/filters/sass_spec.rb#L3)
2
+ ## Input
3
+ ```haml
4
+ :sass
5
+ .users_controller
6
+ .show_action
7
+ margin: 10px
8
+ padding: 20px
9
+
10
+ ```
11
+
12
+ ## Output
13
+ ### Haml, Hamlit
14
+ ```html
15
+ <style>
16
+ .users_controller .show_action {
17
+ margin: 10px;
18
+ padding: 20px; }
19
+ </style>
20
+
21
+ ```
22
+
23
+ ### Faml
24
+ ```html
25
+ <style>
26
+ .users_controller .show_action {
27
+ margin: 10px;
28
+ padding: 20px; }
29
+ </style>
30
+
31
+ ```
32
+
33
+
34
+ # [sass\_spec.rb:19](https://github.com/k0kubun/hamlit/blob/master/spec/hamlit/filters/sass_spec.rb#L19)
35
+ ## Input
36
+ ```haml
37
+ :sass
38
+ .users_controller
39
+ .show_action
40
+ content: "#{'<&>'}"
41
+
42
+ ```
43
+
44
+ ## Output
45
+ ### Haml, Hamlit
46
+ ```html
47
+ <style>
48
+ .users_controller .show_action {
49
+ content: "<&>"; }
50
+ </style>
51
+
52
+ ```
53
+
54
+ ### Faml
55
+ ```html
56
+ <style>
57
+ .users_controller .show_action {
58
+ content: "<&>"; }
59
+ </style>
60
+
61
+ ```
62
+
@@ -0,0 +1,68 @@
1
+ # [scss\_spec.rb:3](https://github.com/k0kubun/hamlit/blob/master/spec/hamlit/filters/scss_spec.rb#L3)
2
+ ## Input
3
+ ```haml
4
+ :scss
5
+ .users_controller {
6
+ .show_action {
7
+ margin: 10px;
8
+ padding: 20px;
9
+ }
10
+ }
11
+
12
+ ```
13
+
14
+ ## Output
15
+ ### Haml, Hamlit
16
+ ```html
17
+ <style>
18
+ .users_controller .show_action {
19
+ margin: 10px;
20
+ padding: 20px; }
21
+ </style>
22
+
23
+ ```
24
+
25
+ ### Faml
26
+ ```html
27
+ <style>
28
+ .users_controller .show_action {
29
+ margin: 10px;
30
+ padding: 20px; }
31
+
32
+ </style>
33
+
34
+ ```
35
+
36
+
37
+ # [scss\_spec.rb:21](https://github.com/k0kubun/hamlit/blob/master/spec/hamlit/filters/scss_spec.rb#L21)
38
+ ## Input
39
+ ```haml
40
+ :scss
41
+ .users_controller {
42
+ .show_action {
43
+ content: "#{'<&>'}";
44
+ }
45
+ }
46
+
47
+ ```
48
+
49
+ ## Output
50
+ ### Haml, Hamlit
51
+ ```html
52
+ <style>
53
+ .users_controller .show_action {
54
+ content: "<&>"; }
55
+ </style>
56
+
57
+ ```
58
+
59
+ ### Faml
60
+ ```html
61
+ <style>
62
+ .users_controller .show_action {
63
+ content: "<&>"; }
64
+
65
+ </style>
66
+
67
+ ```
68
+
data/hamlit.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.required_ruby_version = ">= 2.0.0"
21
21
 
22
22
  spec.add_dependency "escape_utils"
23
- spec.add_dependency "temple", "~> 0.7.3"
23
+ spec.add_dependency "temple", "~> 0.7.6"
24
24
  spec.add_dependency "thor"
25
25
  spec.add_dependency "tilt"
26
26
  spec.add_development_dependency "benchmark-ips"
data/lib/hamlit/engine.rb CHANGED
@@ -20,15 +20,6 @@ module Hamlit
20
20
  filter :ControlFlow
21
21
  filter :MultiFlattener
22
22
  filter :StaticMerger
23
- use :Generator, -> { create(options[:generator]) }
24
-
25
- private
26
-
27
- def create(klass)
28
- valid_options = options.to_hash.select do |key, value|
29
- klass.options.valid_key?(key)
30
- end
31
- klass.new(valid_options)
32
- end
23
+ use :Generator, -> { options[:generator] }
33
24
  end
34
25
  end
data/lib/hamlit/parser.rb CHANGED
@@ -76,12 +76,11 @@ module Hamlit
76
76
  return ast if ast
77
77
  end
78
78
 
79
- parse_inner_line(scanner, inline: inline)
79
+ parse_inner_line(scanner)
80
80
  end
81
81
 
82
82
  # Parse a line and return ast if it is acceptable outside an inline tag
83
83
  def parse_outer_line(scanner)
84
- return parse_text(scanner) if scanner.scan(/\\/)
85
84
  return parse_text(scanner) if scanner.match?(/\#{/)
86
85
  return parse_text(scanner) if scanner.match?(/[.#]($|[^a-zA-Z0-9_-])/)
87
86
  return parse_doctype(scanner) if scanner.match?(/!!!/)
@@ -89,6 +88,8 @@ module Hamlit
89
88
  case scanner.peek(1)
90
89
  when '%', '.', '#'
91
90
  parse_tag(scanner)
91
+ when '\\'
92
+ parse_text(scanner, scan: /\\/)
92
93
  when '/'
93
94
  parse_comment(scanner)
94
95
  when ':'
@@ -97,18 +98,22 @@ module Hamlit
97
98
  end
98
99
 
99
100
  # Parse a line and return ast which is acceptable inside an inline tag
100
- def parse_inner_line(scanner, inline: false)
101
+ def parse_inner_line(scanner)
101
102
  return parse_text(scanner, lstrip: true) if scanner.scan(/==/)
102
- return parse_text(scanner, lstrip: true, escape: false) if scanner.scan(/!( |==)/)
103
- return parse_script(scanner, force_escape: true) if scanner.match?(/&=/)
103
+ return parse_text(scanner, lstrip: true, escape: false) if scanner.scan(/!==/)
104
+ return parse_text(scanner, lstrip: true, escape: true) if scanner.scan(/&==/)
104
105
  return parse_script(scanner, disable_escape: true) if scanner.match?(/!=/)
105
- return parse_text(scanner, lstrip: true, escape: false) if scanner.scan(/!/)
106
+ return parse_script(scanner, force_escape: true) if scanner.match?(/&=/)
106
107
 
107
108
  case scanner.peek(1)
108
109
  when '=', '~'
109
110
  parse_script(scanner)
110
111
  when '-'
111
112
  parse_silent_script(scanner)
113
+ when '!'
114
+ parse_text(scanner, lstrip: true, escape: false, scan: /!/)
115
+ when '&'
116
+ parse_text(scanner, lstrip: true, escape: true, scan: /&/)
112
117
  else
113
118
  parse_text(scanner)
114
119
  end
@@ -51,7 +51,7 @@ module Hamlit
51
51
  lines = lines.map do |line|
52
52
  line.strip.gsub(/ *\|\Z/, '')
53
53
  end
54
- lines.join(' ')
54
+ lines.map { |l| "#{l} "}.join
55
55
  end
56
56
  end
57
57
  end
@@ -5,7 +5,8 @@ module Hamlit
5
5
  module Text
6
6
  include Concerns::Error
7
7
 
8
- def parse_text(scanner, lstrip: false, escape: true)
8
+ def parse_text(scanner, lstrip: false, escape: true, scan: nil)
9
+ scanner.scan(scan) if scan
9
10
  text = (scanner.scan(/.+/) || '')
10
11
  text = text.lstrip if lstrip
11
12
  [:haml, :text, text, escape]
@@ -1,3 +1,3 @@
1
1
  module Hamlit
2
- VERSION = "1.5.4"
2
+ VERSION = "1.5.5"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  describe Hamlit::Engine do
2
2
  describe 'tab indent' do
3
- it 'accepts tab indentation' do
3
+ it 'accepts tab indentation', skipdoc: true do
4
4
  assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
5
5
  %p
6
6
  \t%a
@@ -1,11 +1,11 @@
1
1
  describe Hamlit::Engine do
2
2
  describe 'multiline' do
3
3
  it 'joins multi-lines ending with pipe' do
4
- assert_render(<<-HAML, <<-HTML, compatible_only: [])
4
+ assert_render(<<-HAML, <<-HTML)
5
5
  a |
6
6
  b |
7
7
  HAML
8
- a b
8
+ a b
9
9
  HTML
10
10
  end
11
11
 
@@ -17,7 +17,7 @@ describe Hamlit::Engine do
17
17
  end
18
18
 
19
19
  describe 'html escape' do
20
- it 'escapes attribute values on static attributes' do
20
+ it 'escapes attribute values on static attributes', skipdoc: true do
21
21
  assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
22
22
  %a(title="'")
23
23
  %a(title = "'\"")
@@ -29,7 +29,7 @@ describe Hamlit::Engine do
29
29
  HTML
30
30
  end
31
31
 
32
- it 'escapes attribute values on dynamic attributes' do
32
+ it 'escapes attribute values on dynamic attributes', skipdoc: true do
33
33
  assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
34
34
  - title = "'\""
35
35
  - href = '/search?foo=bar&hoge=<fuga>'
@@ -121,7 +121,7 @@ describe Hamlit::Engine do
121
121
  HTML
122
122
  end
123
123
 
124
- it 'joins attribute class and element class' do
124
+ it 'joins attribute class and element class', skipdoc: true do
125
125
  assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
126
126
  .foo{ class: ['bar'] }
127
127
  .foo{ class: ['bar', nil] }
@@ -198,22 +198,32 @@ describe Hamlit::Engine do
198
198
  HTML
199
199
  end
200
200
 
201
- # NOTE: This incompatibility will not be fixed for performance.
202
201
  it 'does not delete non-boolean attributes, for optimization' do
203
- assert_render(<<-'HAML', <<-HTML, compatible_only: []) # wontfix
202
+ assert_render(<<-'HAML', <<-HTML, compatible_only: [])
203
+ / wontfix: Non-boolean attributes are not escaped for optimization.
204
204
  - val = false
205
205
  %a{ href: val }
206
206
  - val = nil
207
207
  %a{ href: val }
208
+
209
+ / Boolean attributes are escaped correctly.
210
+ - val = false
211
+ %a{ disabled: val }
212
+ - val = nil
213
+ %a{ disabled: val }
208
214
  HAML
215
+ <!-- wontfix: Non-boolean attributes are not escaped for optimization. -->
209
216
  <a href='false'></a>
210
217
  <a href=''></a>
218
+ <!-- Boolean attributes are escaped correctly. -->
219
+ <a></a>
220
+ <a></a>
211
221
  HTML
212
222
  end
213
223
  end
214
224
 
215
225
  describe 'html escape' do
216
- it 'escapes attribute values on static attributes' do
226
+ it 'escapes attribute values on static attributes', skipdoc: true do
217
227
  assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
218
228
  %a{title: "'"}
219
229
  %a{title: "'\""}
@@ -225,7 +235,7 @@ describe Hamlit::Engine do
225
235
  HTML
226
236
  end
227
237
 
228
- it 'escapes attribute values on dynamic attributes' do
238
+ it 'escapes attribute values on dynamic attributes', skipdoc: true do
229
239
  assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
230
240
  - title = "'\""
231
241
  - href = '/search?foo=bar&hoge=<fuga>'
@@ -237,7 +247,7 @@ describe Hamlit::Engine do
237
247
  HTML
238
248
  end
239
249
 
240
- it 'escapes attribute values on hash attributes' do
250
+ it 'escapes attribute values on hash attributes', skipdoc: true do
241
251
  assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
242
252
  - title = { title: "'\"" }
243
253
  - href = { href: '/search?foo=bar&hoge=<fuga>' }
@@ -260,7 +270,7 @@ describe Hamlit::Engine do
260
270
  HTML
261
271
  end
262
272
 
263
- it 'renders true attributes' do
273
+ it 'renders true attributes', skipdoc: true do
264
274
  assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
265
275
  %span{ data: { disable: true } } bar
266
276
  HAML
@@ -76,7 +76,7 @@ describe Hamlit::Engine do
76
76
  HTML
77
77
  end
78
78
 
79
- it 'renders empty elsif statement' do
79
+ it 'renders empty elsif statement', skipdoc: true do
80
80
  assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
81
81
  %span
82
82
  - if false
@@ -87,7 +87,7 @@ describe Hamlit::Engine do
87
87
  HTML
88
88
  end
89
89
 
90
- it 'renders empty else statement' do
90
+ it 'renders empty else statement', skipdoc: true do
91
91
  assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
92
92
  %span
93
93
  - if false
@@ -99,7 +99,7 @@ describe Hamlit::Engine do
99
99
  HTML
100
100
  end
101
101
 
102
- it 'renders empty when statement' do
102
+ it 'renders empty when statement', skipdoc: true do
103
103
  assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
104
104
  %span
105
105
  - case
@@ -187,7 +187,7 @@ describe Hamlit::Engine do
187
187
  HTML
188
188
  end
189
189
 
190
- it 'joins a next line if a current line ends with ","' do
190
+ it 'joins a next line if a current line ends with ","', skipdoc: true do
191
191
  assert_render("- foo = [', \n ']\n= foo", <<-HTML, compatible_only: :haml)
192
192
  [&quot;, &quot;]
193
193
  HTML
@@ -186,68 +186,6 @@ describe Hamlit::Engine do
186
186
  HTML
187
187
  end
188
188
 
189
- describe 'inline operator' do
190
- it 'does not accept backslash operator' do
191
- assert_render(<<-'HAML', <<-'HTML')
192
- %span\ foo
193
- HAML
194
- <span>\ foo</span>
195
- HTML
196
- end
197
-
198
- it 'accepts != operator' do
199
- assert_render(<<-'HAML', <<-'HTML')
200
- %span!= '<nyaa>'
201
- HAML
202
- <span><nyaa></span>
203
- HTML
204
- end
205
-
206
- it 'accepts !== operator' do
207
- assert_render(<<-'HAML', <<-'HTML')
208
- %span!==#{'<nyaa>'}
209
- %span!== #{'<nyaa>'}
210
- !==#{'<nyaa>'}
211
- !== #{'<nyaa>'}
212
- HAML
213
- <span><nyaa></span>
214
- <span><nyaa></span>
215
- <nyaa>
216
- <nyaa>
217
- HTML
218
- end
219
-
220
- it 'accepts &= operator' do
221
- assert_render(<<-'HAML', <<-'HTML', escape_html: false)
222
- %span&= '<nyaa>'
223
- HAML
224
- <span>&lt;nyaa&gt;</span>
225
- HTML
226
- end
227
-
228
- it 'accepts ! operator' do
229
- assert_render(<<-'HAML', <<-'HTML', compatible_only: :faml)
230
- %span!#{'<nyaa>'}
231
- %span! #{'<nyaa>'}
232
- !#{'<nyaa>'}
233
- ! #{'<nyaa>'}
234
- HAML
235
- <span><nyaa></span>
236
- <span><nyaa></span>
237
- <nyaa>
238
- <nyaa>
239
- HTML
240
- end
241
-
242
- it 'accepts ~ operator' do
243
- assert_render(<<-HAML, <<-HTML, escape_html: false)
244
- %span~ 1
245
- HAML
246
- <span>1</span>
247
- HTML
248
- end
249
- end
250
-
251
189
  describe 'whitespace removal' do
252
190
  it 'removes outer whitespace by >' do
253
191
  assert_render(<<-HAML, <<-HTML)
@@ -71,20 +71,102 @@ describe Hamlit::Engine do
71
71
  expect(render_string('\ a')).to eq(" a\n")
72
72
  end
73
73
 
74
- it 'renders ! operator' do
75
- assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
76
- aaa#{'<a>'}
77
- !aaa#{'<a>'}
78
- ! aaa#{'<a>'}
79
- ! aaa#{'<a>'}
80
- !!aa
81
- HAML
82
- aaa&lt;a&gt;
83
- aaa<a>
84
- aaa<a>
85
- aaa<a>
86
- !aa
87
- HTML
74
+ describe 'inline operator' do
75
+ it 'renders ! operator' do
76
+ assert_render(<<-'HAML', <<-'HTML')
77
+ %span!#{'<nyaa>'}
78
+ %span! #{'<nyaa>'}
79
+ ! #{'<nyaa>'}
80
+ HAML
81
+ <span><nyaa></span>
82
+ <span><nyaa></span>
83
+ <nyaa>
84
+ HTML
85
+ end
86
+
87
+ it 'renders & operator' do
88
+ assert_render(<<-'HAML', <<-'HTML')
89
+ %span& #{'<nyaa>'}
90
+ %span&#{'<nyaa>'}
91
+ & #{'<nyaa>'}
92
+ HAML
93
+ <span>&lt;nyaa&gt;</span>
94
+ <span>&lt;nyaa&gt;</span>
95
+ &lt;nyaa&gt;
96
+ HTML
97
+ end
98
+
99
+ it 'renders !, & operator right before a non-space character' do
100
+ assert_render(<<-'HAML', <<-'HTML', compatible_only: :faml)
101
+ &nbsp;
102
+ \&nbsp;
103
+ !hello
104
+ \!hello
105
+ HAML
106
+ nbsp;
107
+ &nbsp;
108
+ hello
109
+ !hello
110
+ HTML
111
+ end
112
+
113
+ it 'does not accept backslash operator' do
114
+ assert_render(<<-'HAML', <<-'HTML')
115
+ %span\ foo
116
+ HAML
117
+ <span>\ foo</span>
118
+ HTML
119
+ end
120
+
121
+ it 'renders != operator' do
122
+ assert_render(<<-'HAML', <<-'HTML')
123
+ %span!= '<nyaa>'
124
+ HAML
125
+ <span><nyaa></span>
126
+ HTML
127
+ end
128
+
129
+ it 'renders !== operator' do
130
+ assert_render(<<-'HAML', <<-'HTML')
131
+ %span!==#{'<nyaa>'}
132
+ %span!== #{'<nyaa>'}
133
+ !==#{'<nyaa>'}
134
+ !== #{'<nyaa>'}
135
+ HAML
136
+ <span><nyaa></span>
137
+ <span><nyaa></span>
138
+ <nyaa>
139
+ <nyaa>
140
+ HTML
141
+ end
142
+
143
+ it 'renders &= operator' do
144
+ assert_render(<<-'HAML', <<-'HTML', escape_html: false)
145
+ %span&= '<nyaa>'
146
+ HAML
147
+ <span>&lt;nyaa&gt;</span>
148
+ HTML
149
+ end
150
+
151
+ it 'renders &== operator' do
152
+ assert_render(<<-'HAML', <<-'HTML')
153
+ &===
154
+ &== =
155
+ &== #{'<p>'}
156
+ HAML
157
+ =
158
+ =
159
+ &lt;p&gt;
160
+ HTML
161
+ end
162
+
163
+ it 'renders ~ operator' do
164
+ assert_render(<<-HAML, <<-HTML, escape_html: false)
165
+ %span~ 1
166
+ HAML
167
+ <span>1</span>
168
+ HTML
169
+ end
88
170
  end
89
171
 
90
172
  describe 'string interpolation' do
@@ -100,7 +182,6 @@ describe Hamlit::Engine do
100
182
  specify { assert_render('あ#{1}', "あ1\n") }
101
183
  specify { assert_render('あ#{"い"}う', "あいう\n") }
102
184
  specify { assert_render('a#{"<b>"}c', "a&lt;b&gt;c\n") }
103
- specify { assert_render(":plain\n あ\n \#{'い'}", "あ\nい\n\n", compatible_only: :haml) }
104
185
  end
105
186
  end
106
187
  end
@@ -0,0 +1,15 @@
1
+ describe Hamlit::Filters::Plain do
2
+ describe '#compile' do
3
+ it 'renders plain filter' do
4
+ assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
5
+ :plain
6
+
7
+ #{'い'}
8
+ HAML
9
+
10
+
11
+
12
+ HTML
13
+ end
14
+ end
15
+ end