hamlit 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/hamlit/compilers/strip.rb +2 -1
- data/lib/hamlit/parsers/whitespace.rb +24 -14
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/tag_spec.rb +46 -33
- data/spec/rails/app/views/users/whitespace.html.haml +4 -0
- data/spec/rails/config/routes.rb +1 -0
- data/spec/rails/spec/hamlit_spec.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c8ab979e9c67463e76b46cba08d35e24ead7a1f
|
4
|
+
data.tar.gz: 4e162fbcb66071f515a64b97ac7d540fddd81042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cdf077dc864d24d4bf71b4f17d5830d15f9cc940468ea26dbb7ba87932a249cd0ea764b51614d76cbf21b1ee0f413f8e6f48e4facafbceac37b851e299480ab
|
7
|
+
data.tar.gz: 0da6132ea58a728dd16ec662223328e46661844c3e02f61ff20608850902eb1af9bbce96bc86dad6fd7957628127aa6747843c10da67ecd2dfcfa2e99e935e50
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# This module is created to compile [:haml, :strip],
|
2
|
+
# which is sexp for whitespace inner removal.module Hamlit
|
1
3
|
module Hamlit
|
2
4
|
module Compilers
|
3
5
|
module Strip
|
@@ -10,7 +12,6 @@ module Hamlit
|
|
10
12
|
|
11
13
|
def strip_newline(content)
|
12
14
|
indexes = newline_indexes(content)
|
13
|
-
return content if indexes.length < 2
|
14
15
|
|
15
16
|
content = content.dup
|
16
17
|
content.delete_at(indexes.last)
|
@@ -16,26 +16,36 @@ module Hamlit
|
|
16
16
|
inner_removal
|
17
17
|
end
|
18
18
|
|
19
|
-
def remove_last_outer_space!(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def remove_last_outer_space!(exps)
|
20
|
+
exps.reverse!
|
21
|
+
remove_first_outer_space!(exps)
|
22
|
+
ensure
|
23
|
+
exps.reverse!
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
sexp, *args = node
|
33
|
-
next if sexp == :code
|
34
|
-
return if node != [:static, "\n"]
|
28
|
+
def remove_first_outer_space!(exps)
|
29
|
+
deleted = false
|
30
|
+
exps.delete_if do |exp|
|
31
|
+
break if deleted
|
35
32
|
|
36
|
-
|
33
|
+
name, *args = exp
|
34
|
+
case name
|
35
|
+
when :static
|
36
|
+
break if args != ["\n"]
|
37
|
+
deleted = true
|
38
|
+
next true
|
39
|
+
when :code
|
40
|
+
next false
|
41
|
+
when :newline
|
42
|
+
next false
|
43
|
+
when :haml
|
44
|
+
remove_last_outer_space!(exp) if args.first == :script
|
45
|
+
end
|
46
|
+
break
|
37
47
|
end
|
38
|
-
|
48
|
+
remove_last_outer_space!(exps) if deleted
|
39
49
|
end
|
40
50
|
|
41
51
|
def reset_outer_removal
|
data/lib/hamlit/version.rb
CHANGED
@@ -186,42 +186,55 @@ describe Hamlit::Engine do
|
|
186
186
|
HTML
|
187
187
|
end
|
188
188
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
189
|
+
describe 'whitespace removal' do
|
190
|
+
it 'removes outer whitespace by >' do
|
191
|
+
assert_render(<<-HAML, <<-HTML)
|
192
|
+
%span> a
|
193
|
+
%span b
|
194
|
+
%span c
|
195
|
+
%span>
|
196
|
+
d
|
197
|
+
%span
|
198
|
+
e
|
199
|
+
%span f
|
200
|
+
HAML
|
201
|
+
<span>a</span><span>b</span>
|
202
|
+
<span>c</span><span>
|
195
203
|
d
|
196
|
-
|
204
|
+
</span><span>
|
197
205
|
e
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
b
|
216
|
-
%span
|
206
|
+
</span>
|
207
|
+
<span>f</span>
|
208
|
+
HTML
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'removes outer whitespace by > from inside of block' do
|
212
|
+
assert_render(<<-HAML, <<-HTML)
|
213
|
+
%span a
|
214
|
+
- if true
|
215
|
+
%span>
|
216
|
+
b
|
217
|
+
%span
|
218
|
+
c
|
219
|
+
HAML
|
220
|
+
<span>a</span><span>
|
221
|
+
b
|
222
|
+
</span><span>
|
217
223
|
c
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
224
|
+
</span>
|
225
|
+
HTML
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'removes whitespaces inside block script' do
|
229
|
+
assert_render(<<-HAML, <<-HTML)
|
230
|
+
%span<
|
231
|
+
= 2.times do
|
232
|
+
= 'foo'
|
233
|
+
%span> bar
|
234
|
+
HAML
|
235
|
+
<span>foofoo2<span>bar</span></span>
|
236
|
+
HTML
|
237
|
+
end
|
225
238
|
end
|
226
239
|
end
|
227
240
|
end
|
data/spec/rails/config/routes.rb
CHANGED
@@ -72,6 +72,11 @@ describe 'Hamlit rails integration', type: :request do
|
|
72
72
|
get form_users_path
|
73
73
|
expect(response.body).to include('row')
|
74
74
|
end
|
75
|
+
|
76
|
+
it 'renders whitespace removal inside #capture' do
|
77
|
+
get whitespace_users_path
|
78
|
+
expect(response.body).to include('<a href="#">foo</a>')
|
79
|
+
end
|
75
80
|
end
|
76
81
|
|
77
82
|
describe 'haml helpers' do
|
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.1
|
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-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -417,6 +417,7 @@ files:
|
|
417
417
|
- spec/rails/app/views/users/index.html.haml
|
418
418
|
- spec/rails/app/views/users/old_attributes.html.haml
|
419
419
|
- spec/rails/app/views/users/safe_buffer.html.haml
|
420
|
+
- spec/rails/app/views/users/whitespace.html.haml
|
420
421
|
- spec/rails/bin/bundle
|
421
422
|
- spec/rails/bin/rails
|
422
423
|
- spec/rails/bin/rake
|
@@ -529,6 +530,7 @@ test_files:
|
|
529
530
|
- spec/rails/app/views/users/index.html.haml
|
530
531
|
- spec/rails/app/views/users/old_attributes.html.haml
|
531
532
|
- spec/rails/app/views/users/safe_buffer.html.haml
|
533
|
+
- spec/rails/app/views/users/whitespace.html.haml
|
532
534
|
- spec/rails/bin/bundle
|
533
535
|
- spec/rails/bin/rails
|
534
536
|
- spec/rails/bin/rake
|