Allow to specify json engine used.
Default to MultiJson (with Yajl engine) instead of ActiveSupport::JSON
This commit is contained in:
parent
a9143693d4
commit
1db4cae807
7
Gemfile
7
Gemfile
|
@ -2,5 +2,8 @@ source "http://rubygems.org"
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
# Mocking library
|
gem 'yajl-ruby'
|
||||||
gem 'rspec-mocks'
|
|
||||||
|
group :test do
|
||||||
|
gem 'rspec-mocks'
|
||||||
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@ PATH
|
||||||
specs:
|
specs:
|
||||||
rabl-rails (0.1.0)
|
rabl-rails (0.1.0)
|
||||||
activesupport (~> 3.0)
|
activesupport (~> 3.0)
|
||||||
|
railties (~> 3.0)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
|
@ -55,6 +56,7 @@ GEM
|
||||||
sqlite3 (1.3.6)
|
sqlite3 (1.3.6)
|
||||||
thor (0.15.4)
|
thor (0.15.4)
|
||||||
tilt (1.3.3)
|
tilt (1.3.3)
|
||||||
|
yajl-ruby (1.1.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
@ -62,6 +64,6 @@ PLATFORMS
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
actionpack (~> 3.0)
|
actionpack (~> 3.0)
|
||||||
rabl-rails!
|
rabl-rails!
|
||||||
railties (~> 3.0)
|
|
||||||
rspec-mocks
|
rspec-mocks
|
||||||
sqlite3
|
sqlite3
|
||||||
|
yajl-ruby
|
||||||
|
|
|
@ -14,22 +14,29 @@ require 'rabl-rails/library'
|
||||||
require 'rabl-rails/handler'
|
require 'rabl-rails/handler'
|
||||||
require 'rabl-rails/railtie'
|
require 'rabl-rails/railtie'
|
||||||
|
|
||||||
|
require 'multi_json'
|
||||||
|
|
||||||
module RablRails
|
module RablRails
|
||||||
extend self
|
|
||||||
|
|
||||||
mattr_accessor :cache_templates
|
mattr_accessor :cache_templates
|
||||||
@@cache_templates = true
|
@@cache_templates = true
|
||||||
|
|
||||||
mattr_accessor :include_json_root
|
mattr_accessor :include_json_root
|
||||||
@@include_json_root = true
|
@@include_json_root = true
|
||||||
|
|
||||||
def configure
|
mattr_accessor :json_engine
|
||||||
|
@@json_engine = :yajl
|
||||||
|
|
||||||
|
def self.configure
|
||||||
yield self
|
yield self
|
||||||
|
post_configure
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_templates?
|
def self.cache_templates?
|
||||||
ActionController::Base.perform_caching && @@cache_templates
|
ActionController::Base.perform_caching && @@cache_templates
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def self.post_configure
|
||||||
|
MultiJson.engine = self.json_engine
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module RablRails
|
||||||
class JSON < Base
|
class JSON < Base
|
||||||
def format_output(hash)
|
def format_output(hash)
|
||||||
hash = { options[:root_name] => hash } if options[:root_name] && RablRails.include_json_root
|
hash = { options[:root_name] => hash } if options[:root_name] && RablRails.include_json_root
|
||||||
ActiveSupport::JSON.encode(hash)
|
MultiJson.encode(hash)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,8 +16,8 @@ Gem::Specification.new do |s|
|
||||||
s.require_paths = ["lib"]
|
s.require_paths = ["lib"]
|
||||||
|
|
||||||
s.add_dependency "activesupport", "~> 3.0"
|
s.add_dependency "activesupport", "~> 3.0"
|
||||||
|
s.add_dependency "railties", "~> 3.0"
|
||||||
|
|
||||||
s.add_development_dependency "sqlite3"
|
s.add_development_dependency "sqlite3"
|
||||||
s.add_development_dependency "railties", "~> 3.0"
|
|
||||||
s.add_development_dependency "actionpack", "~> 3.0"
|
s.add_development_dependency "actionpack", "~> 3.0"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue