sinatra-jsonp 0.2.1 → 0.3
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.md +9 -5
- data/lib/sinatra/jsonp.rb +2 -2
- data/spec/jsonp_spec.rb +36 -0
- data/spec/spec_helper.rb +9 -0
- metadata +28 -18
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Sinatra::Jsonp
|
2
|
-
|
1
|
+
Sinatra::Jsonp 
|
2
|
+
==============
|
3
3
|
|
4
4
|
JSONP output helper for [Sinatra](http://sinatrarb.com). Automatically detects callback params and returns proper JSONP output.
|
5
5
|
If no callback params where detected it returns plain JSON.
|
@@ -9,13 +9,16 @@ Works with [jQuery](http://jquery.com) [jQuery.getJSON](http://api.jquery.com/jQ
|
|
9
9
|
Installation
|
10
10
|
------------
|
11
11
|
|
12
|
-
|
12
|
+
```bash
|
13
|
+
gem install sinatra-jsonp
|
14
|
+
```
|
13
15
|
|
14
16
|
Usage
|
15
17
|
-----
|
16
18
|
|
17
19
|
Classic:
|
18
20
|
|
21
|
+
```ruby
|
19
22
|
require "sinatra"
|
20
23
|
require "sinatra/jsonp"
|
21
24
|
|
@@ -35,9 +38,10 @@ Classic:
|
|
35
38
|
data = ["hello","hi","hallo"]
|
36
39
|
jsonp data, :functionB
|
37
40
|
end
|
38
|
-
|
41
|
+
```
|
39
42
|
Modular:
|
40
43
|
|
44
|
+
```ruby
|
41
45
|
require "sinatra/base"
|
42
46
|
require "sinatra/jsonp"
|
43
47
|
|
@@ -49,7 +53,7 @@ Modular:
|
|
49
53
|
jsonp data
|
50
54
|
end
|
51
55
|
end
|
52
|
-
|
56
|
+
```
|
53
57
|
|
54
58
|
Links
|
55
59
|
-----
|
data/lib/sinatra/jsonp.rb
CHANGED
@@ -3,14 +3,14 @@ require 'json'
|
|
3
3
|
|
4
4
|
module Sinatra
|
5
5
|
module Jsonp
|
6
|
-
def jsonp(*args)
|
6
|
+
def jsonp(*args)
|
7
7
|
if args.size > 0
|
8
8
|
data = args[0].to_json
|
9
9
|
if args.size > 1
|
10
10
|
callback = args[1].to_s
|
11
11
|
else
|
12
12
|
['callback','jscallback','jsonp','jsoncallback'].each do |x|
|
13
|
-
callback = params.delete(x)
|
13
|
+
callback = params.delete(x) unless callback
|
14
14
|
end
|
15
15
|
end
|
16
16
|
if callback
|
data/spec/jsonp_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require 'sinatra/jsonp'
|
3
|
+
|
4
|
+
describe Sinatra::Jsonp do
|
5
|
+
before do
|
6
|
+
mock_app do
|
7
|
+
helpers Sinatra::Jsonp
|
8
|
+
|
9
|
+
get '/method' do
|
10
|
+
data = ["hello","hi","hallo"]
|
11
|
+
jsonp data
|
12
|
+
end
|
13
|
+
get '/method_with_params' do
|
14
|
+
data = ["hello","hi","hallo"]
|
15
|
+
jsonp data, :functionA
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return JSON if no callback passed" do
|
21
|
+
get '/method'
|
22
|
+
body.should == '["hello","hi","hallo"]'
|
23
|
+
end
|
24
|
+
it "should return JSONP if callback passed via GET param" do
|
25
|
+
get '/method?callback=functionA'
|
26
|
+
body.should == 'functionA(["hello","hi","hallo"])'
|
27
|
+
end
|
28
|
+
it "should return JSONP if callback passed via method param" do
|
29
|
+
get '/method_with_params'
|
30
|
+
body.should == 'functionA(["hello","hi","hallo"])'
|
31
|
+
end
|
32
|
+
it "should return JSONP with callback passed via method params even if it passed via GET param" do
|
33
|
+
get '/method_with_params?callback=functionB'
|
34
|
+
body.should == 'functionA(["hello","hi","hallo"])'
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-jsonp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 1
|
9
|
-
version: 0.2.1
|
4
|
+
prerelease:
|
5
|
+
version: "0.3"
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Serg Podtynnyi
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-04-25 00:00:00 +04:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,9 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ~>
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 1
|
30
|
-
- 0
|
31
24
|
version: "1.0"
|
32
25
|
type: :runtime
|
33
26
|
version_requirements: *id001
|
@@ -39,12 +32,31 @@ dependencies:
|
|
39
32
|
requirements:
|
40
33
|
- - ~>
|
41
34
|
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 1
|
44
|
-
- 4
|
45
35
|
version: "1.4"
|
46
36
|
type: :runtime
|
47
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "2.3"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
48
60
|
description: JSONP output helper for Sinatra
|
49
61
|
email: serg.podtynnyi@gmail.com
|
50
62
|
executables: []
|
@@ -54,6 +66,8 @@ extensions: []
|
|
54
66
|
extra_rdoc_files: []
|
55
67
|
|
56
68
|
files:
|
69
|
+
- spec/jsonp_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
57
71
|
- lib/sinatra/jsonp.rb
|
58
72
|
- README.md
|
59
73
|
has_rdoc: true
|
@@ -70,21 +84,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
84
|
requirements:
|
71
85
|
- - ">="
|
72
86
|
- !ruby/object:Gem::Version
|
73
|
-
segments:
|
74
|
-
- 0
|
75
87
|
version: "0"
|
76
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
89
|
none: false
|
78
90
|
requirements:
|
79
91
|
- - ">="
|
80
92
|
- !ruby/object:Gem::Version
|
81
|
-
segments:
|
82
|
-
- 0
|
83
93
|
version: "0"
|
84
94
|
requirements: []
|
85
95
|
|
86
96
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.
|
97
|
+
rubygems_version: 1.6.2
|
88
98
|
signing_key:
|
89
99
|
specification_version: 3
|
90
100
|
summary: JSONP output helper for Sinatra
|