Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/html2slim/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def initialize(file)
erb.gsub!(/<%(.+?)\s*\{\s*(\|.+?\|)?\s*%>/){ %(<%#{$1} do #{$2}%>) }

# case, if, for, unless, until, while, and blocks...
erb.gsub!(/<%(-\s+)?((\s*(case|if|for|unless|until|while) .+?)|.+?do\s*(\|.+?\|)?\s*)-?%>/){ %(<ruby code="#{$2.gsub(/"/, '&quot;')}">) }
statement_start = /\s*(?:case|if|for|unless|until|while) .+?/
method_start = /.+?(?:,\s*\n.+?)*do\s*(?:\|.+?\|)?\s*/
erb.gsub!(/<%(?:-\s+)?(#{statement_start}|#{method_start})-?%>/){ %(<ruby code="#{$1.gsub(/"/, '&quot;')}">) }
# else
erb.gsub!(/<%-?\s*else\s*-?%>/, %(</ruby><ruby code="else">))
# elsif
Expand Down
2 changes: 1 addition & 1 deletion lib/html2slim/hpricot_monkeypatches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def to_slim(lvl=0)
private

def slim_ruby_code(r)
(code.strip[0] == "=" ? "" : "- ") + code.strip.gsub(/\n/, "\n#{r}- ")
(code.strip[0] == "=" ? "" : "- ") + code.strip.gsub(/(?<!,)([ ]*\n)/, "\\1#{r}- ")
end

def code
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/multiline_method_args.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= form_with url: search_path,
class: "search-form",
method: :get do |form| %>
<div class="form-group">
<%= form.text_field :query,
class: "form-control" %>
</div>
<%= form.submit "Search",
class: "btn" %>
<% end %>
8 changes: 8 additions & 0 deletions test/fixtures/multiline_method_args.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
= form_with url: search_path,
class: "search-form",
method: :get do |form|
.form-group
= form.text_field :query,
class: "form-control"
= form.submit "Search",
class: "btn"
6 changes: 6 additions & 0 deletions test/test_html2slim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def test_convert_multiline_block
end
end

def test_convert_multiline_method_args
IO.popen("bin/erb2slim test/fixtures/multiline_method_args.erb -", "r") do |f|
assert_equal File.read("test/fixtures/multiline_method_args.slim"), f.read
end
end

def test_convert_elsif_block
IO.popen("bin/erb2slim test/fixtures/erb_elsif.erb -", "r") do |f|
assert_equal File.read("test/fixtures/erb_elsif.slim"), f.read
Expand Down