From 51ef9e1bb3bbe7fa93ec75bc2184a1a79ffa8149 Mon Sep 17 00:00:00 2001 From: Ivan Kasatenko Date: Wed, 25 Jan 2017 16:36:26 +0600 Subject: [PATCH] Rails SLIM capturing support, addresses issue #133 --- lib/deface/slim_converter.rb | 18 +++++++++++++++++- spec/deface/slim_converter_spec.rb | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/deface/slim_converter.rb b/lib/deface/slim_converter.rb index 4384fb0..9145742 100644 --- a/lib/deface/slim_converter.rb +++ b/lib/deface/slim_converter.rb @@ -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 diff --git a/spec/deface/slim_converter_spec.rb b/spec/deface/slim_converter_spec.rb index 8812822..431e1a9 100644 --- a/spec/deface/slim_converter_spec.rb +++ b/spec/deface/slim_converter_spec.rb @@ -26,6 +26,13 @@ def slim_to_erb(src) li = link_to 'Log out', logout_path })).to eq("") 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("
<% _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)) %>
") + end end end