sinatra-jsonp 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,13 +1,12 @@
1
- Sinatra::Jsonp [![Build Status](https://travis-ci.org/shtirlic/sinatra-jsonp.png)](https://travis-ci.org/shtirlic/sinatra-jsonp)
2
- ==============
1
+ # Sinatra::Jsonp [![Build Status](https://travis-ci.org/shtirlic/sinatra-jsonp.png)](https://travis-ci.org/shtirlic/sinatra-jsonp)
3
2
 
4
3
  JSONP output helper for [Sinatra](http://sinatrarb.com). Automatically detects callback params and returns proper JSONP output.
5
4
  If no callback params where detected it returns plain JSON.
6
5
  Works with [jQuery](http://jquery.com) [jQuery.getJSON](http://api.jquery.com/jQuery.getJSON/) method out of the box.
7
6
 
8
7
 
9
- Installation
10
- ------------
8
+ ## Installation
9
+
11
10
 
12
11
  System install
13
12
 
@@ -18,11 +17,11 @@ gem install sinatra-jsonp
18
17
  Gemfile
19
18
 
20
19
  ```ruby
21
- gem 'sinatra-jsonp', :require => 'sinatra/jsonp'
20
+ gem 'sinatra-jsonp'
22
21
  ```
23
22
 
24
- Usage
25
- -----
23
+ ## Usage
24
+
26
25
 
27
26
  Classic:
28
27
 
@@ -56,6 +55,9 @@ require "sinatra/jsonp"
56
55
  class Foo < Sinatra::Base
57
56
  helpers Sinatra::Jsonp
58
57
 
58
+ # Enable JSON pretty output
59
+ #enable :json_pretty
60
+
59
61
  get '/' do
60
62
  data = ["hello","hi","hallo"]
61
63
  jsonp data
@@ -63,14 +65,14 @@ class Foo < Sinatra::Base
63
65
  end
64
66
  ```
65
67
 
66
- Links
67
- -----
68
+ ## Links
69
+
68
70
 
69
71
  * [jQuery](http://jquery.com)
70
72
  * [Sinatra](http://www.sinatrarb.com)
71
73
 
72
74
 
73
- License
74
- -------
75
+ ## License
76
+
75
77
 
76
78
  See LICENSE for details.
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rspec/core/rake_task'
2
3
 
3
4
  RSpec::Core::RakeTask.new(:spec)
data/lib/sinatra/jsonp.rb CHANGED
@@ -5,7 +5,7 @@ module Sinatra
5
5
  module Jsonp
6
6
  def jsonp(*args)
7
7
  if args.size > 0
8
- data = MultiJson.dump args[0]
8
+ data = MultiJson.dump args[0], :pretty => settings.respond_to?(:json_pretty) && settings.json_pretty
9
9
  if args.size > 1
10
10
  callback = args[1].to_s
11
11
  else
data/spec/jsonp_spec.rb CHANGED
@@ -39,4 +39,17 @@ describe Sinatra::Jsonp do
39
39
  get '/method_with_params?callback=functionB'
40
40
  body.should == 'functionA(["hello","hi","hallo"])'
41
41
  end
42
+
43
+ it "return pretty JSON if :json_pretty enabled" do
44
+ mock_app do
45
+ helpers Sinatra::Jsonp
46
+ enable :json_pretty
47
+ get '/method' do
48
+ data = ["hello","hi","hallo"]
49
+ jsonp data
50
+ end
51
+ end
52
+ get '/method'
53
+ body.should == "[\n \"hello\",\n \"hi\",\n \"hallo\"\n]"
54
+ end
42
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-jsonp
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -115,12 +115,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -3994309697278529484
118
121
  required_rubygems_version: !ruby/object:Gem::Requirement
119
122
  none: false
120
123
  requirements:
121
124
  - - ! '>='
122
125
  - !ruby/object:Gem::Version
123
126
  version: '0'
127
+ segments:
128
+ - 0
129
+ hash: -3994309697278529484
124
130
  requirements: []
125
131
  rubyforge_project:
126
132
  rubygems_version: 1.8.24
@@ -128,4 +134,3 @@ signing_key:
128
134
  specification_version: 3
129
135
  summary: JSONP output helper for Sinatra
130
136
  test_files: []
131
- has_rdoc: