neatjson 0.6.2 → 0.7
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.
- checksums.yaml +4 -4
- data/README.md +199 -194
- data/lib/neatjson.rb +24 -23
- data/neatjson.gemspec +17 -17
- data/test/test_neatjson.rb +0 -0
- data/test/tests.js +173 -167
- data/test/tests.rb +169 -165
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8936fb4141535e1b7ff27991e518e2aa402c592
|
4
|
+
data.tar.gz: 9c7eb711499583c719c168cf3f29f443ec900082
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e4a1047b1cffdcaa584779dd0e5368d7353ee08272734855ac8249e500734b8bbe6d76cdcb316e2dadde9753b88e58ecb633753cbfca0ab06590aa6847a4ca6
|
7
|
+
data.tar.gz: 075950b5e26facacbb8c4b8aeda3b310c8e5cc705578e5e952254f29323ea2fd5c5c5945f011988937848f96104f53df3bf607e7b9a907dc6e3c2d1c7383e64e
|
data/README.md
CHANGED
@@ -1,194 +1,199 @@
|
|
1
|
-
# NeatJSON
|
2
|
-
|
3
|
-
[](http://badge.fury.io/rb/neatjson)
|
4
|
-
[](https://rubygems.org/gems/neatjson)
|
5
|
-
|
6
|
-
Pretty-print your JSON in Ruby with more power than is provided by `JSON.pretty_generate`. In particular, like Ruby's `pp` (pretty print), NeatJSON will keep objects on one line if they fit, but break them over multiple lines if needed.
|
7
|
-
|
8
|
-
Here's an excerpt (from a much larger JSON):
|
9
|
-
|
10
|
-
~~~ json
|
11
|
-
{
|
12
|
-
"navigation.createroute.poi":[
|
13
|
-
{"text":"Lay in a course to the Hilton","params":{"poi":"Hilton"}},
|
14
|
-
{"text":"Take me to the airport","params":{"poi":"airport"}},
|
15
|
-
{"text":"Let's go to IHOP","params":{"poi":"IHOP"}},
|
16
|
-
{"text":"Show me how to get to The Med","params":{"poi":"The Med"}},
|
17
|
-
{"text":"Create a route to Arby's","params":{"poi":"Arby's"}},
|
18
|
-
{
|
19
|
-
"text":"Go to the Hilton by the Airport",
|
20
|
-
"params":{"poi":"Hilton","location":"Airport"}
|
21
|
-
},
|
22
|
-
{
|
23
|
-
"text":"Take me to the Fry's in Fresno",
|
24
|
-
"params":{"poi":"Fry's","location":"Fresno"}
|
25
|
-
}
|
26
|
-
],
|
27
|
-
"navigation.eta":[
|
28
|
-
{"text":"When will we get there?"},
|
29
|
-
{"text":"When will I arrive?"},
|
30
|
-
{"text":"What time will I get to the destination?"},
|
31
|
-
{"text":"What time will I reach the destination?"},
|
32
|
-
{"text":"What time will it be when I arrive?"}
|
33
|
-
]
|
34
|
-
}
|
35
|
-
~~~
|
36
|
-
|
37
|
-
## Installation
|
38
|
-
|
39
|
-
`gem install neatjson`
|
40
|
-
|
41
|
-
## Examples
|
42
|
-
|
43
|
-
~~~ ruby
|
44
|
-
require 'neatjson'
|
45
|
-
|
46
|
-
o = { b:42.005, a:[42,17], longer:true, str:"yes
|
47
|
-
please" }
|
48
|
-
|
49
|
-
puts JSON.neat_generate(o)
|
50
|
-
#=> {"b":42.005,"a":[42,17],"longer":true,"str":"yes\nplease"}
|
51
|
-
|
52
|
-
puts JSON.neat_generate(o,sorted:true)
|
53
|
-
#=> {"a":[42,17],"b":42.005,"longer":true,"str":"yes\nplease"}
|
54
|
-
|
55
|
-
puts JSON.neat_generate(o,sorted:true,padding:1,after_comma:1)
|
56
|
-
#=> { "a":[ 42, 17 ], "b":42.005, "longer":true, "str":"yes\nplease" }
|
57
|
-
|
58
|
-
puts JSON.neat_generate(o,sorted:true,wrap:40)
|
59
|
-
#=> {
|
60
|
-
#=> "a":[42,17],
|
61
|
-
#=> "b":42.005,
|
62
|
-
#=> "longer":true,
|
63
|
-
#=> "str":"yes\nplease"
|
64
|
-
#=> }
|
65
|
-
|
66
|
-
puts JSON.neat_generate(o,sorted:true,wrap:40,decimals:2)
|
67
|
-
#=> {
|
68
|
-
#=> "a":[42,17],
|
69
|
-
#=> "b":42.01,
|
70
|
-
#=> "longer":true,
|
71
|
-
#=> "str":"yes\nplease"
|
72
|
-
#=> }
|
73
|
-
|
74
|
-
puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true)
|
75
|
-
#=> {
|
76
|
-
#=> "a" :[42,17],
|
77
|
-
#=> "b" :42.005,
|
78
|
-
#=> "longer":true,
|
79
|
-
#=> "str" :"yes\nplease"
|
80
|
-
#=> }
|
81
|
-
|
82
|
-
puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true,around_colon:1)
|
83
|
-
#=> {
|
84
|
-
#=> "a" : [42,17],
|
85
|
-
#=> "b" : 42.005,
|
86
|
-
#=> "longer" : true,
|
87
|
-
#=> "str" : "yes\nplease"
|
88
|
-
#=> }
|
89
|
-
|
90
|
-
puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true,around_colon:1,short:true)
|
91
|
-
#=> {"a" : [42,17],
|
92
|
-
#=> "b" : 42.005,
|
93
|
-
#=> "longer" : true,
|
94
|
-
#=> "str" : "yes\nplease"}
|
95
|
-
|
96
|
-
a = [1,2,[3,4,[5]]]
|
97
|
-
puts JSON.neat_generate(a)
|
98
|
-
#=> [1,2,[3,4,[5]]]
|
99
|
-
|
100
|
-
puts JSON.pretty_generate(a) # oof!
|
101
|
-
#=> [
|
102
|
-
#=> 1,
|
103
|
-
#=> 2,
|
104
|
-
#=> [
|
105
|
-
#=> 3,
|
106
|
-
#=> 4,
|
107
|
-
#=> [
|
108
|
-
#=> 5
|
109
|
-
#=> ]
|
110
|
-
#=> ]
|
111
|
-
#=> ]
|
112
|
-
|
113
|
-
puts JSON.neat_generate( a, wrap:true, short:true )
|
114
|
-
#=> [1,
|
115
|
-
#=> 2,
|
116
|
-
#=> [3,
|
117
|
-
#=> 4,
|
118
|
-
#=> [5]]]
|
119
|
-
~~~
|
120
|
-
|
121
|
-
## Options
|
122
|
-
You may pass any of the following option symbols to `neat_generate`:
|
123
|
-
|
124
|
-
* `:wrap` — The maximum line width before wrapping. Use `false` to never wrap, or `true` (or `-1`) to always wrap. Default: `80`
|
125
|
-
* `:indent` — Whitespace used to indent each level when wrapping. Default: `" "` (two spaces)
|
126
|
-
* `:
|
127
|
-
|
128
|
-
*
|
129
|
-
* `:
|
130
|
-
* `:
|
131
|
-
* `:
|
132
|
-
* `:
|
133
|
-
* `:
|
134
|
-
* `:
|
135
|
-
* `:
|
136
|
-
* `:
|
137
|
-
* `:
|
138
|
-
* `:
|
139
|
-
* `:
|
140
|
-
* `:
|
141
|
-
* `:
|
142
|
-
* `:
|
143
|
-
* `:
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
For
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
*
|
159
|
-
*
|
160
|
-
* Possibly allow
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
*
|
172
|
-
|
173
|
-
|
174
|
-
*
|
175
|
-
|
176
|
-
* **v0.
|
177
|
-
*
|
178
|
-
|
179
|
-
*
|
180
|
-
|
181
|
-
|
182
|
-
*
|
183
|
-
|
184
|
-
|
185
|
-
*
|
186
|
-
|
187
|
-
|
188
|
-
*
|
189
|
-
|
190
|
-
|
191
|
-
*
|
192
|
-
|
193
|
-
|
194
|
-
|
1
|
+
# NeatJSON
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/neatjson)
|
4
|
+
[](https://rubygems.org/gems/neatjson)
|
5
|
+
|
6
|
+
Pretty-print your JSON in Ruby with more power than is provided by `JSON.pretty_generate`. In particular, like Ruby's `pp` (pretty print), NeatJSON will keep objects on one line if they fit, but break them over multiple lines if needed.
|
7
|
+
|
8
|
+
Here's an excerpt (from a much larger JSON):
|
9
|
+
|
10
|
+
~~~ json
|
11
|
+
{
|
12
|
+
"navigation.createroute.poi":[
|
13
|
+
{"text":"Lay in a course to the Hilton","params":{"poi":"Hilton"}},
|
14
|
+
{"text":"Take me to the airport","params":{"poi":"airport"}},
|
15
|
+
{"text":"Let's go to IHOP","params":{"poi":"IHOP"}},
|
16
|
+
{"text":"Show me how to get to The Med","params":{"poi":"The Med"}},
|
17
|
+
{"text":"Create a route to Arby's","params":{"poi":"Arby's"}},
|
18
|
+
{
|
19
|
+
"text":"Go to the Hilton by the Airport",
|
20
|
+
"params":{"poi":"Hilton","location":"Airport"}
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"text":"Take me to the Fry's in Fresno",
|
24
|
+
"params":{"poi":"Fry's","location":"Fresno"}
|
25
|
+
}
|
26
|
+
],
|
27
|
+
"navigation.eta":[
|
28
|
+
{"text":"When will we get there?"},
|
29
|
+
{"text":"When will I arrive?"},
|
30
|
+
{"text":"What time will I get to the destination?"},
|
31
|
+
{"text":"What time will I reach the destination?"},
|
32
|
+
{"text":"What time will it be when I arrive?"}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
~~~
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
`gem install neatjson`
|
40
|
+
|
41
|
+
## Examples
|
42
|
+
|
43
|
+
~~~ ruby
|
44
|
+
require 'neatjson'
|
45
|
+
|
46
|
+
o = { b:42.005, a:[42,17], longer:true, str:"yes
|
47
|
+
please" }
|
48
|
+
|
49
|
+
puts JSON.neat_generate(o)
|
50
|
+
#=> {"b":42.005,"a":[42,17],"longer":true,"str":"yes\nplease"}
|
51
|
+
|
52
|
+
puts JSON.neat_generate(o,sorted:true)
|
53
|
+
#=> {"a":[42,17],"b":42.005,"longer":true,"str":"yes\nplease"}
|
54
|
+
|
55
|
+
puts JSON.neat_generate(o,sorted:true,padding:1,after_comma:1)
|
56
|
+
#=> { "a":[ 42, 17 ], "b":42.005, "longer":true, "str":"yes\nplease" }
|
57
|
+
|
58
|
+
puts JSON.neat_generate(o,sorted:true,wrap:40)
|
59
|
+
#=> {
|
60
|
+
#=> "a":[42,17],
|
61
|
+
#=> "b":42.005,
|
62
|
+
#=> "longer":true,
|
63
|
+
#=> "str":"yes\nplease"
|
64
|
+
#=> }
|
65
|
+
|
66
|
+
puts JSON.neat_generate(o,sorted:true,wrap:40,decimals:2)
|
67
|
+
#=> {
|
68
|
+
#=> "a":[42,17],
|
69
|
+
#=> "b":42.01,
|
70
|
+
#=> "longer":true,
|
71
|
+
#=> "str":"yes\nplease"
|
72
|
+
#=> }
|
73
|
+
|
74
|
+
puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true)
|
75
|
+
#=> {
|
76
|
+
#=> "a" :[42,17],
|
77
|
+
#=> "b" :42.005,
|
78
|
+
#=> "longer":true,
|
79
|
+
#=> "str" :"yes\nplease"
|
80
|
+
#=> }
|
81
|
+
|
82
|
+
puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true,around_colon:1)
|
83
|
+
#=> {
|
84
|
+
#=> "a" : [42,17],
|
85
|
+
#=> "b" : 42.005,
|
86
|
+
#=> "longer" : true,
|
87
|
+
#=> "str" : "yes\nplease"
|
88
|
+
#=> }
|
89
|
+
|
90
|
+
puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true,around_colon:1,short:true)
|
91
|
+
#=> {"a" : [42,17],
|
92
|
+
#=> "b" : 42.005,
|
93
|
+
#=> "longer" : true,
|
94
|
+
#=> "str" : "yes\nplease"}
|
95
|
+
|
96
|
+
a = [1,2,[3,4,[5]]]
|
97
|
+
puts JSON.neat_generate(a)
|
98
|
+
#=> [1,2,[3,4,[5]]]
|
99
|
+
|
100
|
+
puts JSON.pretty_generate(a) # oof!
|
101
|
+
#=> [
|
102
|
+
#=> 1,
|
103
|
+
#=> 2,
|
104
|
+
#=> [
|
105
|
+
#=> 3,
|
106
|
+
#=> 4,
|
107
|
+
#=> [
|
108
|
+
#=> 5
|
109
|
+
#=> ]
|
110
|
+
#=> ]
|
111
|
+
#=> ]
|
112
|
+
|
113
|
+
puts JSON.neat_generate( a, wrap:true, short:true )
|
114
|
+
#=> [1,
|
115
|
+
#=> 2,
|
116
|
+
#=> [3,
|
117
|
+
#=> 4,
|
118
|
+
#=> [5]]]
|
119
|
+
~~~
|
120
|
+
|
121
|
+
## Options
|
122
|
+
You may pass any of the following option symbols to `neat_generate`:
|
123
|
+
|
124
|
+
* `:wrap` — The maximum line width before wrapping. Use `false` to never wrap, or `true` (or `-1`) to always wrap. Default: `80`
|
125
|
+
* `:indent` — Whitespace used to indent each level when wrapping. Default: `" "` (two spaces)
|
126
|
+
* `:indent_last` — Indent the closing bracket/brace for arrays and objects? Default: `false`
|
127
|
+
* `:short` — Keep the output 'short' when wrapping? This puts opening brackets on the same line as the first value, and closing brackets on the same line as the last. Default: `false`
|
128
|
+
* _This causes the `:indent` and `:indent_last` options to be ignored, instead basing indentation on array and object padding._
|
129
|
+
* `:sorted` — Sort the keys for objects to be in alphabetical order? Default: `false`
|
130
|
+
* `:aligned` — When wrapping objects, line up the colons (per object)? Default: `false`
|
131
|
+
* `:decimals` — Decimal precision to use for non-integer numbers; use `false` to keep float values precise. Default: `false`
|
132
|
+
* `:array_padding` — Number of spaces to put inside brackets for arrays. Default: `0`
|
133
|
+
* `:object_padding` — Number of spaces to put inside braces for objects. Default: `0`
|
134
|
+
* `:padding` — Shorthand to set both `:array_padding` and `:object_padding`. Default: `0`
|
135
|
+
* `:before_comma` — Number of spaces to put before commas (for both arrays and objects). Default: `0`
|
136
|
+
* `:after_comma` — Number of spaces to put after commas (for both arrays and objects). Default: `0`
|
137
|
+
* `:around_comma` — Shorthand to set both `:before_comma` and `:after_comma`. Default: `0`
|
138
|
+
* `:before_colon_1` — Number of spaces before a colon when the object is on one line. Default: `0`
|
139
|
+
* `:after_colon_1` — Number of spaces after a colon when the object is on one line. Default: `0`
|
140
|
+
* `:before_colon_n` — Number of spaces before a colon when the object is on multiple lines. Default: `0`
|
141
|
+
* `:after_colon_n` — Number of spaces after a colon when the object is on multiple lines. Default: `0`
|
142
|
+
* `:before_colon` — Shorthand to set both `:before_colon_1` and `:before_colon_n`. Default: `0`
|
143
|
+
* `:after_colon` — Shorthand to set both `:after_colon_1` and `:after_colon_n`. Default: `0`
|
144
|
+
* `:around_colon` — Shorthand to set both `:before_colon` and `:after_colon`. Default: `0`
|
145
|
+
|
146
|
+
|
147
|
+
## License & Contact
|
148
|
+
|
149
|
+
NeatJSON is copyright ©2015 by Gavin Kistner and is released under
|
150
|
+
the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
151
|
+
See the LICENSE.txt file for more details.
|
152
|
+
|
153
|
+
For bugs or feature requests please open [issues on GitHub][1].
|
154
|
+
For other communication you can [email the author directly](mailto:!@phrogz.net?subject=NeatJSON).
|
155
|
+
|
156
|
+
## TODO (aka Known Limitations)
|
157
|
+
|
158
|
+
* Figure out the best way to play with custom objects that use `to_json` for their representation.
|
159
|
+
* Detect circular references.
|
160
|
+
* Possibly allow illegal JSON values like `NaN` or `Infinity`.
|
161
|
+
* Possibly allow "JSON5" output (legal identifiers unquoted, etc.)
|
162
|
+
|
163
|
+
## HISTORY
|
164
|
+
|
165
|
+
* **v0.6.2** - February 8th, 2016
|
166
|
+
* Use memoization to avoid performance stalls when wrapping deeply-nested objects/arrays.
|
167
|
+
_Thanks @chroche_
|
168
|
+
|
169
|
+
* **v0.6.1** - October 12th, 2015
|
170
|
+
* Fix handling of nested empty objects and arrays. (Would cause a runtime error in many cases.)
|
171
|
+
* _This change causes empty arrays in a tight wrapping scenario to appear on a single line where they would previously take up three lines._
|
172
|
+
|
173
|
+
* **v0.6** - April 26th, 2015
|
174
|
+
* Added `before_colon_1` and `before_colon_n` to distinguish between single-line and multi-line objects.
|
175
|
+
|
176
|
+
* **v0.5** - April 19th, 2015
|
177
|
+
* Do not format integers (or floats that equal their integer) using `decimals` option.
|
178
|
+
* Make `neatJSON()` JavaScript available to Node.js as well as web browsers.
|
179
|
+
* Add (Node-based) testing for the JavaScript version.
|
180
|
+
|
181
|
+
* **v0.4** - April 18th, 2015
|
182
|
+
* Add JavaScript version with online runner.
|
183
|
+
|
184
|
+
* **v0.3.2** - April 16th, 2015
|
185
|
+
* Force YARD to use Markdown for documentation.
|
186
|
+
|
187
|
+
* **v0.3.1** - April 16th, 2015
|
188
|
+
* Remove some debugging code accidentally left in.
|
189
|
+
|
190
|
+
* **v0.3** - April 16th, 2015
|
191
|
+
* Fix another bug with `short:true` and wrapping array values inside objects.
|
192
|
+
|
193
|
+
* **v0.2** - April 16th, 2015
|
194
|
+
* Fix bug with `short:true` and wrapping values inside objects.
|
195
|
+
|
196
|
+
* **v0.1** - April 15th, 2015
|
197
|
+
* Initial release.
|
198
|
+
|
199
|
+
[1]: https://github.com/Phrogz/NeatJSON/issues
|
data/lib/neatjson.rb
CHANGED
@@ -6,27 +6,28 @@ module JSON
|
|
6
6
|
# @author Gavin Kistner <!@phrogz.net>
|
7
7
|
# @param object [Object] the object to serialize
|
8
8
|
# @param opts [Hash] the formatting options
|
9
|
-
# @option opts [Integer] :wrap
|
10
|
-
# @option opts [String] :indent
|
11
|
-
# @option opts [Boolean] :
|
12
|
-
# @option opts [Boolean] :
|
13
|
-
# @option opts [Boolean] :
|
14
|
-
# @option opts [
|
15
|
-
# @option opts [Integer] :
|
16
|
-
# @option opts [Integer] :
|
17
|
-
# @option opts [Integer] :
|
18
|
-
# @option opts [Integer] :
|
19
|
-
# @option opts [Integer] :
|
20
|
-
# @option opts [Integer] :
|
21
|
-
# @option opts [Integer] :
|
22
|
-
# @option opts [Integer] :
|
23
|
-
# @option opts [Integer] :
|
24
|
-
# @option opts [Integer] :
|
25
|
-
# @option opts [Integer] :
|
26
|
-
# @option opts [Integer] :
|
27
|
-
# @option opts [Integer] :
|
28
|
-
# @option opts [Integer] :
|
29
|
-
# @option opts [Integer] :
|
9
|
+
# @option opts [Integer] :wrap (80) The maximum line width before wrapping. Use `false` to never wrap, or `true` to always wrap.
|
10
|
+
# @option opts [String] :indent (" ") Whitespace used to indent each level when wrapping (without the :short option).
|
11
|
+
# @option opts [Boolean] :indent_last (false) Indent the closing bracket for arrays and objects (without the :short option).
|
12
|
+
# @option opts [Boolean] :short (false) Keep the output 'short' when wrapping, putting opening brackets on the same line as the first value, and closing brackets on the same line as the last item.
|
13
|
+
# @option opts [Boolean] :sorted (false) Sort the keys for objects to be in alphabetical order.
|
14
|
+
# @option opts [Boolean] :aligned (false) When wrapping objects, align the colons (only per object).
|
15
|
+
# @option opts [Integer] :decimals (null) Decimal precision to use for floats; omit to keep numberic values precise.
|
16
|
+
# @option opts [Integer] :padding (0) Number of spaces to put inside brackets/braces for both arrays and objects.
|
17
|
+
# @option opts [Integer] :array_padding (0) Number of spaces to put inside brackets for arrays. Overrides `:padding`.
|
18
|
+
# @option opts [Integer] :object_padding (0) Number of spaces to put inside braces for objects. Overrides `:padding`.
|
19
|
+
# @option opts [Integer] :around_comma (0) Number of spaces to put before/after commas (for both arrays and objects).
|
20
|
+
# @option opts [Integer] :before_comma (0) Number of spaces to put before commas (for both arrays and objects).
|
21
|
+
# @option opts [Integer] :after_comma (0) Number of spaces to put after commas (for both arrays and objects).
|
22
|
+
# @option opts [Integer] :around_colon (0) Number of spaces to put before/after colons (for objects).
|
23
|
+
# @option opts [Integer] :before_colon (0) Number of spaces to put before colons (for objects).
|
24
|
+
# @option opts [Integer] :after_colon (0) Number of spaces to put after colons (for objects).
|
25
|
+
# @option opts [Integer] :around_colon_1 (0) Number of spaces to put before/after colons for single-line objects.
|
26
|
+
# @option opts [Integer] :before_colon_1 (0) Number of spaces to put before colons for single-line objects.
|
27
|
+
# @option opts [Integer] :after_colon_1 (0) Number of spaces to put after colons for single-line objects.
|
28
|
+
# @option opts [Integer] :around_colon_n (0) Number of spaces to put before/after colons for multi-line objects.
|
29
|
+
# @option opts [Integer] :before_colon_n (0) Number of spaces to put before colons for multi-line objects.
|
30
|
+
# @option opts [Integer] :after_colon_n (0) Number of spaces to put after colons for multi-line objects.
|
30
31
|
# @return [String] the JSON representation of the object.
|
31
32
|
def self.neat_generate(object,opts={})
|
32
33
|
opts[:wrap] = 80 unless opts.key?(:wrap)
|
@@ -80,7 +81,7 @@ module JSON
|
|
80
81
|
pieces.join ",\n"
|
81
82
|
else
|
82
83
|
indent2 = "#{indent}#{opts[:indent]}"
|
83
|
-
"#{indent}[\n#{o.map{ |v| build[ v, indent2 ] }.join ",\n"}\n#{indent}]"
|
84
|
+
"#{indent}[\n#{o.map{ |v| build[ v, indent2 ] }.join ",\n"}\n#{opts[:indent_last] ? indent2 : indent}]"
|
84
85
|
end
|
85
86
|
|
86
87
|
when Hash
|
@@ -126,7 +127,7 @@ module JSON
|
|
126
127
|
one_line
|
127
128
|
end
|
128
129
|
end
|
129
|
-
"#{indent}{\n#{keyvals.join(",\n")}\n#{indent}}"
|
130
|
+
"#{indent}{\n#{keyvals.join(",\n")}\n#{opts[:indent_last] ? indent2 : indent}}"
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|