Skip to content

Commit

Permalink
Rails SLIM capturing support, addresses issue spree#133
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyWriter committed Jan 25, 2017
1 parent 04bbbfe commit 51ef9e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/deface/slim_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@ def initialize(template, options = {})
end

def result
::Slim::ERBConverter.new.call(@template).gsub /<%\s*%>/, ''
conv = defined?(Slim::RailsTemplate) ? rails_converter : generic_converter
conv.call(@template).gsub(/<%\s*%>/, '')
end

private

def rails_converter
slim_erb_converter.new(
Temple::OptionMap.new(Slim::RailsTemplate.options.to_h.except(:engine))
)
end

def generic_converter
slim_erb_converter.new
end

def slim_erb_converter
::Slim::ERBConverter
end
end
end
7 changes: 7 additions & 0 deletions spec/deface/slim_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def slim_to_erb(src)
li = link_to 'Log out', logout_path
})).to eq("<nav id=\"top-nav-bar\"><ul class=\"inline\" data-hook=\"\" id=\"nav-bar\"><% if true %><div class=\"nav-links high_res\"><li class=\"dropdown\"><div class=\"welcome\">Welcome <%= ::Temple::Utils.escape_html_safe((Spree::User.first.email)) %> &#9662;</div><ul class=\"dropdown\"><li><%= ::Temple::Utils.escape_html_safe((link_to 'Account', account_path)) %></li><li><%= ::Temple::Utils.escape_html_safe((link_to 'Log out', logout_path)) %></li></ul></li></div><% end %></ul></nav>")
end

it "should handle Rails capturing" do
expect(slim_to_erb(%q{#wishlist-form
= form_for Spree::WishedProduct.new do |f|
= f.submit 'Save'
})).to eq("<div id=\"wishlist-form\"><% _slim_controls1 = form_for Spree::WishedProduct.new do |f| %><%= ::Temple::Utils.escape_html_safe((f.submit 'Save')) %><% end %><%= ::Temple::Utils.escape_html_safe((_slim_controls1)) %></div>")
end
end

end
Expand Down

0 comments on commit 51ef9e1

Please sign in to comment.