forked from slim-template/slim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve load order dependencies with Rails
Using `if defined?(::ActionView)` can cause complications in environments where Bundler gems are preloaded before a Rails application boots. This will lead to a scenario where Slim just silently fails to register a Rails template handler, which will lead to missing template errors later. The patch uses a `Rails::Railtie` instead to define a lazy initialization path using an `on_load` hook. This will make the slim gem independent of the gem and rails app loading order. The only constraint is that `gem rails` appears before `gem slim` in the Gemfile. However, this applies for pretty much any Rails gem.
- Loading branch information
Showing
3 changed files
with
18 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Slim | ||
class Railtie < Rails::Railtie | ||
initializer "initialize slim template handler" do | ||
ActiveSupport.on_load(:action_view) do | ||
Slim::RailsTemplate = Temple::Templates::Rails(Slim::Engine, | ||
register_as: :slim, | ||
# Use rails-specific generator. This is necessary | ||
# to support block capturing and streaming. | ||
generator: Temple::Generators::RailsOutputBuffer, | ||
# Disable the internal slim capturing. | ||
# Rails takes care of the capturing by itself. | ||
disable_capture: true, | ||
streaming: true) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters