ballast 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc5799f1e29dc591080f335e942871ad0941546d
4
- data.tar.gz: 1fa78408a9ab5e5de07394b508803bf21c3b98cf
3
+ metadata.gz: 781cd7e0e76f7375d3b5a8c4924f9af9682507c6
4
+ data.tar.gz: 5d08c7cc2a140f78dff529e7ec50791fdec242bc
5
5
  SHA512:
6
- metadata.gz: 736d23b13df218cba6cb2b93b88018d7e73b8c29c203c62e556a03efec18f6176a9eef07efd2994244a01d64f9a5f68c7f6af499ea7191b1952347b78071529d
7
- data.tar.gz: dbc51a1733cfcffbf0586e7f7f21ddb6e0488b52a4419c0a2a9ecab5571db78d8cc14f287c47a3cbbbf78e8cc3c908d518ac70414931cbf585a29fbc0e6db555
6
+ metadata.gz: a1d5be67c3c4797333311ef25b57739973ff43e706a37564abbb2849065fc138e6df92f1b34ac2cff86911e477434c2414efb344c53d0a87e136e9fb5bafe644
7
+ data.tar.gz: b520d0dd2a52ef6f0145725894eb4af06b4939e57d672c4827e1c3019e05bba09b46ad6d29f74868af9bc2b4f1346d6d3dc51fcfecddc0bf27ae1a16aa71099a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 1.5.2 / 2014-01-04
2
+
3
+ * Improved pretty JSON handling.
4
+
1
5
  ### 1.5.1 / 2014-01-04
2
6
 
3
7
  * Fixed is_json? detection.
data/ballast.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
26
26
 
27
27
  gem.add_dependency("actionpack", "~> 4.0.0")
28
28
  gem.add_dependency("rack", "~> 1.5.2")
29
+ gem.add_dependency("oj", "~> 2.5.3")
29
30
  gem.add_dependency("lazier", "~> 3.3.10")
30
31
  gem.add_dependency("brauser", "~> 3.2.4")
31
32
  gem.add_dependency("interactor", "~> 2.1.0")
@@ -231,7 +231,7 @@
231
231
  <li class="public ">
232
232
  <span class="summary_signature">
233
233
 
234
- <a href="#send_ajax-instance_method" title="#send_ajax (instance method)">- (Object) <strong>send_ajax</strong>(data, status: :ok, format: :json) </a>
234
+ <a href="#send_ajax-instance_method" title="#send_ajax (instance method)">- (Object) <strong>send_ajax</strong>(data, status: :ok, format: :json, pretty_json: false) </a>
235
235
 
236
236
 
237
237
 
@@ -309,17 +309,17 @@
309
309
  <pre class="lines">
310
310
 
311
311
 
312
- 75
313
312
  76
314
313
  77
315
314
  78
316
315
  79
317
316
  80
318
317
  81
319
- 82</pre>
318
+ 82
319
+ 83</pre>
320
320
  </td>
321
321
  <td>
322
- <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 75</span>
322
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 76</span>
323
323
 
324
324
  <span class='kw'>def</span> <span class='id identifier rubyid_allow_cors'>allow_cors</span>
325
325
  <span class='id identifier rubyid_headers'>headers</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span><span class='lparen'>(</span><span class='lbrace'>{</span>
@@ -359,12 +359,12 @@
359
359
  <pre class="lines">
360
360
 
361
361
 
362
- 85
363
362
  86
364
- 87</pre>
363
+ 87
364
+ 88</pre>
365
365
  </td>
366
366
  <td>
367
- <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 85</span>
367
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 86</span>
368
368
 
369
369
  <span class='kw'>def</span> <span class='id identifier rubyid_disallow_robots'>disallow_robots</span>
370
370
  <span class='id identifier rubyid_render'>render</span><span class='lparen'>(</span><span class='label'>text:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>User-agent: *\nDisallow: /</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='label'>content_type:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>text/plain</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
@@ -557,16 +557,16 @@
557
557
  <pre class="lines">
558
558
 
559
559
 
560
- 66
561
560
  67
562
561
  68
563
562
  69
564
563
  70
565
564
  71
566
- 72</pre>
565
+ 72
566
+ 73</pre>
567
567
  </td>
568
568
  <td>
569
- <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 66</span>
569
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 67</span>
570
570
 
571
571
  <span class='kw'>def</span> <span class='id identifier rubyid_prevent_caching'>prevent_caching</span>
572
572
  <span class='id identifier rubyid_response'>response</span><span class='period'>.</span><span class='id identifier rubyid_headers'>headers</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span><span class='lparen'>(</span><span class='lbrace'>{</span>
@@ -583,7 +583,7 @@
583
583
  <div class="method_details ">
584
584
  <h3 class="signature " id="send_ajax-instance_method">
585
585
 
586
- - (<tt>Object</tt>) <strong>send_ajax</strong>(data, status: :ok, format: :json)
586
+ - (<tt>Object</tt>) <strong>send_ajax</strong>(data, status: :ok, format: :json, pretty_json: false)
587
587
 
588
588
 
589
589
 
@@ -645,6 +645,21 @@
645
645
 
646
646
  </li>
647
647
 
648
+ <li>
649
+
650
+ <span class='name'>pretty_json</span>
651
+
652
+
653
+ <span class='type'>(<tt>Boolean</tt>)</span>
654
+
655
+
656
+
657
+ &mdash;
658
+ <div class='inline'><p>If JSON response must be pretty formatted.</p>
659
+ </div>
660
+
661
+ </li>
662
+
648
663
  </ul>
649
664
 
650
665
 
@@ -654,7 +669,6 @@
654
669
  <pre class="lines">
655
670
 
656
671
 
657
- 37
658
672
  38
659
673
  39
660
674
  40
@@ -669,12 +683,13 @@
669
683
  49
670
684
  50
671
685
  51
672
- 52</pre>
686
+ 52
687
+ 53</pre>
673
688
  </td>
674
689
  <td>
675
- <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 37</span>
690
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 38</span>
676
691
 
677
- <span class='kw'>def</span> <span class='id identifier rubyid_send_ajax'>send_ajax</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='label'>status:</span> <span class='symbol'>:ok</span><span class='comma'>,</span> <span class='label'>format:</span> <span class='symbol'>:json</span><span class='rparen'>)</span>
692
+ <span class='kw'>def</span> <span class='id identifier rubyid_send_ajax'>send_ajax</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='label'>status:</span> <span class='symbol'>:ok</span><span class='comma'>,</span> <span class='label'>format:</span> <span class='symbol'>:json</span><span class='comma'>,</span> <span class='label'>pretty_json:</span> <span class='kw'>false</span><span class='rparen'>)</span>
678
693
  <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_performed?'>performed?</span> <span class='kw'>then</span>
679
694
  <span class='comment'># Prepare data
680
695
  </span> <span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_prepare_ajax_send'>prepare_ajax_send</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='id identifier rubyid_status'>status</span><span class='rparen'>)</span>
@@ -683,8 +698,8 @@
683
698
  </span> <span class='id identifier rubyid_format'>format</span><span class='comma'>,</span> <span class='id identifier rubyid_callback'>callback</span><span class='comma'>,</span> <span class='id identifier rubyid_content_type'>content_type</span> <span class='op'>=</span> <span class='id identifier rubyid_format_ajax_send'>format_ajax_send</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span>
684
699
  <span class='id identifier rubyid_status'>status</span> <span class='op'>=</span> <span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:status</span><span class='rbracket'>]</span>
685
700
 
686
- <span class='comment'># Prepare data for formatting
687
- </span> <span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='lbracket'>[</span><span class='symbol'>:json</span><span class='comma'>,</span> <span class='symbol'>:jsonp</span><span class='comma'>,</span> <span class='symbol'>:pretty_json</span><span class='comma'>,</span> <span class='symbol'>:pretty_jsonp</span><span class='comma'>,</span> <span class='symbol'>:text</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span>
701
+ <span class='comment'># Adjust data
702
+ </span> <span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='id identifier rubyid_pretty_json'>pretty_json</span> <span class='op'>?</span> <span class='const'>Oj</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='lbracket'>[</span><span class='symbol'>:json</span><span class='comma'>,</span> <span class='symbol'>:jsonp</span><span class='comma'>,</span> <span class='symbol'>:text</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span>
688
703
 
689
704
  <span class='comment'># Render
690
705
  </span> <span class='id identifier rubyid_render'>render</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='label'>status:</span> <span class='id identifier rubyid_status'>status</span><span class='comma'>,</span> <span class='label'>callback:</span> <span class='id identifier rubyid_callback'>callback</span><span class='comma'>,</span> <span class='label'>content_type:</span> <span class='id identifier rubyid_content_type'>content_type</span><span class='rparen'>)</span>
@@ -773,14 +788,14 @@
773
788
  <pre class="lines">
774
789
 
775
790
 
776
- 59
777
791
  60
778
792
  61
779
793
  62
780
- 63</pre>
794
+ 63
795
+ 64</pre>
781
796
  </td>
782
797
  <td>
783
- <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 59</span>
798
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/ajax.rb', line 60</span>
784
799
 
785
800
  <span class='kw'>def</span> <span class='id identifier rubyid_update_ajax'>update_ajax</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='id identifier rubyid_operation'>operation</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
786
801
  <span class='id identifier rubyid_operation'>operation</span> <span class='op'>||=</span> <span class='ivar'>@operation</span>
@@ -797,7 +812,7 @@
797
812
  </div>
798
813
 
799
814
  <div id="footer">
800
- Generated on Sat Jan 4 10:31:57 2014 by
815
+ Generated on Sat Jan 4 11:33:08 2014 by
801
816
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
802
817
  0.8.7.3 (ruby-2.1.0).
803
818
  </div>
@@ -967,7 +967,7 @@ and <code>%:Z</code> for the zone name considering also DST.</p>
967
967
  </div>
968
968
 
969
969
  <div id="footer">
970
- Generated on Sat Jan 4 10:31:57 2014 by
970
+ Generated on Sat Jan 4 11:33:08 2014 by
971
971
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
972
972
  0.8.7.3 (ruby-2.1.0).
973
973
  </div>
@@ -291,7 +291,7 @@
291
291
  </div>
292
292
 
293
293
  <div id="footer">
294
- Generated on Sat Jan 4 10:31:57 2014 by
294
+ Generated on Sat Jan 4 11:33:08 2014 by
295
295
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
296
296
  0.8.7.3 (ruby-2.1.0).
297
297
  </div>
@@ -638,7 +638,7 @@
638
638
  </div>
639
639
 
640
640
  <div id="footer">
641
- Generated on Sat Jan 4 10:31:57 2014 by
641
+ Generated on Sat Jan 4 11:33:08 2014 by
642
642
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
643
643
  0.8.7.3 (ruby-2.1.0).
644
644
  </div>
@@ -118,7 +118,7 @@
118
118
  </div>
119
119
 
120
120
  <div id="footer">
121
- Generated on Sat Jan 4 10:31:57 2014 by
121
+ Generated on Sat Jan 4 11:33:08 2014 by
122
122
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
123
123
  0.8.7.3 (ruby-2.1.0).
124
124
  </div>
@@ -273,7 +273,7 @@ Subfolders are not supported.</p>
273
273
  </div>
274
274
 
275
275
  <div id="footer">
276
- Generated on Sat Jan 4 10:31:58 2014 by
276
+ Generated on Sat Jan 4 11:33:09 2014 by
277
277
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
278
278
  0.8.7.3 (ruby-2.1.0).
279
279
  </div>
@@ -408,7 +408,7 @@
408
408
  </div>
409
409
 
410
410
  <div id="footer">
411
- Generated on Sat Jan 4 10:31:57 2014 by
411
+ Generated on Sat Jan 4 11:33:09 2014 by
412
412
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
413
413
  0.8.7.3 (ruby-2.1.0).
414
414
  </div>
@@ -317,7 +317,7 @@
317
317
  </div>
318
318
 
319
319
  <div id="footer">
320
- Generated on Sat Jan 4 10:31:57 2014 by
320
+ Generated on Sat Jan 4 11:33:08 2014 by
321
321
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
322
322
  0.8.7.3 (ruby-2.1.0).
323
323
  </div>
@@ -148,7 +148,7 @@
148
148
  </div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Sat Jan 4 10:31:57 2014 by
151
+ Generated on Sat Jan 4 11:33:09 2014 by
152
152
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.8.7.3 (ruby-2.1.0).
154
154
  </div>
@@ -148,7 +148,7 @@
148
148
  </div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Sat Jan 4 10:31:57 2014 by
151
+ Generated on Sat Jan 4 11:33:09 2014 by
152
152
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.8.7.3 (ruby-2.1.0).
154
154
  </div>
@@ -148,7 +148,7 @@
148
148
  </div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Sat Jan 4 10:31:57 2014 by
151
+ Generated on Sat Jan 4 11:33:09 2014 by
152
152
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.8.7.3 (ruby-2.1.0).
154
154
  </div>
@@ -116,7 +116,7 @@
116
116
  </div>
117
117
 
118
118
  <div id="footer">
119
- Generated on Sat Jan 4 10:31:57 2014 by
119
+ Generated on Sat Jan 4 11:33:08 2014 by
120
120
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
121
  0.8.7.3 (ruby-2.1.0).
122
122
  </div>
@@ -345,7 +345,7 @@
345
345
  </div>
346
346
 
347
347
  <div id="footer">
348
- Generated on Sat Jan 4 10:31:58 2014 by
348
+ Generated on Sat Jan 4 11:33:09 2014 by
349
349
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
350
350
  0.8.7.3 (ruby-2.1.0).
351
351
  </div>
@@ -116,7 +116,7 @@
116
116
  </div>
117
117
 
118
118
  <div id="footer">
119
- Generated on Sat Jan 4 10:31:57 2014 by
119
+ Generated on Sat Jan 4 11:33:08 2014 by
120
120
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
121
  0.8.7.3 (ruby-2.1.0).
122
122
  </div>
@@ -1295,7 +1295,7 @@ as owner will be created.</p>
1295
1295
  </div>
1296
1296
 
1297
1297
  <div id="footer">
1298
- Generated on Sat Jan 4 10:31:58 2014 by
1298
+ Generated on Sat Jan 4 11:33:09 2014 by
1299
1299
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1300
1300
  0.8.7.3 (ruby-2.1.0).
1301
1301
  </div>
@@ -576,7 +576,7 @@ as owner will be created.</p>
576
576
  </div>
577
577
 
578
578
  <div id="footer">
579
- Generated on Sat Jan 4 10:31:58 2014 by
579
+ Generated on Sat Jan 4 11:33:09 2014 by
580
580
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
581
581
  0.8.7.3 (ruby-2.1.0).
582
582
  </div>
@@ -908,7 +908,7 @@
908
908
  </div>
909
909
 
910
910
  <div id="footer">
911
- Generated on Sat Jan 4 10:31:58 2014 by
911
+ Generated on Sat Jan 4 11:33:09 2014 by
912
912
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
913
913
  0.8.7.3 (ruby-2.1.0).
914
914
  </div>
@@ -149,7 +149,7 @@
149
149
 
150
150
  </div>
151
151
  </dt>
152
- <dd><pre class="code"><span class='int'>1</span></pre></dd>
152
+ <dd><pre class="code"><span class='int'>2</span></pre></dd>
153
153
 
154
154
  <dt id="STRING-constant" class="">STRING =
155
155
  <div class="docstring">
@@ -180,7 +180,7 @@
180
180
  </div>
181
181
 
182
182
  <div id="footer">
183
- Generated on Sat Jan 4 10:31:57 2014 by
183
+ Generated on Sat Jan 4 11:33:08 2014 by
184
184
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
185
185
  0.8.7.3 (ruby-2.1.0).
186
186
  </div>
data/doc/Ballast.html CHANGED
@@ -121,7 +121,7 @@ Licensed under the MIT license, which can be found at http://www.opensource.org/
121
121
  </div>
122
122
 
123
123
  <div id="footer">
124
- Generated on Sat Jan 4 10:31:57 2014 by
124
+ Generated on Sat Jan 4 11:33:08 2014 by
125
125
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
126
126
  0.8.7.3 (ruby-2.1.0).
127
127
  </div>
data/doc/_index.html CHANGED
@@ -310,7 +310,7 @@
310
310
  </div>
311
311
 
312
312
  <div id="footer">
313
- Generated on Sat Jan 4 10:31:57 2014 by
313
+ Generated on Sat Jan 4 11:33:08 2014 by
314
314
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
315
315
  0.8.7.3 (ruby-2.1.0).
316
316
  </div>
data/doc/file.README.html CHANGED
@@ -106,7 +106,7 @@
106
106
  </div></div>
107
107
 
108
108
  <div id="footer">
109
- Generated on Sat Jan 4 10:31:57 2014 by
109
+ Generated on Sat Jan 4 11:33:08 2014 by
110
110
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
111
111
  0.8.7.3 (ruby-2.1.0).
112
112
  </div>
data/doc/index.html CHANGED
@@ -106,7 +106,7 @@
106
106
  </div></div>
107
107
 
108
108
  <div id="footer">
109
- Generated on Sat Jan 4 10:31:57 2014 by
109
+ Generated on Sat Jan 4 11:33:08 2014 by
110
110
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
111
111
  0.8.7.3 (ruby-2.1.0).
112
112
  </div>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Sat Jan 4 10:31:57 2014 by
106
+ Generated on Sat Jan 4 11:33:08 2014 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.7.3 (ruby-2.1.0).
109
109
  </div>
@@ -34,7 +34,8 @@ module Ballast
34
34
  # @param data [Hash] The response to send.
35
35
  # @param status [Symbol|Fixnum] The HTTP status of the response, *ignored if already set in data*.
36
36
  # @param format [Symbol] The content type of the response.
37
- def send_ajax(data, status: :ok, format: :json)
37
+ # @param pretty_json [Boolean] If JSON response must be pretty formatted.
38
+ def send_ajax(data, status: :ok, format: :json, pretty_json: false)
38
39
  if !performed? then
39
40
  # Prepare data
40
41
  data = prepare_ajax_send(data, status)
@@ -43,8 +44,8 @@ module Ballast
43
44
  format, callback, content_type = format_ajax_send(format)
44
45
  status = data[:status]
45
46
 
46
- # Prepare data for formatting
47
- data = ActiveSupport::JSON.encode(data) if [:json, :jsonp, :pretty_json, :pretty_jsonp, :text].include?(format)
47
+ # Adjust data
48
+ data = (pretty_json ? Oj.dump(data) : ActiveSupport::JSON.encode(data)) if [:json, :jsonp, :text].include?(format)
48
49
 
49
50
  # Render
50
51
  render(format => data, status: status, callback: callback, content_type: content_type)
@@ -104,9 +105,8 @@ module Ballast
104
105
  # @param format [Symbol] The format of the data.
105
106
  # @return [Array] An array of format, callback and content_type.
106
107
  def format_ajax_send(format)
107
- format ||= params[:format] || request.format || "json"
108
- format = format.to_sym
109
- callback = format == :jsonp ? (params[:callback] || "jsonp#{Time.now.to_i}") : nil
108
+ format = (format || params[:format] || request.format || "json").to_sym
109
+ callback = [:jsonp, :pretty_jsonp].include?(format) ? (params[:callback] || "jsonp#{Time.now.to_i}") : nil
110
110
  content_type = (format == :text) ? "text/plain" : nil
111
111
 
112
112
  [format, callback, content_type]
@@ -16,7 +16,7 @@ module Ballast
16
16
  MINOR = 5
17
17
 
18
18
  # The patch version.
19
- PATCH = 1
19
+ PATCH = 2
20
20
 
21
21
  # The current version of ballast.
22
22
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
data/lib/ballast.rb CHANGED
@@ -10,8 +10,10 @@ require "addressable/uri"
10
10
  require "rack/utils"
11
11
  require "rack/fiber_pool"
12
12
  require "em-synchrony"
13
+ require "oj"
13
14
 
14
15
  Lazier.load!
16
+ Oj.default_options = Oj.default_options.merge(mode: :compat, indent: 2, symbol_keys: true)
15
17
 
16
18
  require "ballast/version" if !defined?(Ballast::Version)
17
19
  require "ballast/errors"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shogun
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.5.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: oj
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.5.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.5.3
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: lazier
43
57
  requirement: !ruby/object:Gem::Requirement