Skip to content

Commit

Permalink
Adds compatibility for sprockets 2, 3, and 4
Browse files Browse the repository at this point in the history
Fixes #122
  • Loading branch information
cmckni3 committed Aug 17, 2016
1 parent b2a826f commit 45118a4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/slim-rails/register_engine.rb
@@ -1,6 +1,12 @@
module Slim
module Rails
module RegisterEngine
class Transformer
def self.call(input)
Slim::Template.new(input[:name]) { input[:data] }.render(nil)
end
end

def self.register_engine(app, config)
if ::Rails::VERSION::MAJOR == 3
_register_engine3(app)
Expand All @@ -22,7 +28,16 @@ def self._register_engine(config)
return unless config.respond_to?(:assets)

config.assets.configure do |env|
env.register_engine('.slim', Slim::Template)
if env.respond_to?(:register_transformer)
env.register_mime_type 'text/slim', extensions: ['.slim', '.slim.html']#, charset: :html
env.register_preprocessor 'text/slim', 'text/html', RegisterEngine::Transformer
end

if env.respond_to?(:register_engine)
args = ['.slim', Slim::Template]
args << { silence_deprecation: true } if Sprockets::VERSION.start_with?("3")
env.register_engine(*args)
end
end
end
end
Expand Down

0 comments on commit 45118a4

Please sign in to comment.