mustache_json 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,10 +50,12 @@ toward views that can be rendered either server-side (in Ruby) or client-side
50
50
 
51
51
  This library doesn't depend on any specific JSON library and is instead built
52
52
  to be able to have a swappable JSON encoding back-end. Back-ends are settable
53
- by calling <tt>Mustache::JSON.backend = :new_backend</tt>. Currently it defaults
54
- to the JSON gem but the following back-ends are available:
53
+ by calling <tt>Mustache::JSON.backend = :new_backend</tt>. You can also set it
54
+ to a class, which simply expects that there be a class method <tt>encode</tt>
55
+ that can be called with a Hash. Currently it defaults to the JSON gem but the
56
+ following back-ends are available:
55
57
 
56
- * JSON Gem (<tt>:json</tt>)
58
+ * JSON Gem (<tt>:json_gem</tt>)
57
59
  * JSON Pure (<tt>:json_pure</tt>)
58
60
  * ActiveSupport (<tt>:active_support</tt>)
59
61
  * YAJL Ruby (<tt>:yajl</tt>)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -44,8 +44,12 @@ class Mustache
44
44
  #
45
45
  # The default backend is the JSON gem.
46
46
  def self.backend=(backend)
47
- require "mustache/json/backends/#{backend.to_s.downcase}.rb"
48
- @backend = class_for(backend)
47
+ if backend.is_a?(Class)
48
+ @backend = backend
49
+ else
50
+ require "mustache/json/backends/#{backend.to_s.downcase}.rb"
51
+ @backend = class_for(backend)
52
+ end
49
53
  end
50
54
 
51
55
  # Generic JSON encoder that will use the specified back-end.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mustache_json}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Bleigh"]
@@ -56,6 +56,16 @@ describe Mustache do
56
56
  @stache = MustachioedPerson.new
57
57
  end
58
58
 
59
+ describe ' swappable backends' do
60
+ require 'mustache/json/backends/json_gem'
61
+ it 'should accept a strings, symbols, and classes' do
62
+ [:json_gem, 'json_gem', Mustache::JSON::Backends::JsonGem].each do |backend|
63
+ Mustache::JSON.backend = backend
64
+ Mustache::JSON.backend.should == Mustache::JSON::Backends::JsonGem
65
+ end
66
+ end
67
+ end
68
+
59
69
  [:json_gem, :json_pure, :yajl, :active_support].each do |backend|
60
70
  describe " with the #{backend} backend" do
61
71
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustache_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh