2012-02-22 18:14:00 +00:00
|
|
|
require 'rails/railtie'
|
|
|
|
|
|
|
|
require 'active_support'
|
|
|
|
require 'active_support/core_ext/class/attribute_accessors'
|
|
|
|
|
2012-04-20 14:28:34 +00:00
|
|
|
require 'rabl-rails/version'
|
|
|
|
require 'rabl-rails/template'
|
2012-09-05 16:11:23 +00:00
|
|
|
require 'rabl-rails/condition'
|
2012-04-20 14:28:34 +00:00
|
|
|
require 'rabl-rails/compiler'
|
2012-04-09 23:03:07 +00:00
|
|
|
|
2012-04-20 14:28:34 +00:00
|
|
|
require 'rabl-rails/renderer'
|
2012-04-09 23:03:07 +00:00
|
|
|
|
2012-04-20 14:28:34 +00:00
|
|
|
require 'rabl-rails/library'
|
|
|
|
require 'rabl-rails/handler'
|
|
|
|
require 'rabl-rails/railtie'
|
2012-02-22 18:14:00 +00:00
|
|
|
|
2012-07-18 21:42:09 +00:00
|
|
|
require 'multi_json'
|
2012-04-09 23:03:07 +00:00
|
|
|
|
2012-04-20 14:28:34 +00:00
|
|
|
module RablRails
|
2012-07-25 17:22:10 +00:00
|
|
|
extend Renderer
|
2012-09-05 16:11:23 +00:00
|
|
|
|
2012-07-03 15:45:23 +00:00
|
|
|
autoload :Responder, 'rabl-rails/responder'
|
2012-04-09 23:03:07 +00:00
|
|
|
|
2012-04-02 14:22:43 +00:00
|
|
|
mattr_accessor :cache_templates
|
|
|
|
@@cache_templates = true
|
2012-09-05 16:11:23 +00:00
|
|
|
|
2012-07-13 17:15:04 +00:00
|
|
|
mattr_accessor :include_json_root
|
|
|
|
@@include_json_root = true
|
2012-04-02 14:22:43 +00:00
|
|
|
|
2012-07-03 15:45:23 +00:00
|
|
|
mattr_accessor :use_custom_responder
|
|
|
|
@@use_custom_responder = false
|
2012-09-11 09:42:19 +00:00
|
|
|
|
2012-07-03 15:45:23 +00:00
|
|
|
mattr_accessor :responder_default_template
|
|
|
|
@@responder_default_template = 'show'
|
2012-07-18 21:42:09 +00:00
|
|
|
|
2012-11-14 11:10:54 +00:00
|
|
|
mattr_reader :plist_engine
|
2012-10-28 20:57:19 +00:00
|
|
|
@@plist_engine = nil
|
|
|
|
|
|
|
|
mattr_accessor :include_plist_root
|
|
|
|
@@include_plist_root = nil
|
|
|
|
|
2012-07-18 21:42:09 +00:00
|
|
|
def self.configure
|
2012-04-02 14:22:43 +00:00
|
|
|
yield self
|
2012-09-11 09:42:19 +00:00
|
|
|
|
2012-07-03 15:45:23 +00:00
|
|
|
ActionController::Base.responder = Responder if self.use_custom_responder
|
2012-04-02 14:22:43 +00:00
|
|
|
end
|
2012-09-05 16:11:23 +00:00
|
|
|
|
2012-08-03 13:38:43 +00:00
|
|
|
def self.json_engine=(name)
|
|
|
|
MultiJson.engine = name
|
|
|
|
rescue LoadError
|
2012-09-13 15:05:52 +00:00
|
|
|
Rails.logger.warn %Q(WARNING: rabl-rails could not load "#{name}" as JSON engine, fallback to default)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.json_engine
|
|
|
|
MultiJson.engine
|
2012-08-03 13:38:43 +00:00
|
|
|
end
|
2012-09-11 09:42:19 +00:00
|
|
|
|
2012-09-17 13:24:39 +00:00
|
|
|
def self.xml_engine=(name)
|
|
|
|
ActiveSupport::XmlMini.backend = name
|
|
|
|
rescue LoadError, NameError
|
|
|
|
Rails.logger.warn %Q(WARNING: rabl-rails could not load "#{name}" as XML engine, fallback to default)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.xml_engine
|
|
|
|
ActiveSupport::XmlMini.backend
|
2012-08-03 13:38:43 +00:00
|
|
|
end
|
2012-09-05 16:11:23 +00:00
|
|
|
|
2012-11-14 11:10:54 +00:00
|
|
|
def self.plist_engine=(name)
|
|
|
|
raise "Your plist engine does not respond to #dump" unless name.respond_to?(:dump)
|
|
|
|
@@plist_engine = name
|
|
|
|
end
|
|
|
|
|
2012-07-18 21:42:09 +00:00
|
|
|
def self.cache_templates?
|
2012-04-02 14:22:43 +00:00
|
|
|
ActionController::Base.perform_caching && @@cache_templates
|
|
|
|
end
|
2012-09-05 16:11:23 +00:00
|
|
|
|
2012-08-03 13:38:43 +00:00
|
|
|
def self.load_default_engines!
|
2012-10-28 20:57:19 +00:00
|
|
|
self.json_engine = MultiJson.default_engine
|
|
|
|
self.xml_engine = 'LibXML' if defined?(LibXML)
|
|
|
|
self.plist_engine = Plist::Emit if defined?(Plist)
|
2012-07-18 21:42:09 +00:00
|
|
|
end
|
2012-02-22 10:42:38 +00:00
|
|
|
end
|