rabl-rails/lib/rabl-rails.rb

88 lines
2.0 KiB
Ruby
Raw Normal View History

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'
require 'rabl-rails/condition'
2012-04-20 14:28:34 +00:00
require 'rabl-rails/compiler'
2012-04-20 14:28:34 +00:00
require 'rabl-rails/renderer'
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
require 'multi_json'
2012-04-20 14:28:34 +00:00
module RablRails
extend Renderer
2012-07-03 15:45:23 +00:00
autoload :Responder, 'rabl-rails/responder'
2012-04-02 14:22:43 +00:00
mattr_accessor :cache_templates
@@cache_templates = true
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-07-03 15:45:23 +00:00
mattr_accessor :responder_default_template
@@responder_default_template = 'show'
mattr_reader :plist_engine
2012-10-28 20:57:19 +00:00
@@plist_engine = nil
mattr_accessor :include_plist_root
@@include_plist_root = nil
def self.configure
2012-04-02 14:22:43 +00:00
yield self
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
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
end
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
end
def self.plist_engine=(name)
raise "Your plist engine does not respond to #dump" unless name.respond_to?(:dump)
@@plist_engine = name
end
def self.cache_templates?
2012-04-02 14:22:43 +00:00
ActionController::Base.perform_caching && @@cache_templates
end
def self.load_default_engines!
2012-10-28 20:57:19 +00:00
self.json_engine = MultiJson.default_engine
self.plist_engine = Plist::Emit if defined?(Plist)
2012-11-14 14:13:59 +00:00
if defined?(LibXML)
self.xml_engine = 'LibXML'
elsif defined?(Nokogiri)
self.xml_engine = 'Nokogiri'
end
end
2012-02-22 10:42:38 +00:00
end