From 72a4d20ff144d3550ef908146970f85199466827 Mon Sep 17 00:00:00 2001 From: kmossdorf Date: Thu, 7 Sep 2017 16:15:18 +0200 Subject: [PATCH 1/2] Add ability to use slim in conjunction with ejs and jst --- lib/slim-rails/register_engine.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/slim-rails/register_engine.rb b/lib/slim-rails/register_engine.rb index d4241aa..1ac8ea9 100644 --- a/lib/slim-rails/register_engine.rb +++ b/lib/slim-rails/register_engine.rb @@ -30,6 +30,7 @@ def self._register_engine(config) config.assets.configure do |env| if env.respond_to?(:register_transformer) && Sprockets::VERSION.to_i > 3 env.register_mime_type 'text/slim', extensions: ['.slim', '.slim.html']#, charset: :html + env.register_mime_type 'application/javascript', extensions: ['.js.jst.ejs.slim'] env.register_transformer 'text/slim', 'text/html', RegisterEngine::Transformer elsif env.respond_to?(:register_engine) args = ['.slim', Slim::Template] From 785432888ae637f0a5e5b115606f5cef264bb257 Mon Sep 17 00:00:00 2001 From: kmossdorf Date: Thu, 7 Sep 2017 16:15:18 +0200 Subject: [PATCH 2/2] Add ability to use slim in conjunction with ejs and jst --- lib/slim-rails/register_engine.rb | 1 + test/lib/slim-rails_assets_test.rb | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/slim-rails/register_engine.rb b/lib/slim-rails/register_engine.rb index d4241aa..d12acbc 100644 --- a/lib/slim-rails/register_engine.rb +++ b/lib/slim-rails/register_engine.rb @@ -30,6 +30,7 @@ def self._register_engine(config) config.assets.configure do |env| if env.respond_to?(:register_transformer) && Sprockets::VERSION.to_i > 3 env.register_mime_type 'text/slim', extensions: ['.slim', '.slim.html']#, charset: :html + env.register_mime_type 'application/javascript', extensions: %w[.js.slim .jst.slim .ejs.slim] env.register_transformer 'text/slim', 'text/html', RegisterEngine::Transformer elsif env.respond_to?(:register_engine) args = ['.slim', Slim::Template] diff --git a/test/lib/slim-rails_assets_test.rb b/test/lib/slim-rails_assets_test.rb index 5e7b261..2baf007 100644 --- a/test/lib/slim-rails_assets_test.rb +++ b/test/lib/slim-rails_assets_test.rb @@ -18,9 +18,23 @@ class DummyApp < ::Rails::Application #{code} APP + # Test HTML creation asset_path = File.join(dir, 'app', 'assets', 'html', 'test.slim') FileUtils.mkdir_p(File.dirname(asset_path)) - File.write(asset_path, ".test\n | hi") + File.write(asset_path, ".test\n | hi") + + asset_path = File.join(dir, 'app', 'assets', 'html', 'test.js.slim') + FileUtils.mkdir_p(File.dirname(asset_path)) + content = <<-EOH + ruby: + isTrue = true + + .test + - if true + javascript: + var x = 42; + EOH + File.write(asset_path, content) `BUNDLE_GEMFILE=#{ENV['BUNDLE_GEMFILE']} bundle exec ruby #{app_path}` end @@ -31,4 +45,10 @@ class DummyApp < ::Rails::Application assert_equal '
hi
', with_app(true, 'print DummyApp.assets["test.slim"].to_s') assert_equal '
hi
', with_app(true, 'print DummyApp.assets["test", accept: "text/html"].to_s') end + + test 'compile javascript slim view' do + assert_equal 'ok', with_app(false, 'print DummyApp.assets || "ok"') + assert_equal '
', with_app(true, 'print DummyApp.assets["test.js.slim"].to_s.strip') + assert_equal '
', with_app(true, 'print DummyApp.assets["test.js.slim", accept: "text/html"].to_s') + end end