Fix engines loading.
Load default engines once and setter also set up engine
This commit is contained in:
parent
9ce0e2b350
commit
62dfd3b7d5
|
@ -24,18 +24,25 @@ module RablRails
|
||||||
mattr_accessor :include_json_root
|
mattr_accessor :include_json_root
|
||||||
@@include_json_root = true
|
@@include_json_root = true
|
||||||
|
|
||||||
mattr_accessor :json_engine
|
mattr_reader :json_engine
|
||||||
@@json_engine = :yajl
|
@@json_engine = :yajl
|
||||||
|
|
||||||
def self.configure
|
def self.configure
|
||||||
yield self
|
yield self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.json_engine=(name)
|
||||||
|
MultiJson.engine = name
|
||||||
|
@@json_engine = name
|
||||||
|
rescue LoadError
|
||||||
|
Rails.logger.warn %Q(WARNING: rabl-rails could not load "#{self.json_engine}" as JSON engine, fallback to default)
|
||||||
|
end
|
||||||
|
|
||||||
def self.cache_templates?
|
def self.cache_templates?
|
||||||
ActionController::Base.perform_caching && @@cache_templates
|
ActionController::Base.perform_caching && @@cache_templates
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.set_conversion_engines!
|
def self.load_default_engines!
|
||||||
MultiJson.use(self.json_engine) rescue nil
|
self.json_engine = :yajl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
module RablRails
|
module RablRails
|
||||||
class Railtie < Rails::Railtie
|
class Railtie < Rails::Railtie
|
||||||
initializer "rabl.initialize" do |app|
|
initializer "rabl.initialize" do |app|
|
||||||
|
RablRails.load_default_engines!
|
||||||
|
|
||||||
ActiveSupport.on_load(:action_view) do
|
ActiveSupport.on_load(:action_view) do
|
||||||
ActionView::Template.register_template_handler :rabl, RablRails::Handlers::Rabl
|
ActionView::Template.register_template_handler :rabl, RablRails::Handlers::Rabl
|
||||||
RablRails.set_conversion_engines!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue