diff --git a/lib/slim-rails/register_engine.rb b/lib/slim-rails/register_engine.rb index 695788a..2d51181 100644 --- a/lib/slim-rails/register_engine.rb +++ b/lib/slim-rails/register_engine.rb @@ -31,6 +31,7 @@ def _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 d708e85..3527bb4 100644 --- a/test/lib/slim-rails_assets_test.rb +++ b/test/lib/slim-rails_assets_test.rb @@ -31,7 +31,20 @@ class DummyApp < ::Rails::Application 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 @@ -62,4 +75,10 @@ class DummyApp < ::Rails::Application assert_equal ".test\n | hi", with_app(true, 'print DummyApp.assets["test.slim"]') end 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