mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Use Railtie instead of AcitveSupport.on_load
This commit is contained in:
parent
81be1a8b18
commit
d3984964f3
3 changed files with 22 additions and 20 deletions
|
@ -4,7 +4,6 @@ require 'hamlit/template'
|
|||
require 'hamlit/version'
|
||||
|
||||
begin
|
||||
require 'rails'
|
||||
require 'hamlit/rails_template'
|
||||
require 'hamlit/railtie'
|
||||
rescue LoadError
|
||||
end
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
require 'temple'
|
||||
|
||||
module Hamlit
|
||||
RailsTemplate = Temple::Templates::Rails.create(
|
||||
Hamlit::Engine,
|
||||
generator: Temple::Generators::RailsOutputBuffer,
|
||||
register_as: :haml,
|
||||
escape_html: true,
|
||||
streaming: true,
|
||||
ugly: true,
|
||||
)
|
||||
|
||||
ActiveSupport.on_load(:action_view) do
|
||||
# Haml extends Haml::Helpers in action view each time.
|
||||
# It costs much, so Hamlit includes a compatible module at first.
|
||||
ActionView::Base.send :include, Hamlit::Helpers
|
||||
end
|
||||
end
|
21
lib/hamlit/railtie.rb
Normal file
21
lib/hamlit/railtie.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'rails'
|
||||
require 'temple'
|
||||
|
||||
module Hamlit
|
||||
class Railtie < ::Rails::Railtie
|
||||
initializer :hamlit do |app|
|
||||
Hamlit::RailsTemplate = Temple::Templates::Rails.create(
|
||||
Hamlit::Engine,
|
||||
generator: Temple::Generators::RailsOutputBuffer,
|
||||
register_as: :haml,
|
||||
escape_html: true,
|
||||
streaming: true,
|
||||
ugly: true,
|
||||
)
|
||||
|
||||
# Haml extends Haml::Helpers in ActionView each time.
|
||||
# It costs much, so Hamlit includes a compatible module at first.
|
||||
ActionView::Base.send :include, Hamlit::Helpers
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue