mustache_json 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +5 -3
- data/VERSION +1 -1
- data/lib/mustache_json.rb +6 -2
- data/mustache_json.gemspec +1 -1
- data/spec/mustache_json_spec.rb +10 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -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>.
|
54
|
-
to
|
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>:
|
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.
|
1
|
+
0.0.4
|
data/lib/mustache_json.rb
CHANGED
@@ -44,8 +44,12 @@ class Mustache
|
|
44
44
|
#
|
45
45
|
# The default backend is the JSON gem.
|
46
46
|
def self.backend=(backend)
|
47
|
-
|
48
|
-
|
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.
|
data/mustache_json.gemspec
CHANGED
data/spec/mustache_json_spec.rb
CHANGED
@@ -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
|