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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9176878aecdc9d91f66537557f147dc8978d5003
4
- data.tar.gz: 117ba8f39ed072c6964536add0336be21c44d391
3
+ metadata.gz: 1c8ab979e9c67463e76b46cba08d35e24ead7a1f
4
+ data.tar.gz: 4e162fbcb66071f515a64b97ac7d540fddd81042
5
5
  SHA512:
6
- metadata.gz: 172e4743255392ecf60944c2820173cc6fbbb3e1f539f91380a0490fce09bc62d62ad0a239422502190f15ec55e8870200d5b574dbdc92bf0895a87c8f542902
7
- data.tar.gz: 5af7251fa167c35448565ff8612f4a5c175ab3b389f72e1f55c75f52d2d2acbb5447288211525f50ff19de470eb9bc80b5525cbd0df3c33dfc7327f54c016759
6
+ metadata.gz: 9cdf077dc864d24d4bf71b4f17d5830d15f9cc940468ea26dbb7ba87932a249cd0ea764b51614d76cbf21b1ee0f413f8e6f48e4facafbceac37b851e299480ab
7
+ data.tar.gz: 0da6132ea58a728dd16ec662223328e46661844c3e02f61ff20608850902eb1af9bbce96bc86dad6fd7957628127aa6747843c10da67ecd2dfcfa2e99e935e50
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v1.5.1
2
+
3
+ - Remove outer whitespace in the block
4
+
1
5
  ## v1.5.0
2
6
 
3
7
  - Remake implementation of outer whitespace removal
@@ -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!(ast)
20
- index = find_last_newline_index(ast)
21
- return unless index
22
-
23
- ast.delete_at(index)
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
- # Find [:static, "\n"]'s position ignoring [:code].
29
- # If it is not found, return nil.
30
- def find_last_newline_index(ast)
31
- ast.reverse_each.with_index do |node, index|
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
- return ast.length - index - 1
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
- nil
48
+ remove_last_outer_space!(exps) if deleted
39
49
  end
40
50
 
41
51
  def reset_outer_removal
@@ -1,3 +1,3 @@
1
1
  module Hamlit
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
@@ -186,42 +186,55 @@ describe Hamlit::Engine do
186
186
  HTML
187
187
  end
188
188
 
189
- it 'removes outer whitespace by >' do
190
- assert_render(<<-HAML, <<-HTML)
191
- %span> a
192
- %span b
193
- %span c
194
- %span>
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
- %span
204
+ </span><span>
197
205
  e
198
- %span f
199
- HAML
200
- <span>a</span><span>b</span>
201
- <span>c</span><span>
202
- d
203
- </span><span>
204
- e
205
- </span>
206
- <span>f</span>
207
- HTML
208
- end
209
-
210
- it 'removes outer whitespace by > from inside of block' do
211
- assert_render(<<-HAML, <<-HTML)
212
- %span a
213
- - if true
214
- %span>
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
- HAML
219
- <span>a</span><span>
220
- b
221
- </span><span>
222
- c
223
- </span>
224
- HTML
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
@@ -0,0 +1,4 @@
1
+ %span<
2
+ = link_to '#' do
3
+ = 'foo'
4
+ %span> bar
@@ -9,6 +9,7 @@ Rails.application.routes.draw do
9
9
  get :helpers
10
10
  get :safe_buffer
11
11
  get :old_attributes
12
+ get :whitespace
12
13
  end
13
14
  end
14
15
  end
@@ -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.0
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-03 00:00:00.000000000 Z
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