Skip to content

Commit db07797

Browse files
committed
Fixed issue of the wrong conversion of the leading dashed something
For example: ```ruby <%- a = 1 -%> ``` ```erb2slim``` command outputs a following wrong slim file. ```slim - - a = 1 ```
1 parent c2a15a4 commit db07797

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

lib/html2slim/converter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def initialize(file)
2727
# when
2828
erb.gsub!(/<%-?\s*(when .+?)\s*-?%>/){ %(</ruby><ruby code="#{$1.gsub(/"/, '&quot;')}">) }
2929
erb.gsub!(/<%\s*(end|}|end\s+-)\s*%>/, %(</ruby>))
30-
erb.gsub!(/<%(.+?)\s*-?%>/m){ %(<ruby code="#{$1.gsub(/"/, '&quot;')}"></ruby>) }
30+
erb.gsub!(/<%-?(.+?)\s*-?%>/m){ %(<ruby code="#{$1.gsub(/"/, '&quot;')}"></ruby>) }
3131
@slim ||= Hpricot(erb).to_slim
3232
end
3333
end

test/test_html2slim.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,29 @@ def test_data_attributes
8686

8787
def test_erb_tags
8888
# simple
89-
assert_erb_to_slim '<% a = 1 %>', '- a = 1'
89+
assert_erb_to_slim_with_and_without_leading_dash '<% a = 1 %>', '- a = 1'
9090
# simple = (puts)
9191
assert_erb_to_slim '<%= @a.b %>', '= @a.b'
9292
# no block
93-
assert_erb_to_slim '<% @a %>SOME<% @b %>', "- @a\n| SOME\n- @b"
93+
assert_erb_to_slim_with_and_without_leading_dash '<% @a %>SOME<% @b %>', "- @a\n| SOME\n- @b"
9494
# block with do
95-
assert_erb_to_slim '<% @a.each do |yay| %>SOME<% yay %><% end %>', "- @a.each do |yay|\n | SOME\n - yay"
95+
assert_erb_to_slim_with_and_without_leading_dash '<% @a.each do |yay| %>SOME<% yay %><% end %>', "- @a.each do |yay|\n | SOME\n - yay"
9696
# block with { and on var
97-
assert_erb_to_slim '<% @a.each { |yay| %>SOME<% yay %><% } %>', "- @a.each do |yay|\n | SOME\n - yay"
97+
assert_erb_to_slim_with_and_without_leading_dash '<% @a.each { |yay| %>SOME<% yay %><% } %>', "- @a.each do |yay|\n | SOME\n - yay"
9898
# block without vars
99-
assert_erb_to_slim '<% 10.times { %>SOME<% yay %><% } %>', "- 10.times do\n | SOME\n - yay"
99+
assert_erb_to_slim_with_and_without_leading_dash '<% 10.times { %>SOME<% yay %><% } %>', "- 10.times do\n | SOME\n - yay"
100100
# if
101-
assert_erb_to_slim '<% if 1 == 1 %>SOME<% yay %><% end %>', "- if 1 == 1\n | SOME\n - yay"
101+
assert_erb_to_slim_with_and_without_leading_dash '<% if 1 == 1 %>SOME<% yay %><% end %>', "- if 1 == 1\n | SOME\n - yay"
102102
# else
103-
assert_erb_to_slim '<% if 1 == 1 %>SOME<% yay %><% else %>OTHER<% end %>', "- if 1 == 1\n | SOME\n - yay\n- else\n | OTHER"
103+
assert_erb_to_slim_with_and_without_leading_dash '<% if 1 == 1 %>SOME<% yay %><% else %>OTHER<% end %>', "- if 1 == 1\n | SOME\n - yay\n- else\n | OTHER"
104104
# elsif
105-
assert_erb_to_slim '<% if 1 == 1 %>SOME<% yay %><% elsif 2 == 2 %>OTHER<% end %>', "- if 1 == 1\n | SOME\n - yay\n- elsif 2 == 2\n | OTHER"
105+
assert_erb_to_slim_with_and_without_leading_dash '<% if 1 == 1 %>SOME<% yay %><% elsif 2 == 2 %>OTHER<% end %>', "- if 1 == 1\n | SOME\n - yay\n- elsif 2 == 2\n | OTHER"
106106
# case/when
107-
assert_erb_to_slim '<% case @foo %><% when 1 %>1<% when 2 %>2<% else %>3<% end %>', "- case @foo\n- when 1\n | 1\n- when 2\n | 2\n- else\n | 3"
107+
assert_erb_to_slim_with_and_without_leading_dash '<% case @foo %><% when 1 %>1<% when 2 %>2<% else %>3<% end %>', "- case @foo\n- when 1\n | 1\n- when 2\n | 2\n- else\n | 3"
108108
# while
109-
assert_erb_to_slim '<% while @foo.next %>NEXT<% end %>', "- while @foo.next\n | NEXT"
109+
assert_erb_to_slim_with_and_without_leading_dash '<% while @foo.next %>NEXT<% end %>', "- while @foo.next\n | NEXT"
110110
# all togheter and mixed
111-
assert_erb_to_slim '<% while @foo.next %><% if 1 == 1 %><% for i in @foo.bar %>WORKS<% end %><% end %><% end %>', "- while @foo.next\n - if 1 == 1\n - for i in @foo.bar\n | WORKS"
111+
assert_erb_to_slim_with_and_without_leading_dash '<% while @foo.next %><% if 1 == 1 %><% for i in @foo.bar %>WORKS<% end %><% end %><% end %>', "- while @foo.next\n - if 1 == 1\n - for i in @foo.bar\n | WORKS"
112112
# unless
113113
assert_erb_to_slim_with_and_without_leading_dash '<% unless @foo.done? %>NEXT<% end %>',
114114
"- unless @foo.done?\n | NEXT"

0 commit comments

Comments
 (0)