diff --git a/lib/rabl-rails.rb b/lib/rabl-rails.rb index fe297c2..7426b84 100644 --- a/lib/rabl-rails.rb +++ b/lib/rabl-rails.rb @@ -24,18 +24,25 @@ module RablRails mattr_accessor :include_json_root @@include_json_root = true - mattr_accessor :json_engine + mattr_reader :json_engine @@json_engine = :yajl def self.configure yield self 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? ActionController::Base.perform_caching && @@cache_templates end - def self.set_conversion_engines! - MultiJson.use(self.json_engine) rescue nil + def self.load_default_engines! + self.json_engine = :yajl end end diff --git a/lib/rabl-rails/railtie.rb b/lib/rabl-rails/railtie.rb index 5201adb..eee7e22 100644 --- a/lib/rabl-rails/railtie.rb +++ b/lib/rabl-rails/railtie.rb @@ -1,9 +1,10 @@ module RablRails class Railtie < Rails::Railtie initializer "rabl.initialize" do |app| + RablRails.load_default_engines! + ActiveSupport.on_load(:action_view) do ActionView::Template.register_template_handler :rabl, RablRails::Handlers::Rabl - RablRails.set_conversion_engines! end end end