diff --git a/Gemfile b/Gemfile index 3dd2f20..46ed377 100644 --- a/Gemfile +++ b/Gemfile @@ -2,5 +2,8 @@ source "http://rubygems.org" gemspec -# Mocking library -gem 'rspec-mocks' +gem 'yajl-ruby' + +group :test do + gem 'rspec-mocks' +end diff --git a/Gemfile.lock b/Gemfile.lock index 881f7c6..707de63 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ PATH specs: rabl-rails (0.1.0) activesupport (~> 3.0) + railties (~> 3.0) GEM remote: http://rubygems.org/ @@ -55,6 +56,7 @@ GEM sqlite3 (1.3.6) thor (0.15.4) tilt (1.3.3) + yajl-ruby (1.1.0) PLATFORMS ruby @@ -62,6 +64,6 @@ PLATFORMS DEPENDENCIES actionpack (~> 3.0) rabl-rails! - railties (~> 3.0) rspec-mocks sqlite3 + yajl-ruby diff --git a/lib/rabl-rails.rb b/lib/rabl-rails.rb index 289746b..47eee41 100644 --- a/lib/rabl-rails.rb +++ b/lib/rabl-rails.rb @@ -14,22 +14,29 @@ require 'rabl-rails/library' require 'rabl-rails/handler' require 'rabl-rails/railtie' - +require 'multi_json' module RablRails - extend self - mattr_accessor :cache_templates @@cache_templates = true mattr_accessor :include_json_root @@include_json_root = true - def configure + mattr_accessor :json_engine + @@json_engine = :yajl + + def self.configure yield self + post_configure end - def cache_templates? + def self.cache_templates? ActionController::Base.perform_caching && @@cache_templates end + + private + def self.post_configure + MultiJson.engine = self.json_engine + end end diff --git a/lib/rabl-rails/renderers/json.rb b/lib/rabl-rails/renderers/json.rb index 29f528c..ef42fb5 100644 --- a/lib/rabl-rails/renderers/json.rb +++ b/lib/rabl-rails/renderers/json.rb @@ -3,7 +3,7 @@ module RablRails class JSON < Base def format_output(hash) hash = { options[:root_name] => hash } if options[:root_name] && RablRails.include_json_root - ActiveSupport::JSON.encode(hash) + MultiJson.encode(hash) end end end diff --git a/rabl-rails.gemspec b/rabl-rails.gemspec index 4707712..5fd4a42 100644 --- a/rabl-rails.gemspec +++ b/rabl-rails.gemspec @@ -16,8 +16,8 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_dependency "activesupport", "~> 3.0" + s.add_dependency "railties", "~> 3.0" s.add_development_dependency "sqlite3" - s.add_development_dependency "railties", "~> 3.0" s.add_development_dependency "actionpack", "~> 3.0" end