apidoc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'thor'
7
+ gem 'mustache'
8
+ gem 'rack-test'
9
+ gem 'mustache'
10
+
11
+ # Add dependencies to develop your gem here.
12
+ # Include everything needed to run rake, tests, features, etc.
13
+ group :development do
14
+ gem "rspec", "~> 2.8.0"
15
+ gem "rdoc", "~> 3.12"
16
+ gem "bundler", "~> 1.0.0"
17
+ gem "jeweler", "~> 1.8.3"
18
+ gem "json"
19
+ gem "sinatra"
20
+ end
@@ -0,0 +1,48 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.3)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.3)
12
+ mustache (0.99.4)
13
+ rack (1.4.0)
14
+ rack-protection (1.2.0)
15
+ rack
16
+ rack-test (0.6.1)
17
+ rack (>= 1.0)
18
+ rake (0.9.2.2)
19
+ rdoc (3.12)
20
+ json (~> 1.4)
21
+ rspec (2.8.0)
22
+ rspec-core (~> 2.8.0)
23
+ rspec-expectations (~> 2.8.0)
24
+ rspec-mocks (~> 2.8.0)
25
+ rspec-core (2.8.0)
26
+ rspec-expectations (2.8.0)
27
+ diff-lcs (~> 1.1.2)
28
+ rspec-mocks (2.8.0)
29
+ sinatra (1.3.2)
30
+ rack (>= 1.3.6, ~> 1.3)
31
+ rack-protection (~> 1.2)
32
+ tilt (>= 1.3.3, ~> 1.3)
33
+ thor (0.15.2)
34
+ tilt (1.3.3)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 1.0.0)
41
+ jeweler (~> 1.8.3)
42
+ json
43
+ mustache
44
+ rack-test
45
+ rdoc (~> 3.12)
46
+ rspec (~> 2.8.0)
47
+ sinatra
48
+ thor
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 T.J. VanSlyke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ = apidoc
2
+
3
+ Minimalist API documentation generator for Rack applications.
4
+
5
+ == Motivation
6
+
7
+ After searching for similar API documentation solutions and coming up dry, I
8
+ stumbled upon http://apiary.io. While I appreciate the motivation for this
9
+ project, I really wanted an API documentation tool that is:
10
+
11
+ 1. Example based: Show me what a _real_ request looks like with _real_ data.
12
+ 2. Self-testing and replicable: Build API documentation as part of your CI build, and know
13
+ it's up-to-date because it ran real requests against your application.
14
+ 3. Minimalist: `apidoc` is designed to make requests using the content type of
15
+ your choice and display the request, response and a short description. Nothing more.
16
+
17
+
18
+ == Install
19
+
20
+ $ gem install apidoc
21
+
22
+ == Use
23
+
24
+ # my_apidoc.rb
25
+
26
+ require 'path/to/my/app'
27
+
28
+ doc = ApiDoc.new(MyApp) do
29
+ get '/tacos.json' do
30
+ desc "Get all tacos owned by this user"
31
+ end
32
+
33
+ post "/tacos.json" do
34
+ desc "Make a fresh, delicious new taco"
35
+ params do
36
+ { meat: 'fish', sour_cream: true }
37
+ end
38
+ end
39
+ end
40
+
41
+ ApiDoc::HtmlWriter.new(doc).write(STDOUT)
42
+
43
+ See the examples folder for more examples.
44
+
45
+ == Contributing to apidoc
46
+
47
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
48
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
49
+ * Fork the project.
50
+ * Start a feature/bugfix branch.
51
+ * Commit and push until you are happy with your contribution.
52
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
53
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
54
+
55
+ == Copyright
56
+
57
+ Copyright (c) 2012 T.J. VanSlyke. See LICENSE.txt for
58
+ further details.
59
+
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "apidoc"
18
+ gem.homepage = "http://github.com/turingstudio/apidoc"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Minimalist API documentation generator for Rack applications.}
21
+ gem.description = %Q{Minimalist API documentation generator for Rack applications.}
22
+ gem.email = "tj@turing.com"
23
+ gem.authors = ["T.J. VanSlyke"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "apidoc #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
50
+
51
+ task :examples do
52
+ `ruby examples/tacos_api.rb > examples/tacos_api.html`
53
+ `ruby examples/burritos_api.rb > examples/burritos_api.html`
54
+ end
55
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,89 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "apidoc"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["T.J. VanSlyke"]
12
+ s.date = "2012-06-03"
13
+ s.description = "Minimalist API documentation generator for Rack applications."
14
+ s.email = "tj@turing.com"
15
+ s.executables = ["apidoc"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "apidoc.gemspec",
30
+ "bin/apidoc",
31
+ "examples/authentication.rb",
32
+ "examples/burritos_api.html",
33
+ "examples/burritos_api.rb",
34
+ "examples/tacos_api.html",
35
+ "examples/tacos_api.rb",
36
+ "ftags",
37
+ "lib/apidoc.rb",
38
+ "spec/apidoc_spec.rb",
39
+ "spec/spec_helper.rb",
40
+ "templates/apidoc_helper.rb",
41
+ "templates/layout.mustache",
42
+ "templates/resource.mustache"
43
+ ]
44
+ s.homepage = "http://github.com/turingstudio/apidoc"
45
+ s.licenses = ["MIT"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = "1.8.10"
48
+ s.summary = "Minimalist API documentation generator for Rack applications."
49
+
50
+ if s.respond_to? :specification_version then
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<thor>, [">= 0"])
55
+ s.add_runtime_dependency(%q<mustache>, [">= 0"])
56
+ s.add_runtime_dependency(%q<rack-test>, [">= 0"])
57
+ s.add_runtime_dependency(%q<mustache>, [">= 0"])
58
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
59
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
60
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
62
+ s.add_development_dependency(%q<json>, [">= 0"])
63
+ s.add_development_dependency(%q<sinatra>, [">= 0"])
64
+ else
65
+ s.add_dependency(%q<thor>, [">= 0"])
66
+ s.add_dependency(%q<mustache>, [">= 0"])
67
+ s.add_dependency(%q<rack-test>, [">= 0"])
68
+ s.add_dependency(%q<mustache>, [">= 0"])
69
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
70
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
73
+ s.add_dependency(%q<json>, [">= 0"])
74
+ s.add_dependency(%q<sinatra>, [">= 0"])
75
+ end
76
+ else
77
+ s.add_dependency(%q<thor>, [">= 0"])
78
+ s.add_dependency(%q<mustache>, [">= 0"])
79
+ s.add_dependency(%q<rack-test>, [">= 0"])
80
+ s.add_dependency(%q<mustache>, [">= 0"])
81
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
82
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
83
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
84
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
85
+ s.add_dependency(%q<json>, [">= 0"])
86
+ s.add_dependency(%q<sinatra>, [">= 0"])
87
+ end
88
+ end
89
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/apidoc'
4
+
5
+ ApiDoc::Application.start
6
+
@@ -0,0 +1,8 @@
1
+ require 'apidoc_helper'
2
+
3
+ post "/api/v1/session.json" do
4
+ desc "Authenticate user session"
5
+ setup { @user = User.make! }
6
+ params { { user: { email: @user.email, password: @user.password } } }
7
+ end
8
+
@@ -0,0 +1,190 @@
1
+ <html>
2
+ <head>
3
+ <title></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"></div>
159
+ <div class="api-resource">
160
+ <div class="method">GET</div>
161
+ <div class="path">/burritos.json</div>
162
+ <div class="desc">Get all burritos</div>
163
+ <div class="params"></div>
164
+ <div class="response">[
165
+ {
166
+ &quot;meat&quot;: &quot;chicken&quot;
167
+ },
168
+ {
169
+ &quot;meat&quot;: &quot;tofu&quot;
170
+ }
171
+ ]</div>
172
+ </div>
173
+ <div class="api-resource">
174
+ <div class="method">POST</div>
175
+ <div class="path">/burritos.json</div>
176
+ <div class="desc">Make a new delicious burrito</div>
177
+ <div class="params">{
178
+ &quot;meat&quot;: &quot;beef&quot;,
179
+ &quot;lettuce&quot;: true
180
+ }</div>
181
+ <div class="response">{
182
+ &quot;meat&quot;: &quot;beef&quot;,
183
+ &quot;lettuce&quot;: true
184
+ }</div>
185
+ </div>
186
+
187
+ </div>
188
+ </body>
189
+ </html>
190
+