apidoc 0.1.0

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.
@@ -0,0 +1,211 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'sinatra/base'
3
+
4
+ describe ApiDoc do
5
+ before do
6
+ class TestApp < Sinatra::Base
7
+ get '/tacos.json' do
8
+ JSON.generate [ { meat: 'beef' }, { meat: 'chicken' } ]
9
+ end
10
+
11
+ post '/tacos.json' do
12
+ request.body
13
+ end
14
+ end
15
+
16
+ @doc = ApiDoc.new(TestApp) do
17
+ get '/tacos.json' do
18
+ desc "Get all tacos"
19
+ end
20
+ end
21
+ end
22
+
23
+ subject { @doc }
24
+
25
+ it "should have one resource" do
26
+ subject.resources.length.should == 1
27
+ end
28
+
29
+ describe "the /tacos.json resource" do
30
+ before do
31
+ @doc.run
32
+ end
33
+
34
+ subject { @doc.resources.first }
35
+ its(:method) { should == 'GET' }
36
+ its(:path) { should == '/tacos.json' }
37
+ its(:response_body) { should == JSON.generate([ { meat: 'beef' }, { meat: 'chicken' } ]) }
38
+ end
39
+
40
+ describe "when writing to HTML" do
41
+ subject do
42
+ stream = StringIO.new
43
+ ApiDoc::HtmlWriter.new(@doc).write(stream)
44
+ stream.read
45
+ end
46
+
47
+ it "should write the request method" do
48
+ subject.should include('GET')
49
+ end
50
+
51
+ it "should write the request path" do
52
+ subject.should include("/tacos.json")
53
+ end
54
+
55
+ it "should write the response body" do
56
+ subject.should include('meat')
57
+ end
58
+
59
+ describe "when accepting JSON as input" do
60
+ before do
61
+ @doc = ApiDoc.new(TestApp) do
62
+ post '/tacos.json' do
63
+ desc "Make a new delicious taco"
64
+ accept :json
65
+ params do
66
+ JSON.generate({ meat: 'beef', lettuce: true })
67
+ end
68
+ end
69
+ end
70
+
71
+ @doc.run
72
+ end
73
+
74
+ subject do
75
+ stream = StringIO.new
76
+ ApiDoc::HtmlWriter.new(@doc).write(stream)
77
+ stream.read
78
+ end
79
+
80
+ it "should pretty-print the JSON data in the IN section" do
81
+ subject.should include("{\n &quot;meat&quot;: &quot;beef&quot;,\n &quot;lettuce&quot;: true\n}")
82
+ end
83
+ end
84
+
85
+ describe "when setting the default accept and content type" do
86
+ before do
87
+ @doc = ApiDoc.new(TestApp) do
88
+ accept :json
89
+ content_type :json
90
+
91
+ post '/tacos.json' do
92
+ desc "Make a new delicious taco"
93
+ params do
94
+ JSON.generate({ meat: 'beef', lettuce: true })
95
+ end
96
+ end
97
+ end
98
+
99
+ @doc.run
100
+ end
101
+
102
+ subject { @doc }
103
+
104
+ it "should propagate the accept type to its resources" do
105
+ @doc.resources.first.accept.should == :json
106
+ end
107
+
108
+ it "should propagate the content type to its resources" do
109
+ @doc.resources.first.content_type.should == :json
110
+ end
111
+ end
112
+
113
+ describe "when providing JSON as output" do
114
+ before do
115
+ @doc = ApiDoc.new(TestApp) do
116
+ post '/tacos.json' do
117
+ desc "Make a new delicious taco"
118
+ content_type :json
119
+ params do
120
+ JSON.generate({ meat: 'beef', lettuce: true })
121
+ end
122
+ end
123
+ end
124
+
125
+ @doc.run
126
+ end
127
+
128
+ subject do
129
+ stream = StringIO.new
130
+ ApiDoc::HtmlWriter.new(@doc).write(stream)
131
+ stream.read
132
+ end
133
+
134
+ it "should pretty-print the JSON data in the OUT section" do
135
+ subject.should include("{\n &quot;meat&quot;: &quot;beef&quot;,\n &quot;lettuce&quot;: true\n}")
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ describe "different request methods" do
142
+ before do
143
+ class RequestMethodsApp < Sinatra::Base
144
+ get '/get.json' do
145
+ JSON.generate({ method: 'GET' })
146
+ end
147
+ post '/post.json' do
148
+ JSON.generate({ method: 'POST' })
149
+ end
150
+ put '/put.json' do
151
+ JSON.generate({ method: 'PUT' })
152
+ end
153
+ delete '/delete.json' do
154
+ JSON.generate({ method: 'DELETE' })
155
+ end
156
+ options '/options.json' do
157
+ JSON.generate({ method: 'OPTIONS' })
158
+ end
159
+ end
160
+
161
+ @doc = ApiDoc.new(RequestMethodsApp) do
162
+ get '/get.json' do
163
+ desc "a get request"
164
+ end
165
+
166
+ post '/post.json' do
167
+ desc "a post request"
168
+ end
169
+
170
+ put '/put.json' do
171
+ desc "a put request"
172
+ end
173
+
174
+ delete '/delete.json' do
175
+ desc "a delete request"
176
+ end
177
+
178
+ options '/options.json' do
179
+ desc "an options request"
180
+ end
181
+ end
182
+ end
183
+
184
+ it "should have all five resources" do
185
+ @doc.resources.length.should == 5
186
+ end
187
+
188
+ end
189
+
190
+ describe "when specifying a request with parameters" do
191
+ before do
192
+ @doc = ApiDoc.new(TestApp) do
193
+ post '/tacos.json' do
194
+ desc "Make a new delicious taco"
195
+ params do
196
+ JSON.generate({ meat: 'beef', lettuce: true })
197
+ end
198
+ end
199
+ end
200
+
201
+ @doc.run
202
+ end
203
+
204
+ subject { @doc.resources.first }
205
+
206
+ its(:params) { should == JSON.generate({ meat: 'beef', lettuce: true }) }
207
+ its(:response_body) { should == JSON.generate({ meat: 'beef', lettuce: true }) }
208
+ end
209
+
210
+ end
211
+
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'apidoc'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'apidoc'
2
+
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../../../config/environment", __FILE__)
5
+ # Requires supporting ruby files with custom matchers and macros, etc,
6
+ # in spec/support/ and its subdirectories.
7
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
8
+ require 'database_cleaner'
9
+
10
+ DatabaseCleaner.strategy = :truncation
11
+
@@ -0,0 +1,163 @@
1
+ <html>
2
+ <head>
3
+ <title>{{name}}</title>
4
+ <style>
5
+
6
+ html, body, div, span, applet, object, iframe,
7
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
8
+ a, abbr, acronym, address, big, cite, code,
9
+ del, dfn, em, img, ins, kbd, q, s, samp,
10
+ small, strike, strong, sub, sup, tt, var,
11
+ b, u, i, center,
12
+ dl, dt, dd, ol, ul, li,
13
+ fieldset, form, label, legend,
14
+ table, caption, tbody, tfoot, thead, tr, th, td,
15
+ article, aside, canvas, details, embed,
16
+ figure, figcaption, footer, header, hgroup,
17
+ menu, nav, output, ruby, section, summary,
18
+ time, mark, audio, video {
19
+ margin: 0;
20
+ padding: 0;
21
+ border: 0;
22
+ font-size: 100%;
23
+ font: inherit;
24
+ vertical-align: baseline;
25
+ }
26
+ /* HTML5 display-role reset for older browsers */
27
+ article, aside, details, figcaption, figure,
28
+ footer, header, hgroup, menu, nav, section {
29
+ display: block;
30
+ }
31
+ body {
32
+ line-height: 1;
33
+ }
34
+ ol, ul {
35
+ list-style: none;
36
+ }
37
+ blockquote, q {
38
+ quotes: none;
39
+ }
40
+ blockquote:before, blockquote:after,
41
+ q:before, q:after {
42
+ content: '';
43
+ content: none;
44
+ }
45
+ table {
46
+ border-collapse: collapse;
47
+ border-spacing: 0;
48
+ }
49
+
50
+
51
+
52
+
53
+
54
+ body {
55
+ font-family: Helvetica;
56
+ margin: 1em;
57
+ }
58
+
59
+ .name {
60
+ font-size: 2.0em;
61
+ }
62
+
63
+ .api-resource {
64
+ margin: 1em 0;
65
+ }
66
+
67
+ .api-resource .method {
68
+ font-size: 1em;
69
+ background-color: #999;
70
+ background-image: -webkit-linear-gradient(top,
71
+ transparent 0%,
72
+ rgba(0, 0, 0, 0.296875) 100%);
73
+ background-origin: padding-box;
74
+ border-bottom-color:
75
+ white;
76
+ border-bottom-left-radius: 0px;
77
+ border-bottom-style: none;
78
+ border-bottom-width: 0px;
79
+ border-left-color:
80
+ white;
81
+ border-left-style: none;
82
+ border-left-width: 0px;
83
+ border-right-color:
84
+ white;
85
+ border-right-style: none;
86
+ border-right-width: 0px;
87
+ border-top-color:
88
+ white;
89
+ border-top-left-radius: 3px;
90
+ border-top-style: none;
91
+ border-top-width: 0px;
92
+ color:
93
+ white;
94
+ text-align: center;
95
+ text-shadow:
96
+ rgba(0, 0, 0, 0.296875) 0px -1px 0px;
97
+ text-transform: uppercase;
98
+ vertical-align: baseline;
99
+ padding: 0.5em;
100
+ display: inline-block;
101
+ width: 84px;
102
+ }
103
+
104
+ .api-resource .path {
105
+ display: inline-block;
106
+ font-family: Monaco, fixed;
107
+ color: #0669CD;
108
+ font-size: 1em;
109
+ }
110
+
111
+ .api-resource .desc {
112
+ margin: 1em 0;
113
+ color:
114
+ #333;
115
+ display: block;
116
+ font-family: Helvetica, sans-serif;
117
+ font-size: 13px;
118
+ font-style: normal;
119
+ font-weight: 100;
120
+ height: 17px;
121
+ line-height: 17px;
122
+ text-shadow:
123
+ rgba(255, 255, 255, 0.597656) 0px 1px 0px;
124
+ vertical-align: baseline;
125
+ }
126
+ .api-resource .params,
127
+ .api-resource .response {
128
+ font-family: Monaco, fixed;
129
+ margin: 1em 0;
130
+ overflow: scroll;
131
+ white-space: pre;
132
+ background-color: #333333;
133
+ color: #8B8B8B;
134
+ padding: 1em;
135
+ border-radius: 2px;
136
+ }
137
+
138
+ .api-resource .params:before {
139
+ content: "IN";
140
+ color: #C29262;
141
+ display: block;
142
+ font-family: Helvetica;
143
+ margin: 0.5em 0;
144
+ }
145
+
146
+ .api-resource .response:before {
147
+ content: "OUT";
148
+ display: block;
149
+ color: #C29262;
150
+ font-family: Helvetica;
151
+ margin: 0.5em 0;
152
+ }
153
+ </style>
154
+ </head>
155
+
156
+ <body>
157
+ <div class="api">
158
+ <div class="name">{{name}}</div>
159
+ {{{content}}}
160
+ </div>
161
+ </body>
162
+ </html>
163
+
@@ -0,0 +1,7 @@
1
+ <div class="api-resource">
2
+ <div class="method">{{method}}</div>
3
+ <div class="path">{{path}}</div>
4
+ <div class="desc">{{desc}}</div>
5
+ <div class="params">{{params}}</div>
6
+ <div class="response">{{response}}</div>
7
+ </div>
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apidoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - T.J. VanSlyke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-03 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70176282425060 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70176282425060
25
+ - !ruby/object:Gem::Dependency
26
+ name: mustache
27
+ requirement: &70176282424240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70176282424240
36
+ - !ruby/object:Gem::Dependency
37
+ name: rack-test
38
+ requirement: &70176282423620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70176282423620
47
+ - !ruby/object:Gem::Dependency
48
+ name: mustache
49
+ requirement: &70176282410920 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70176282410920
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &70176282410100 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 2.8.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70176282410100
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: &70176282409460 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '3.12'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70176282409460
80
+ - !ruby/object:Gem::Dependency
81
+ name: bundler
82
+ requirement: &70176282408660 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.0.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70176282408660
91
+ - !ruby/object:Gem::Dependency
92
+ name: jeweler
93
+ requirement: &70176282407880 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 1.8.3
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70176282407880
102
+ - !ruby/object:Gem::Dependency
103
+ name: json
104
+ requirement: &70176282407180 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70176282407180
113
+ - !ruby/object:Gem::Dependency
114
+ name: sinatra
115
+ requirement: &70176282406500 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70176282406500
124
+ description: Minimalist API documentation generator for Rack applications.
125
+ email: tj@turing.com
126
+ executables:
127
+ - apidoc
128
+ extensions: []
129
+ extra_rdoc_files:
130
+ - LICENSE.txt
131
+ - README.rdoc
132
+ files:
133
+ - .document
134
+ - .rspec
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.txt
138
+ - README.rdoc
139
+ - Rakefile
140
+ - VERSION
141
+ - apidoc.gemspec
142
+ - bin/apidoc
143
+ - examples/authentication.rb
144
+ - examples/burritos_api.html
145
+ - examples/burritos_api.rb
146
+ - examples/tacos_api.html
147
+ - examples/tacos_api.rb
148
+ - ftags
149
+ - lib/apidoc.rb
150
+ - spec/apidoc_spec.rb
151
+ - spec/spec_helper.rb
152
+ - templates/apidoc_helper.rb
153
+ - templates/layout.mustache
154
+ - templates/resource.mustache
155
+ homepage: http://github.com/turingstudio/apidoc
156
+ licenses:
157
+ - MIT
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ segments:
169
+ - 0
170
+ hash: -1506073471830786691
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 1.8.10
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: Minimalist API documentation generator for Rack applications.
183
+ test_files: []