json_builder 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -71,6 +71,10 @@ You will get something like:
71
71
 
72
72
  puts json.compile!
73
73
 
74
+ ## Conversions
75
+
76
+ Time - [ISO-8601](http://en.wikipedia.org/wiki/ISO_8601)
77
+
74
78
  ## Speed
75
79
  JSON Builder is very fast, it's roughly 6 times faster than the core XML Builder based on the [speed benchmark](http://github.com/dewski/json_builder/blob/master/test/benchmarks/speed.rb).
76
80
 
data/lib/json_builder.rb CHANGED
@@ -1,6 +1,3 @@
1
1
  require 'json_builder/version'
2
2
  require 'json_builder/generator'
3
-
4
- if defined? Rails
5
- require 'json_builder/template'
6
- end
3
+ require 'json_builder/template' if defined? Rails
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'blankslate' unless defined?(BlankSlate)
2
+ require 'blankslate' unless defined? BlankSlate
3
3
  require 'json'
4
4
 
5
5
  module JSONBuilder
@@ -17,6 +17,11 @@ module JSONBuilder
17
17
  compile!
18
18
  end
19
19
 
20
+ #
21
+ # Using +tag!+ is neccessary when dynamic keys are needed
22
+ #
23
+ # json.tag!
24
+ #
20
25
  def tag!(sym, *args, &block)
21
26
  method_missing(sym.to_sym, *args, &block)
22
27
  end
@@ -52,8 +57,15 @@ module JSONBuilder
52
57
  end
53
58
 
54
59
  def compile!
60
+ # If there is no JSON, no need for an array
55
61
  if @is_array
56
- compiled = ('[{' + @compiled.join(',') + '}]').gsub(',},{,', '},{')
62
+ if @compiled.length > 0
63
+ compiled = ('[{' + @compiled.join(',') + '}]').gsub(',},{,', '},{')
64
+ else
65
+ # No need to make this pretty
66
+ @pretty_print = false
67
+ compiled = '[]'
68
+ end
57
69
  else
58
70
  compiled = '{' + @compiled.join(', ') + '}'
59
71
  end
@@ -75,7 +87,7 @@ module JSONBuilder
75
87
  when TrueClass then 'true'
76
88
  when FalseClass then 'false'
77
89
  when NilClass then 'null'
78
- when DateTime, Time, Date then "\"#{text.strftime("%Y-%m-%dT%H:%M:%S")}\""
90
+ when DateTime, Time, Date then "\"#{text.strftime('%Y-%m-%dT%H:%M:%S%z')}\""
79
91
  when Fixnum then text
80
92
  end
81
93
  end
@@ -1,3 +1,3 @@
1
1
  module JSONBuilder
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_builder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 1
10
- version: 2.0.1
9
+ - 2
10
+ version: 2.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Garrett Bjerkhoel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-27 00:00:00 -07:00
18
+ date: 2010-08-31 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency