hamlit 1.5.3 → 1.5.4
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/hamlit/compilers/strip.rb +8 -20
- data/lib/hamlit/{parsers → concerns}/whitespace.rb +26 -16
- data/lib/hamlit/parser.rb +2 -4
- data/lib/hamlit/parsers/tag.rb +2 -0
- data/lib/hamlit/version.rb +1 -1
- data/release +6 -0
- data/spec/hamlit/engine/doctype_spec.rb +1 -1
- data/spec/hamlit/engine/indent_spec.rb +1 -1
- data/spec/hamlit/engine/multiline_spec.rb +1 -1
- data/spec/hamlit/engine/new_attribute_spec.rb +2 -2
- data/spec/hamlit/engine/old_attributes_spec.rb +9 -8
- data/spec/hamlit/engine/script_spec.rb +4 -4
- data/spec/hamlit/engine/silent_script_spec.rb +4 -4
- data/spec/hamlit/engine/tag_spec.rb +25 -2
- data/spec/hamlit/engine/text_spec.rb +6 -6
- data/spec/hamlit/filters/coffee_spec.rb +3 -3
- data/spec/hamlit/filters/erb_spec.rb +1 -1
- data/spec/hamlit/filters/javascript_spec.rb +2 -2
- data/spec/hamlit/filters/less_spec.rb +2 -2
- data/spec/hamlit/filters/markdown_spec.rb +1 -1
- data/spec/hamlit/filters/sass_spec.rb +2 -2
- data/spec/hamlit/filters/scss_spec.rb +2 -2
- data/spec/spec_helper.rb +69 -2
- data/test +25 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48cbd681aed1b48f72d46f0256620e5d6d358445
|
4
|
+
data.tar.gz: 804f4570f39a8d92091157197dd26791c908dfd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79e74c4d9128dda022f1275ef9adbd1f0f90733b0f0223e836a8985dac426a29620563602d3ccda345296b1ee251da0c92cd0c93c96d6af091eb6b64a844a0b8
|
7
|
+
data.tar.gz: 8567ec9a0f5984c122cfa99d14c8afbf7b55cf29be98f5439d50fd92f169d4200ee2cb3c398802f7c7a21c919c06dce822d3586e1dd7d8135979bcef539796bf
|
data/CHANGELOG.md
CHANGED
@@ -1,30 +1,18 @@
|
|
1
|
+
require 'hamlit/concerns/whitespace'
|
2
|
+
|
1
3
|
# This module is created to compile [:haml, :strip],
|
2
4
|
# which is sexp for whitespace inner removal.module Hamlit
|
3
5
|
module Hamlit
|
4
6
|
module Compilers
|
5
7
|
module Strip
|
6
|
-
|
7
|
-
stripped = strip_newline(exps)
|
8
|
-
on_multi(*stripped)
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
8
|
+
include Concerns::Whitespace
|
12
9
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
content.delete_at(indexes.last)
|
18
|
-
content.delete_at(indexes.first)
|
19
|
-
content
|
20
|
-
end
|
10
|
+
def on_haml_strip(*exps)
|
11
|
+
exps = exps.dup
|
12
|
+
remove_first_space!(exps)
|
13
|
+
remove_last_space!(exps)
|
21
14
|
|
22
|
-
|
23
|
-
indexes = []
|
24
|
-
exps.each_with_index do |exp, index|
|
25
|
-
indexes << index if exp == [:static, "\n"]
|
26
|
-
end
|
27
|
-
indexes
|
15
|
+
on_multi(*exps)
|
28
16
|
end
|
29
17
|
end
|
30
18
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'set'
|
2
2
|
|
3
|
-
# Hamlit::
|
3
|
+
# Hamlit::Concerns::Whitespace cares about "whitespace removal",
|
4
4
|
# which is achieved by '<' or '>' after html tag.
|
5
|
+
# NOTE: Whitespace means [:static, "\n"] because it is rendered
|
6
|
+
# as whitespace on browsers.
|
5
7
|
module Hamlit
|
6
|
-
module
|
8
|
+
module Concerns
|
7
9
|
module Whitespace
|
8
10
|
def parse_whitespace_removal(scanner)
|
9
11
|
if scanner.match?(/</)
|
@@ -16,20 +18,11 @@ module Hamlit
|
|
16
18
|
inner_removal
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
remove_first_outer_space!(exps)
|
22
|
-
ensure
|
23
|
-
exps.reverse!
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def remove_first_outer_space!(exps)
|
21
|
+
# `<` removes spaces inside script or silent script recursively.
|
22
|
+
def remove_first_space!(exps)
|
29
23
|
deleted = false
|
30
|
-
exps.delete_if do |exp|
|
31
|
-
break if deleted
|
32
24
|
|
25
|
+
exps.delete_if do |exp|
|
33
26
|
name, *args = exp
|
34
27
|
case name
|
35
28
|
when :static
|
@@ -41,13 +34,30 @@ module Hamlit
|
|
41
34
|
when :newline
|
42
35
|
next false
|
43
36
|
when :haml
|
44
|
-
|
37
|
+
# recursive call for script
|
38
|
+
remove_last_space!(exp) if args.first == :script
|
39
|
+
when :multi
|
40
|
+
break if exp == :multi
|
41
|
+
# to flatten multi
|
42
|
+
remove_last_space!(exp)
|
45
43
|
end
|
46
44
|
break
|
47
45
|
end
|
48
|
-
|
46
|
+
|
47
|
+
# recursive call for silent script
|
48
|
+
remove_last_space!(exps) if deleted
|
49
|
+
end
|
50
|
+
|
51
|
+
def remove_last_space!(exps)
|
52
|
+
exps.reverse!
|
53
|
+
remove_first_space!(exps)
|
54
|
+
ensure
|
55
|
+
exps.reverse!
|
56
|
+
exps
|
49
57
|
end
|
50
58
|
|
59
|
+
private
|
60
|
+
|
51
61
|
def reset_outer_removal
|
52
62
|
@outer_removal = Set.new
|
53
63
|
@tag_indent = 0
|
data/lib/hamlit/parser.rb
CHANGED
@@ -8,7 +8,6 @@ require 'hamlit/parsers/multiline'
|
|
8
8
|
require 'hamlit/parsers/script'
|
9
9
|
require 'hamlit/parsers/tag'
|
10
10
|
require 'hamlit/parsers/text'
|
11
|
-
require 'hamlit/parsers/whitespace'
|
12
11
|
|
13
12
|
module Hamlit
|
14
13
|
class Parser < Temple::Parser
|
@@ -20,7 +19,6 @@ module Hamlit
|
|
20
19
|
include Parsers::Script
|
21
20
|
include Parsers::Tag
|
22
21
|
include Parsers::Text
|
23
|
-
include Parsers::Whitespace
|
24
22
|
|
25
23
|
SKIP_NEWLINE_EXPS = %i[newline code multi].freeze
|
26
24
|
SKIP_NEWLINE_FILTERS = %w[ruby markdown erb].freeze
|
@@ -56,7 +54,7 @@ module Hamlit
|
|
56
54
|
|
57
55
|
@current_lineno += 1
|
58
56
|
node = parse_line(current_line)
|
59
|
-
|
57
|
+
remove_last_space!(ast) if outer_remove?
|
60
58
|
|
61
59
|
ast << [:newline] if @current_indent > 0
|
62
60
|
ast << node
|
@@ -104,7 +102,7 @@ module Hamlit
|
|
104
102
|
return parse_text(scanner, lstrip: true, escape: false) if scanner.scan(/!( |==)/)
|
105
103
|
return parse_script(scanner, force_escape: true) if scanner.match?(/&=/)
|
106
104
|
return parse_script(scanner, disable_escape: true) if scanner.match?(/!=/)
|
107
|
-
return parse_text(scanner, lstrip: true, escape: false) if
|
105
|
+
return parse_text(scanner, lstrip: true, escape: false) if scanner.scan(/!/)
|
108
106
|
|
109
107
|
case scanner.peek(1)
|
110
108
|
when '=', '~'
|
data/lib/hamlit/parsers/tag.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'hamlit/concerns/error'
|
2
2
|
require 'hamlit/concerns/indentable'
|
3
|
+
require 'hamlit/concerns/whitespace'
|
3
4
|
require 'hamlit/helpers'
|
4
5
|
|
5
6
|
module Hamlit
|
@@ -7,6 +8,7 @@ module Hamlit
|
|
7
8
|
module Tag
|
8
9
|
include Concerns::Error
|
9
10
|
include Concerns::Indentable
|
11
|
+
include Concerns::Whitespace
|
10
12
|
|
11
13
|
TAG_ID_CLASS_REGEXP = /[a-zA-Z0-9_-]+/
|
12
14
|
TAG_REGEXP = /[a-zA-Z0-9\-_:]+/
|
data/lib/hamlit/version.rb
CHANGED
data/release
ADDED
@@ -18,7 +18,7 @@ describe Hamlit::Engine do
|
|
18
18
|
|
19
19
|
describe 'html escape' do
|
20
20
|
it 'escapes attribute values on static attributes' do
|
21
|
-
assert_render(<<-'HAML', <<-HTML)
|
21
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
22
22
|
%a(title="'")
|
23
23
|
%a(title = "'\"")
|
24
24
|
%a(href='/search?foo=bar&hoge=<fuga>')
|
@@ -30,7 +30,7 @@ describe Hamlit::Engine do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'escapes attribute values on dynamic attributes' do
|
33
|
-
assert_render(<<-'HAML', <<-HTML)
|
33
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
34
34
|
- title = "'\""
|
35
35
|
- href = '/search?foo=bar&hoge=<fuga>'
|
36
36
|
%a(title=title)
|
@@ -41,7 +41,7 @@ describe Hamlit::Engine do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'accepts even illegal input for haml' do
|
44
|
-
assert_render(<<-'HAML', <<-HTML)
|
44
|
+
assert_render(<<-'HAML', <<-HTML, error_with: [:haml, :faml])
|
45
45
|
%span{ class: '}}}', id: '{}}' } }{
|
46
46
|
HAML
|
47
47
|
<span class='}}}' id='{}}'>}{</span>
|
@@ -122,7 +122,7 @@ describe Hamlit::Engine do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'joins attribute class and element class' do
|
125
|
-
assert_render(<<-HAML, <<-HTML)
|
125
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
|
126
126
|
.foo{ class: ['bar'] }
|
127
127
|
.foo{ class: ['bar', nil] }
|
128
128
|
.foo{ class: ['bar', 'baz'] }
|
@@ -198,8 +198,9 @@ describe Hamlit::Engine do
|
|
198
198
|
HTML
|
199
199
|
end
|
200
200
|
|
201
|
-
|
202
|
-
|
201
|
+
# NOTE: This incompatibility will not be fixed for performance.
|
202
|
+
it 'does not delete non-boolean attributes, for optimization' do
|
203
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: []) # wontfix
|
203
204
|
- val = false
|
204
205
|
%a{ href: val }
|
205
206
|
- val = nil
|
@@ -213,7 +214,7 @@ describe Hamlit::Engine do
|
|
213
214
|
|
214
215
|
describe 'html escape' do
|
215
216
|
it 'escapes attribute values on static attributes' do
|
216
|
-
assert_render(<<-'HAML', <<-HTML)
|
217
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
217
218
|
%a{title: "'"}
|
218
219
|
%a{title: "'\""}
|
219
220
|
%a{href: '/search?foo=bar&hoge=<fuga>'}
|
@@ -225,7 +226,7 @@ describe Hamlit::Engine do
|
|
225
226
|
end
|
226
227
|
|
227
228
|
it 'escapes attribute values on dynamic attributes' do
|
228
|
-
assert_render(<<-'HAML', <<-HTML)
|
229
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
229
230
|
- title = "'\""
|
230
231
|
- href = '/search?foo=bar&hoge=<fuga>'
|
231
232
|
%a{title: title}
|
@@ -237,7 +238,7 @@ describe Hamlit::Engine do
|
|
237
238
|
end
|
238
239
|
|
239
240
|
it 'escapes attribute values on hash attributes' do
|
240
|
-
assert_render(<<-'HAML', <<-HTML)
|
241
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
241
242
|
- title = { title: "'\"" }
|
242
243
|
- href = { href: '/search?foo=bar&hoge=<fuga>' }
|
243
244
|
%a{ title }
|
@@ -260,7 +261,7 @@ describe Hamlit::Engine do
|
|
260
261
|
end
|
261
262
|
|
262
263
|
it 'renders true attributes' do
|
263
|
-
assert_render(<<-'HAML', <<-HTML)
|
264
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
|
264
265
|
%span{ data: { disable: true } } bar
|
265
266
|
HAML
|
266
267
|
<span data-disable>bar</span>
|
@@ -39,7 +39,7 @@ describe Hamlit::Engine do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'renders block script' do
|
42
|
-
assert_render(<<-HAML, <<-HTML)
|
42
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: [])
|
43
43
|
= 3.times do |i|
|
44
44
|
= i
|
45
45
|
4
|
@@ -53,7 +53,7 @@ describe Hamlit::Engine do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'renders tag internal block script' do
|
56
|
-
assert_render(<<-HAML, <<-HTML)
|
56
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: [])
|
57
57
|
%span
|
58
58
|
= 1.times do |i|
|
59
59
|
= i
|
@@ -85,7 +85,7 @@ describe Hamlit::Engine do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'renders !=' do
|
88
|
-
assert_render(<<-HAML, <<-HTML, escape_html: true)
|
88
|
+
assert_render(<<-HAML, <<-HTML, escape_html: true, compatible_only: [])
|
89
89
|
!= '<"&>'
|
90
90
|
!= '<"&>'.tap do |str|
|
91
91
|
-# no operation
|
@@ -96,7 +96,7 @@ describe Hamlit::Engine do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'renders &=' do
|
99
|
-
assert_render(<<-HAML, <<-HTML, escape_html: false)
|
99
|
+
assert_render(<<-HAML, <<-HTML, escape_html: false, compatible_only: [])
|
100
100
|
&= '<"&>'
|
101
101
|
&= '<"&>'.tap do |str|
|
102
102
|
-# no operation
|
@@ -77,7 +77,7 @@ describe Hamlit::Engine do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'renders empty elsif statement' do
|
80
|
-
assert_render(<<-'HAML', <<-HTML)
|
80
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
81
81
|
%span
|
82
82
|
- if false
|
83
83
|
- elsif false
|
@@ -88,7 +88,7 @@ describe Hamlit::Engine do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'renders empty else statement' do
|
91
|
-
assert_render(<<-'HAML', <<-HTML)
|
91
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
92
92
|
%span
|
93
93
|
- if false
|
94
94
|
ng
|
@@ -100,7 +100,7 @@ describe Hamlit::Engine do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'renders empty when statement' do
|
103
|
-
assert_render(<<-'HAML', <<-HTML)
|
103
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
104
104
|
%span
|
105
105
|
- case
|
106
106
|
- when false
|
@@ -188,7 +188,7 @@ describe Hamlit::Engine do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'joins a next line if a current line ends with ","' do
|
191
|
-
assert_render("- foo = [', \n ']\n= foo", <<-HTML)
|
191
|
+
assert_render("- foo = [', \n ']\n= foo", <<-HTML, compatible_only: :haml)
|
192
192
|
[", "]
|
193
193
|
HTML
|
194
194
|
end
|
@@ -226,7 +226,7 @@ describe Hamlit::Engine do
|
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'accepts ! operator' do
|
229
|
-
assert_render(<<-'HAML', <<-'HTML')
|
229
|
+
assert_render(<<-'HAML', <<-'HTML', compatible_only: :faml)
|
230
230
|
%span!#{'<nyaa>'}
|
231
231
|
%span! #{'<nyaa>'}
|
232
232
|
!#{'<nyaa>'}
|
@@ -234,7 +234,7 @@ describe Hamlit::Engine do
|
|
234
234
|
HAML
|
235
235
|
<span><nyaa></span>
|
236
236
|
<span><nyaa></span>
|
237
|
-
|
237
|
+
<nyaa>
|
238
238
|
<nyaa>
|
239
239
|
HTML
|
240
240
|
end
|
@@ -297,6 +297,29 @@ describe Hamlit::Engine do
|
|
297
297
|
<span>foofoo2<span>bar</span></span>
|
298
298
|
HTML
|
299
299
|
end
|
300
|
+
|
301
|
+
it 'removes whitespace inside script inside silent script' do
|
302
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: [:haml, :faml])
|
303
|
+
.bar<
|
304
|
+
- 3.times do
|
305
|
+
= 'foo'
|
306
|
+
HAML
|
307
|
+
<div class='bar'>foofoofoo</div>
|
308
|
+
HTML
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'removes whitespace inside script recursively' do
|
312
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: [:haml, :faml])
|
313
|
+
.foo<
|
314
|
+
- 1.times do
|
315
|
+
= 2.times do
|
316
|
+
- 2.times do
|
317
|
+
= 1.times do
|
318
|
+
= 'bar'
|
319
|
+
HAML
|
320
|
+
<div class='foo'>bar1bar1bar1bar12</div>
|
321
|
+
HTML
|
322
|
+
end
|
300
323
|
end
|
301
324
|
end
|
302
325
|
end
|
@@ -13,7 +13,7 @@ describe Hamlit::Engine do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'renders . or # which is not continued by tag name' do
|
16
|
-
assert_render(<<-HAML, <<-HTML)
|
16
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: [], error_with: :haml)
|
17
17
|
.
|
18
18
|
.*
|
19
19
|
#
|
@@ -72,7 +72,7 @@ describe Hamlit::Engine do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'renders ! operator' do
|
75
|
-
assert_render(<<-'HAML', <<-HTML)
|
75
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
76
76
|
aaa#{'<a>'}
|
77
77
|
!aaa#{'<a>'}
|
78
78
|
! aaa#{'<a>'}
|
@@ -80,10 +80,10 @@ describe Hamlit::Engine do
|
|
80
80
|
!!aa
|
81
81
|
HAML
|
82
82
|
aaa<a>
|
83
|
-
!aaa<a>
|
84
83
|
aaa<a>
|
85
84
|
aaa<a>
|
86
|
-
|
85
|
+
aaa<a>
|
86
|
+
!aa
|
87
87
|
HTML
|
88
88
|
end
|
89
89
|
|
@@ -91,7 +91,7 @@ describe Hamlit::Engine do
|
|
91
91
|
specify { assert_render('#{}', "\n") }
|
92
92
|
specify { assert_render('1#{}', "1\n") }
|
93
93
|
specify { assert_render('1#{2}', "12\n") }
|
94
|
-
specify { assert_render('1#{2', "1\#{2\n") }
|
94
|
+
specify { assert_render('1#{2', "1\#{2\n", error_with: [:haml, :faml]) }
|
95
95
|
specify { assert_render('}#{1}', "}1\n") }
|
96
96
|
specify { assert_render('#{1}2', "12\n") }
|
97
97
|
specify { assert_render('1#{ "2#{3}4" }5', "12345\n") }
|
@@ -100,7 +100,7 @@ describe Hamlit::Engine do
|
|
100
100
|
specify { assert_render('あ#{1}', "あ1\n") }
|
101
101
|
specify { assert_render('あ#{"い"}う', "あいう\n") }
|
102
102
|
specify { assert_render('a#{"<b>"}c', "a<b>c\n") }
|
103
|
-
specify { assert_render(":plain\n あ\n \#{'い'}", "あ\nい\n\n") }
|
103
|
+
specify { assert_render(":plain\n あ\n \#{'い'}", "あ\nい\n\n", compatible_only: :haml) }
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe Hamlit::Filters::Coffee do
|
2
2
|
describe '#compile' do
|
3
3
|
it 'renders coffee filter' do
|
4
|
-
assert_render(<<-HAML, <<-HTML)
|
4
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
|
5
5
|
:coffee
|
6
6
|
foo = ->
|
7
7
|
alert('hello')
|
@@ -20,7 +20,7 @@ describe Hamlit::Filters::Coffee do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'renders coffeescript filter' do
|
23
|
-
assert_render(<<-HAML, <<-HTML)
|
23
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
|
24
24
|
:coffee
|
25
25
|
foo = ->
|
26
26
|
alert('hello')
|
@@ -39,7 +39,7 @@ describe Hamlit::Filters::Coffee do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'renders coffeescript filter' do
|
42
|
-
assert_render(<<-'HAML', <<-HTML)
|
42
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
|
43
43
|
:coffee
|
44
44
|
foo = ->
|
45
45
|
alert("#{'<&>'}")
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe Hamlit::Filters::Javascript do
|
2
2
|
describe '#compile' do
|
3
3
|
it 'just renders script tag for empty filter' do
|
4
|
-
assert_render(<<-HAML, <<-HTML)
|
4
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: [])
|
5
5
|
before
|
6
6
|
:javascript
|
7
7
|
after
|
@@ -30,7 +30,7 @@ describe Hamlit::Filters::Javascript do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'accepts illegal indentation' do
|
33
|
-
assert_render(<<-HAML, <<-HTML)
|
33
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: :faml)
|
34
34
|
:javascript
|
35
35
|
if {
|
36
36
|
alert('hello');
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe Hamlit::Filters::Less do
|
2
2
|
describe '#compile' do
|
3
3
|
it 'renders less filter' do
|
4
|
-
assert_render(<<-HAML, <<-HTML)
|
4
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: :haml, error_with: :faml)
|
5
5
|
:less
|
6
6
|
.users_controller {
|
7
7
|
.show_action {
|
@@ -20,7 +20,7 @@ describe Hamlit::Filters::Less do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'parses string interpolation' do
|
23
|
-
assert_render(<<-'HAML', <<-HTML)
|
23
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml, error_with: :faml)
|
24
24
|
:less
|
25
25
|
.foo {
|
26
26
|
content: "#{'<&>'}";
|
@@ -13,7 +13,7 @@ describe Hamlit::Filters::Markdown do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'renders markdown filter with string interpolation' do
|
16
|
-
assert_render(<<-'HAML', <<-HTML)
|
16
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
|
17
17
|
- project = '<Hamlit>'
|
18
18
|
:markdown
|
19
19
|
# #{project}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe Hamlit::Filters::Sass do
|
2
2
|
describe '#compile' do
|
3
3
|
it 'renders sass filter' do
|
4
|
-
assert_render(<<-HAML, <<-HTML)
|
4
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
|
5
5
|
:sass
|
6
6
|
.users_controller
|
7
7
|
.show_action
|
@@ -17,7 +17,7 @@ describe Hamlit::Filters::Sass do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'renders sass filter with string interpolation' do
|
20
|
-
assert_render(<<-'HAML', <<-HTML)
|
20
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
|
21
21
|
:sass
|
22
22
|
.users_controller
|
23
23
|
.show_action
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe Hamlit::Filters::Scss do
|
2
2
|
describe '#compile' do
|
3
3
|
it 'renders scss filter' do
|
4
|
-
assert_render(<<-HAML, <<-HTML)
|
4
|
+
assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
|
5
5
|
:scss
|
6
6
|
.users_controller {
|
7
7
|
.show_action {
|
@@ -19,7 +19,7 @@ describe Hamlit::Filters::Scss do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'parses string interpolation' do
|
22
|
-
assert_render(<<-'HAML', <<-HTML)
|
22
|
+
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
|
23
23
|
:scss
|
24
24
|
.users_controller {
|
25
25
|
.show_action {
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'haml'
|
2
|
+
require 'faml'
|
1
3
|
require 'hamlit'
|
2
4
|
require 'unindent'
|
3
5
|
|
4
6
|
module HamlitSpecHelper
|
7
|
+
DEFAULT_OPTIONS = { ugly: true, escape_html: true }.freeze
|
8
|
+
|
5
9
|
def parse_string(str)
|
6
10
|
Hamlit::Parser.new.call(str)
|
7
11
|
end
|
@@ -11,10 +15,21 @@ module HamlitSpecHelper
|
|
11
15
|
end
|
12
16
|
|
13
17
|
def assert_render(haml, html, options = {})
|
14
|
-
|
15
|
-
|
18
|
+
errs = array_wrap(options.delete(:error_with) || [])
|
19
|
+
impls = array_wrap(options.delete(:compatible_only) || [:haml, :faml] - errs)
|
20
|
+
haml = haml.unindent
|
21
|
+
html = html.unindent
|
16
22
|
|
17
23
|
expect(render_string(haml, options)).to eq(html)
|
24
|
+
impls.each do |impl|
|
25
|
+
expect_compatibility(impl, haml, options)
|
26
|
+
end
|
27
|
+
errs.each do |impl|
|
28
|
+
expect_compatibility(impl, haml, options, type: :error)
|
29
|
+
end
|
30
|
+
([:haml, :faml] - impls - errs).each do |impl|
|
31
|
+
expect_compatibility(impl, haml, options, type: :failure)
|
32
|
+
end
|
18
33
|
end
|
19
34
|
|
20
35
|
def assert_parse(haml, &block)
|
@@ -28,6 +43,58 @@ module HamlitSpecHelper
|
|
28
43
|
result = described_class.new.call(before)
|
29
44
|
expect(result).to eq(after)
|
30
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def expect_compatibility(impl, haml, options, type: :success)
|
50
|
+
case impl
|
51
|
+
when :haml
|
52
|
+
expect_haml(haml, options, type: type)
|
53
|
+
when :faml
|
54
|
+
expect_faml(haml, options, type: type)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def expect_faml(haml, options, type: :success)
|
59
|
+
hamlit_html = render_string(haml, options)
|
60
|
+
options = options.dup
|
61
|
+
options.delete(:escape_html)
|
62
|
+
|
63
|
+
case type
|
64
|
+
when :success
|
65
|
+
faml_html = eval Faml::Engine.new(options).call(haml)
|
66
|
+
expect(hamlit_html).to eq(faml_html)
|
67
|
+
when :failure
|
68
|
+
faml_html = eval Faml::Engine.new(options).call(haml)
|
69
|
+
expect(hamlit_html).to_not eq(faml_html)
|
70
|
+
when :error
|
71
|
+
expect {
|
72
|
+
eval Faml::Engine.new(options).call(haml)
|
73
|
+
}.to raise_error
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def expect_haml(haml, options, type: :success)
|
78
|
+
hamlit_html = render_string(haml, options)
|
79
|
+
options = DEFAULT_OPTIONS.merge(options)
|
80
|
+
case type
|
81
|
+
when :success
|
82
|
+
haml_html = Haml::Engine.new(haml, options).render(Object.new, {})
|
83
|
+
expect(hamlit_html).to eq(haml_html)
|
84
|
+
when :failure
|
85
|
+
haml_html = Haml::Engine.new(haml, options).render(Object.new, {})
|
86
|
+
expect(hamlit_html).to_not eq(haml_html)
|
87
|
+
when :error
|
88
|
+
expect {
|
89
|
+
Haml::Engine.new(haml, options).render(Object.new, {})
|
90
|
+
}.to raise_error
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def array_wrap(arr)
|
95
|
+
return arr if arr.is_a?(Array)
|
96
|
+
[arr]
|
97
|
+
end
|
31
98
|
end
|
32
99
|
|
33
100
|
RSpec.configure do |config|
|
data/test
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
trap 'rm .ruby-version' 0
|
5
|
+
|
6
|
+
VERSIONS=(
|
7
|
+
2.0.0
|
8
|
+
2.1.6
|
9
|
+
2.2.2
|
10
|
+
)
|
11
|
+
|
12
|
+
function test_with() {
|
13
|
+
version=$1
|
14
|
+
rbenv local $version
|
15
|
+
ruby -v
|
16
|
+
rake spec
|
17
|
+
}
|
18
|
+
|
19
|
+
for version in ${VERSIONS[@]}; do
|
20
|
+
test_with $version
|
21
|
+
done
|
22
|
+
|
23
|
+
rbenv local ${VERSIONS[2]}
|
24
|
+
ruby -v
|
25
|
+
rake rails:spec
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -339,6 +339,7 @@ files:
|
|
339
339
|
- lib/hamlit/concerns/registerable.rb
|
340
340
|
- lib/hamlit/concerns/ripperable.rb
|
341
341
|
- lib/hamlit/concerns/string_interpolation.rb
|
342
|
+
- lib/hamlit/concerns/whitespace.rb
|
342
343
|
- lib/hamlit/engine.rb
|
343
344
|
- lib/hamlit/filters/base.rb
|
344
345
|
- lib/hamlit/filters/coffee.rb
|
@@ -365,11 +366,11 @@ files:
|
|
365
366
|
- lib/hamlit/parsers/script.rb
|
366
367
|
- lib/hamlit/parsers/tag.rb
|
367
368
|
- lib/hamlit/parsers/text.rb
|
368
|
-
- lib/hamlit/parsers/whitespace.rb
|
369
369
|
- lib/hamlit/railtie.rb
|
370
370
|
- lib/hamlit/template.rb
|
371
371
|
- lib/hamlit/temple.rb
|
372
372
|
- lib/hamlit/version.rb
|
373
|
+
- release
|
373
374
|
- spec/Rakefile
|
374
375
|
- spec/hamlit/engine/comment_spec.rb
|
375
376
|
- spec/hamlit/engine/doctype_spec.rb
|
@@ -458,6 +459,7 @@ files:
|
|
458
459
|
- spec/rails/vendor/assets/javascripts/.keep
|
459
460
|
- spec/rails/vendor/assets/stylesheets/.keep
|
460
461
|
- spec/spec_helper.rb
|
462
|
+
- test
|
461
463
|
homepage: https://github.com/k0kubun/hamlit
|
462
464
|
licenses:
|
463
465
|
- MIT
|
@@ -571,3 +573,4 @@ test_files:
|
|
571
573
|
- spec/rails/vendor/assets/javascripts/.keep
|
572
574
|
- spec/rails/vendor/assets/stylesheets/.keep
|
573
575
|
- spec/spec_helper.rb
|
576
|
+
has_rdoc:
|