padrino-apidoc 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +8 -0
- data/lib/padrino/apidoc/parser.rb +109 -0
- data/lib/padrino/apidoc/version.rb +5 -0
- data/lib/padrino/apidoc.rb +66 -0
- data/padrino-apidoc.gemspec +26 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb1f30f39d0f5988df171674c6da506bcc7bb5fd
|
4
|
+
data.tar.gz: 800ba1b7c223635ed769d5fadcd02aaa96633bc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1fed3fd8780553a1f28481ba2801cc9ee09cce56666dc565f8f8f4cf51ee75df8ccc414eee26a3d712578add95ae9cebc0896b0039c89b56e5501a4344f8c7b
|
7
|
+
data.tar.gz: 3937c339f3b9d9102bde9cd17c3d47998cadca9d5bddcf4f99bb74f408ca65e7c49445d8914c6f7fce121931c07ef5c1661458a785b25339ce25b66ad08bba41
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Blackburn, Midwire Technologies, LLC.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Padrino::Apidoc
|
2
|
+
|
3
|
+
A padrino sub-app plugin to generate API documentation for your controllers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'padrino-apidoc'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install padrino-apidoc
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Documentation Syntax
|
22
|
+
|
23
|
+
## Section Name
|
24
|
+
|
25
|
+
# Create an application.
|
26
|
+
#
|
27
|
+
# @param <name> the name of the application to create
|
28
|
+
# @param [stack] the stack on which to create the application
|
29
|
+
#
|
30
|
+
# @request
|
31
|
+
# POST /apps.json
|
32
|
+
# name=example&stack=bamboo-ree-1.8.7
|
33
|
+
# @response
|
34
|
+
# {
|
35
|
+
# "id": 1,
|
36
|
+
# "name": "example",
|
37
|
+
# "owner": "user@example.org",
|
38
|
+
# "created_at": "Sat Jan 01 00:00:00 UTC 2000",
|
39
|
+
# "stack": "bamboo-ree-1.8.7",
|
40
|
+
# "slug_size": 1000000,
|
41
|
+
# "repo_size": 500000,
|
42
|
+
# "dynos": 1,
|
43
|
+
# "workers": 0
|
44
|
+
# }
|
45
|
+
|
46
|
+
At the end of your config/apps.rb file:
|
47
|
+
|
48
|
+
Padrino.mount('Padrino::Apidoc::App').to('/docs')
|
49
|
+
|
50
|
+
Navigate to 'localhost:9292/docs' or whatever hostname/port you are running on.
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# This code was taken directly from David Dollar's apidoc project:
|
2
|
+
# https://github.com/ddollar/apidoc.
|
3
|
+
#
|
4
|
+
# It has been modified slightly to allow for more lenient route syntax
|
5
|
+
module Padrino
|
6
|
+
module Apidoc
|
7
|
+
|
8
|
+
class Parser
|
9
|
+
class << self
|
10
|
+
def parse(files)
|
11
|
+
parser = self.new
|
12
|
+
files.each { |file| parser.parse_file(file) }
|
13
|
+
parser
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :docs
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@docs = []
|
21
|
+
@section = 'General'
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_file(file)
|
25
|
+
File.read(file).split("\n").each do |line|
|
26
|
+
case line.strip
|
27
|
+
when /\A##\s*(.+)\Z/ then
|
28
|
+
clear_comments
|
29
|
+
parse_section($1)
|
30
|
+
when /\A#(\s*.*)\Z/ then
|
31
|
+
parse_comment($1)
|
32
|
+
when /\A(get|post|put|delete)\s+(:.+),\s+map:\s+["'](.+)["']/ then
|
33
|
+
parse_method($1, $3)
|
34
|
+
when /\A(get|post|put|delete)\s+["'](.+)["']/ then
|
35
|
+
parse_method($1, $2)
|
36
|
+
when '' then
|
37
|
+
else
|
38
|
+
clear_comments
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
########################################
|
44
|
+
private
|
45
|
+
|
46
|
+
def clear_comments
|
47
|
+
@comments = []
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_section(section)
|
51
|
+
@section = section.gsub("#", "").strip
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_comment(comment)
|
55
|
+
@comments << comment
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse_comments(comments)
|
59
|
+
key = :description
|
60
|
+
|
61
|
+
comments.inject({}) do |parsed, comment|
|
62
|
+
case comment
|
63
|
+
when /\A\s*@param\s+(.+?)\s+(.+)/ then
|
64
|
+
parsed[:params] ||= []
|
65
|
+
required = $1[0..0] == '<'
|
66
|
+
name = $1[1..-2]
|
67
|
+
parsed[:params] << { :name => name, :description => $2, :required => required }
|
68
|
+
when /\A\s*@(\w+)\s*(.*)\Z/ then
|
69
|
+
key = $1.to_sym
|
70
|
+
parsed[key] ||= []
|
71
|
+
parsed[key] << $2 if $2
|
72
|
+
else
|
73
|
+
parsed[key] ||= []
|
74
|
+
parsed[key] << comment
|
75
|
+
end
|
76
|
+
parsed
|
77
|
+
end.inject({}) do |flattened, (k, v)|
|
78
|
+
case v.first
|
79
|
+
when String then
|
80
|
+
flattened[k] = strip_left(v.reject { |l| l.strip == "" }.join("\n"))
|
81
|
+
else
|
82
|
+
flattened[k] = v
|
83
|
+
end
|
84
|
+
flattened
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse_method(verb, uri)
|
89
|
+
@docs << {
|
90
|
+
:section => @section,
|
91
|
+
:verb => verb,
|
92
|
+
:uri => uri,
|
93
|
+
}.merge(parse_comments(@comments))
|
94
|
+
|
95
|
+
clear_comments
|
96
|
+
end
|
97
|
+
|
98
|
+
def strip_left(code)
|
99
|
+
first_line = code.split("\n").first
|
100
|
+
num_spaces = first_line.match(/\A */)[0].length
|
101
|
+
code.split("\n").map do |line|
|
102
|
+
line[num_spaces..-1]
|
103
|
+
end.join("\n")
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end # module Apidoc
|
109
|
+
end # module Padrino
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'padrino'
|
2
|
+
require "padrino/apidoc/version"
|
3
|
+
require "padrino/apidoc/parser"
|
4
|
+
|
5
|
+
module Padrino
|
6
|
+
module Apidoc
|
7
|
+
|
8
|
+
class App < Padrino::Application
|
9
|
+
register Padrino::Rendering
|
10
|
+
register Padrino::Helpers
|
11
|
+
|
12
|
+
helpers do
|
13
|
+
def urlize_section(section)
|
14
|
+
section.downcase.gsub(" ", "_")
|
15
|
+
end
|
16
|
+
|
17
|
+
def docs_in_section(docs, section)
|
18
|
+
docs.select { |doc| urlize_section(doc[:section]) == section }
|
19
|
+
end
|
20
|
+
|
21
|
+
def code(code)
|
22
|
+
Haml::Filters::Preserve.render(Haml::Filters::Escaped.render(code))
|
23
|
+
end
|
24
|
+
|
25
|
+
def doc(page, title)
|
26
|
+
active = (env["PATH_INFO"] == "/#{page}") ? "active" : ""
|
27
|
+
%{ <li class="#{active}"><a href="/#{page}">#{title}</a></li> }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
disable :sessions
|
32
|
+
|
33
|
+
class << self
|
34
|
+
def sections_in(docs)
|
35
|
+
docs.map { |doc| doc[:section] }.uniq.compact
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
set :docs, Parser.parse(Dir["#{Padrino.root}/app/controllers/*.rb"]).docs
|
40
|
+
set :sections, App.sections_in(settings.docs)
|
41
|
+
|
42
|
+
########################################
|
43
|
+
# ROUTES
|
44
|
+
get "/" do
|
45
|
+
render :index, layout_engine: :haml, layout: 'apidoc', :locals => {
|
46
|
+
:docs => settings.docs,
|
47
|
+
:sections => settings.sections
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
get "/docs.css" do
|
52
|
+
content_type "text/css"
|
53
|
+
sass :docs
|
54
|
+
end
|
55
|
+
|
56
|
+
get "/:section" do |section|
|
57
|
+
haml :section, :locals => {
|
58
|
+
:docs => docs_in_section(settings.docs, section),
|
59
|
+
:sections => settings.sections,
|
60
|
+
:section => settings.sections.detect { |s| urlize_section(s) == section }
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'padrino/apidoc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "padrino-apidoc"
|
8
|
+
spec.version = Padrino::Apidoc::VERSION
|
9
|
+
spec.authors = ["Chris Blackburn"]
|
10
|
+
spec.email = ["chris@midwiretech.com"]
|
11
|
+
spec.description = %q{A padrino sub-app plugin to generate API documentation for your controllers.}
|
12
|
+
spec.summary = %q{A padrino sub-app plugin to generate API documentation for your controllers.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "midwire_common"
|
24
|
+
|
25
|
+
spec.add_dependency 'padrino'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: padrino-apidoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Blackburn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: midwire_common
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: padrino
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A padrino sub-app plugin to generate API documentation for your controllers.
|
70
|
+
email:
|
71
|
+
- chris@midwiretech.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/padrino/apidoc.rb
|
82
|
+
- lib/padrino/apidoc/parser.rb
|
83
|
+
- lib/padrino/apidoc/version.rb
|
84
|
+
- padrino-apidoc.gemspec
|
85
|
+
homepage: ''
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.0.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: A padrino sub-app plugin to generate API documentation for your controllers.
|
109
|
+
test_files: []
|