restapi_doc 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.
@@ -0,0 +1,107 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:name => "viewport", "content" => "width=device-width, initial-scale=1.0"}/
5
+ %meta{:description => ""}/
6
+ %meta{:author => ""}/
7
+ %link{:href => "../../assets/css/bootstrap.min.css", :rel => "stylesheet", :type => "text/css"}/
8
+ %link{:href => "../../assets/css/bootstrap-responsive.min.css", :rel => "stylesheet", :type => "text/css"}/
9
+ %link{:href => "../../assets/css/prettify.css", :rel => "stylesheet", :type => "text/css"}/
10
+ %link{:href => "../../assets/ico/favicon.ico", :rel => "shortcut icon"}/
11
+ %link{:href => "../../assets/ico/apple-touch-icon-114-precomposed.png", :rel => "apple-touch-icon-precomposed", :size => "114x114"}/
12
+ %link{:href => "../../assets/ico/apple-touch-icon-72-precomposed.png", :rel => "apple-touch-icon-precomposed", :size => "72x72"}/
13
+ %link{:href => "../../assets/ico/apple-touch-icon-57-precomposed.png", :rel => "apple-touch-icon-precomposed"}/
14
+ %style
15
+ body{padding-top:60px;padding-bottom: 40px;}
16
+ %title #{project_info['project_name']} - RESTful API Doc
17
+ %body{"onload" => "prettyPrint();"}
18
+ %div{:class => "navbar navbar-fixed-top"}
19
+ %div{:class => "navbar-inner"}
20
+ .container
21
+ %a{:class => "btn btn-navbar", "data-toggle" => "collapse", "data-target" => "nav-collapse"}
22
+ %span{:class => "icon-bar"}
23
+ %span{:class => "icon-bar"}
24
+ %span{:class => "icon-bar"}
25
+ %a{:class => "brand"}
26
+ = "#{project_info['project_name']}"
27
+ %div{:class => "nav-collapse"}
28
+ %ul{:class=> "nav"}
29
+ %li{:class => "active"}
30
+ %a{:href => "../../index.html"}
31
+ = "RESTful Resources"
32
+ %div{:class => "container"}
33
+ %h1{:style => "margin-bottom:20px;"} #{rmethod[1]} #{rmethod[2].gsub(/\(.*\)/, '')}
34
+ %div{:class => "row-fluid"}
35
+ %div{:class => "span9"}
36
+ %p #{rmethod[3].content unless rmethod[3].nil?}
37
+ %hr
38
+ %h4{:style => "margin-bottom:10px;"} Resource URL
39
+ %p #{project_info['base_url']}#{rmethod[2].gsub(/\(.*\)/, '')}
40
+ - if !rmethod[3].nil?
41
+ %h4{:style => "margin-top:30px;"} Parameters
42
+ %table{:class => "table"}
43
+ %tbody
44
+ - rmethod[3].params.each do |param|
45
+ %tr
46
+ %td{:style => "width:35%"}
47
+ = "#{param.split('-')[0].strip} (#{param.split('-')[1].strip})"
48
+ %span{:class => "muted", :style => "display:block;font-size:12px;"} #{param.split('-')[2].strip.downcase}
49
+ %td #{param.split('-')[3].strip}
50
+ %hr
51
+ - if !rmethod[3].nil?
52
+ %h4{:style => "margin-bottom:10px;"} HTTP Status Codes
53
+ %table{:class => "table"}
54
+ %tbody
55
+ - rmethod[3].http_responses.each do |httpresp|
56
+ %tr
57
+ %td
58
+ = "#{httpresp.split('-')[0].strip}"
59
+ %span{:class => "muted", :style => "display:block;font-size:12px;"} #{httpresp.split('-')[1].strip}
60
+ %td #{httpresp.split('-')[2].strip}
61
+ %hr
62
+ %h4{:style=> "margin-bottom:10px;"} Examples
63
+ -if !rmethod[3].nil?
64
+ - if !rmethod[3].request_url.nil?
65
+ %h5{:style => "margin-bottom:10px;"} Request URL
66
+ %blockquote
67
+ %p{:style => "font-size:12px;"} #{project_info['base_url']}#{rmethod[3].request_url}
68
+ - if !rmethod[3].nil?
69
+ - if !rmethod[3].request.empty?
70
+ %h5{:style => "margin-bottom:10px;"} Request
71
+ %pre{:class => "prettyprint linenums"} #{rmethod[3].request unless rmethod[3].nil?}
72
+ - if !rmethod[3].nil?
73
+ - if !rmethod[3].output.empty?
74
+ %h5{:style => "margin-bottom:10px;"} Response
75
+ %pre{:class => "prettyprint linenums"} #{rmethod[3].output unless rmethod[3].nil?}
76
+
77
+ %div{:class => "span3"}
78
+ %div{:class => "well"}
79
+ %h4 Resource Information
80
+ %table{:class=> "table table-condensed"}
81
+ %thead
82
+ %tr
83
+ %th
84
+ %tbody
85
+ %tr
86
+ %td Category
87
+ %td #{name}
88
+ %tr
89
+ %td Requires Authentication?
90
+ %td #{rmethod[3].requires_authentication unless rmethod[3].nil?}
91
+ %tr
92
+ %td Requires Account Password?
93
+ %td #{rmethod[3].account_password_required unless rmethod[3].nil?}
94
+ %tr
95
+ %td Response Formats
96
+ %td
97
+ - if !rmethod[3].nil?
98
+ - rmethod[3].response_formats.each do |rf|
99
+ %span #{rf}
100
+ %tr
101
+ %td HTTP Method
102
+ %td #{rmethod[1]}
103
+
104
+
105
+ %script{:src => "../../assets/js/jquery.js", :type => "text/javascript"}
106
+ %script{:src => "../../assets/js/bootstrap.min.js", :type => "text/javascript"}
107
+ %script{:src => "../../assets/js/prettify.js", :type => "text/javascript"}
@@ -0,0 +1,57 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:name => "viewport", "content" => "width=device-width, initial-scale=1.0"}/
5
+ %meta{:description => ""}/
6
+ %meta{:author => ""}/
7
+ %link{:href => "assets/css/bootstrap.min.css", :rel => "stylesheet", :type => "text/css"}/
8
+ %link{:href => "assets/css/bootstrap-responsive.min.css", :rel => "stylesheet", :type => "text/css"}/
9
+ %link{:href => "assets/css/bootstrap.less", :rel => "stylesheet/less"}/
10
+ %script{:src => "assets/js/less.min.js", :type => "text/javascript"}
11
+ %link{:href => "assets/ico/favicon.ico", :rel => "shortcut icon"}/
12
+ %link{:href => "assets/ico/apple-touch-icon-114-precomposed.png", :rel => "apple-touch-icon-precomposed", :size => "114x114"}/
13
+ %link{:href => "assets/ico/apple-touch-icon-72-precomposed.png", :rel => "apple-touch-icon-precomposed", :size => "72x72"}/
14
+ %link{:href => "assets/ico/apple-touch-icon-57-precomposed.png", :rel => "apple-touch-icon-precomposed"}/
15
+ %style
16
+ body{padding-top:60px;padding-bottom: 40px;}
17
+ %title #{project_info['project_name']} - RESTful API Doc
18
+ %body
19
+ %div{:class => "navbar navbar-fixed-top"}
20
+ %div{:class => "navbar-inner"}
21
+ .container
22
+ %a{:class => "btn btn-navbar", "data-toggle" => "collapse", "data-target" => "nav-collapse"}
23
+ %span{:class => "icon-bar"}
24
+ %span{:class => "icon-bar"}
25
+ %span{:class => "icon-bar"}
26
+ %a{:class => "brand"}
27
+ = "#{project_info['project_name']}"
28
+ %div{:class => "nav-collapse"}
29
+ %ul{:class=> "nav"}
30
+ %li{:class => "active"}
31
+ %a{:href => "index.html"}
32
+ = "RESTful Resources"
33
+ %div{:class => "container"}
34
+ #resource_index
35
+ %h1 RESTful API Resources
36
+ %hr
37
+ %div{:class=> "row-fluid"}
38
+ - resource_docs.each do |resource|
39
+ %h3{:style => "text-indent:5x;"} #{resource.name.capitalize}
40
+ %p #{resource.description}
41
+ %hr{:style => "margin-top:2px;margin-bottom:2px;"}
42
+ %table{:class => "table table-striped"}
43
+ %thead
44
+ %tr
45
+ %th{"style" => "width:35%"} Resource
46
+ %th Description
47
+ %tbody
48
+ - resource.resource_methods.each do |method_block|
49
+ %tr
50
+ %td
51
+ %a{:href => "resources/#{resource.name}/#{method_block[0]}.html"}
52
+ = "#{method_block[1]} #{method_block[2].gsub(/\(.*\)/, '')}"
53
+ %td #{method_block[3].content unless method_block[3].nil?}
54
+
55
+ %script{:src => "assets/js/jquery.js", :type => "text/javascript"}
56
+ %script{:src => "assets/js/bootstrap.min.js", :type => "text/javascript"}
57
+ %script{:src => "assets/js/prettify.js", :type => "text/javascript"}
@@ -0,0 +1,99 @@
1
+ # encoding: utf-8
2
+ require 'haml'
3
+ require 'yaml'
4
+ require 'fileutils'
5
+ require File.expand_path('../restapi_doc/resource_doc', __FILE__)
6
+ require File.expand_path('../restapi_doc/config', __FILE__)
7
+ require File.expand_path('../restapi_doc/railtie', __FILE__) if defined?(Rails)
8
+
9
+ module RestApiDoc
10
+ VERSION = File.read(File.expand_path("../VERSION", File.dirname(__FILE__)))
11
+
12
+ include Config
13
+ include FileUtils
14
+
15
+ def create_structure
16
+ File.directory?(config_dir) || mkdir(config_dir)
17
+ Dir["#{config_template_dir}/*.*"].each do |template_file|
18
+ target_file = config_dir(File.basename(template_file))
19
+ cp template_file, config_dir if not File.exist? target_file
20
+ end
21
+ end
22
+
23
+ # Reads 'rake routes' output and gets the controller info
24
+ def get_controller_info
25
+ controller_info = {}
26
+ routes = Dir.chdir(::Rails.root.to_s) { `rake routes` }
27
+ routes.split("\n").each do |entry|
28
+ method, url, controller_action = entry.split.slice(-3, 3)
29
+ controller, action = controller_action.split('#')
30
+ controller_info[controller] ||= []
31
+ controller_info[controller] << [action, method, url]
32
+ end
33
+ controller_info
34
+ end
35
+
36
+ # Create resources
37
+ def get_resources
38
+ controller_info = get_controller_info
39
+ resources = []
40
+ controller_info.each do |controller, action_entries|
41
+ controller_location = controller_dir(controller + '_controller.rb')
42
+ controller_base_routes = action_entries
43
+ resources << ResourceDoc.new(controller, action_entries, controller_location)
44
+ end
45
+ resources
46
+ end
47
+
48
+ # Generates views and their index in a temp directory
49
+ def generate_doc(resource_docs)
50
+ generate_index_templates(resource_docs)
51
+ copy_assets!
52
+ end
53
+
54
+ # Creates index template for all resources
55
+ def generate_index_templates(resource_docs)
56
+ restapi_config = YAML.load(File.read("#{config_dir}/restapi_doc.yml"))
57
+ resource_docs.each { |resource| resource.parse_apidoc }
58
+ template = IO.read(template_dir('index.html.haml'))
59
+ parsed = Haml::Engine.new(template).render(Object.new, :project_info => restapi_config, :resource_docs => resource_docs)
60
+ File.open(temp_dir("index.html"), 'w') { |file| file.write parsed }
61
+
62
+ # Generate detail files
63
+ resource_docs.each do | resource_doc|
64
+ generate_resource_detail_file!(resource_doc)
65
+ end
66
+ end
67
+
68
+ # Generate detail files for resource method
69
+ def generate_resource_detail_file!(resource_doc)
70
+ restapi_config = YAML.load(File.read("#{config_dir}/restapi_doc.yml"))
71
+ Dir.mkdir(temp_dir + "/resources") if (!File.directory?(temp_dir + "/resources"))
72
+ Dir.mkdir(temp_dir + "/resources/" + resource_doc.name) if (!File.directory?(temp_dir + "/resources/" + resource_doc.name))
73
+ resource_doc.resource_methods.each do | method|
74
+ template = IO.read(template_dir('detail.html.haml'))
75
+ parsed = Haml::Engine.new(template).render(Object.new, :project_info => restapi_config, :name => resource_doc.name , :rmethod => method)
76
+ File.open(temp_dir + "/resources/" + resource_doc.name + "/" + method[0] + ".html", 'w') { |file| file.write parsed }
77
+ end
78
+ end
79
+
80
+ # Move document to public
81
+ def move_document
82
+ Dir.mkdir(target_dir) if (!File.directory?(target_dir))
83
+ # Only want to move the .html, .css, .png and .js files, not the .haml templates.
84
+ html_css_files = temp_dir("*.{html,css,js,png}")
85
+ Dir[html_css_files].each { |f| mv f, target_dir }
86
+ mv temp_dir + "/resources", target_dir, :force => true if (File.directory?(temp_dir + "/resources"))
87
+ mv temp_dir + "/assets", target_dir, :force => true if (File.directory?(temp_dir + "/assets"))
88
+ end
89
+
90
+ def copy_assets!
91
+ # Copy over assets
92
+ cp_r asset_dir, temp_dir
93
+ end
94
+
95
+ # Removes the generated files
96
+ def remove_structure
97
+ rm_rf target_dir
98
+ end
99
+ end
@@ -0,0 +1,79 @@
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 = "restapi_doc"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kevin Haight"]
12
+ s.date = "2012-04-26"
13
+ s.description = "REST API doc generates an easy way to create a twitter style document for your RESTful interface. \n Leveraging Twitter Bootstrap to create an easy to read document for your RESTful api. "
14
+ s.email = "kevinjhaight@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/restapi_doc.rb",
27
+ "lib/restapi_doc/config.rb",
28
+ "lib/restapi_doc/config/restapi_doc.yml",
29
+ "lib/restapi_doc/method_doc.rb",
30
+ "lib/restapi_doc/railtie.rb",
31
+ "lib/restapi_doc/resource_doc.rb",
32
+ "lib/restapi_doc/tasks/restapi_doc_tasks.rake",
33
+ "lib/restapi_doc/template/assets/css/bootstrap-responsive.min.css",
34
+ "lib/restapi_doc/template/assets/css/bootstrap.less",
35
+ "lib/restapi_doc/template/assets/css/bootstrap.min.css",
36
+ "lib/restapi_doc/template/assets/css/prettify.css",
37
+ "lib/restapi_doc/template/assets/img/glyphicons-halflings-white.png",
38
+ "lib/restapi_doc/template/assets/img/glyphicons-halflings.png",
39
+ "lib/restapi_doc/template/assets/js/bootstrap.min.js",
40
+ "lib/restapi_doc/template/assets/js/jquery.js",
41
+ "lib/restapi_doc/template/assets/js/less.min.js",
42
+ "lib/restapi_doc/template/assets/js/prettify.js",
43
+ "lib/restapi_doc/template/detail.html.haml",
44
+ "lib/restapi_doc/template/index.html.haml",
45
+ "restapi_doc.gemspec"
46
+ ]
47
+ s.homepage = "http://github.com/alayho/restapi_doc"
48
+ s.require_paths = ["lib"]
49
+ s.rubygems_version = "1.8.17"
50
+ s.summary = "REST API doc generates an easy way to create a twitter style document for your RESTful interface"
51
+
52
+ if s.respond_to? :specification_version then
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.1"])
57
+ s.add_runtime_dependency(%q<haml>, ["= 3.1.4"])
58
+ s.add_development_dependency(%q<rake>, [">= 0"])
59
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
60
+ s.add_development_dependency(%q<rspec>, [">= 2.2.0"])
61
+ s.add_development_dependency(%q<mocha>, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<activesupport>, [">= 2.1"])
64
+ s.add_dependency(%q<haml>, ["= 3.1.4"])
65
+ s.add_dependency(%q<rake>, [">= 0"])
66
+ s.add_dependency(%q<jeweler>, [">= 0"])
67
+ s.add_dependency(%q<rspec>, [">= 2.2.0"])
68
+ s.add_dependency(%q<mocha>, [">= 0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<activesupport>, [">= 2.1"])
72
+ s.add_dependency(%q<haml>, ["= 3.1.4"])
73
+ s.add_dependency(%q<rake>, [">= 0"])
74
+ s.add_dependency(%q<jeweler>, [">= 0"])
75
+ s.add_dependency(%q<rspec>, [">= 2.2.0"])
76
+ s.add_dependency(%q<mocha>, [">= 0"])
77
+ end
78
+ end
79
+
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restapi_doc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Haight
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &2152452280 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152452280
25
+ - !ruby/object:Gem::Dependency
26
+ name: haml
27
+ requirement: &2152451780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2152451780
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2152451180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2152451180
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &2152450340 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2152450340
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &2152449700 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 2.2.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2152449700
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: &2152449180 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2152449180
80
+ description: ! "REST API doc generates an easy way to create a twitter style document
81
+ for your RESTful interface. \n Leveraging Twitter Bootstrap
82
+ to create an easy to read document for your RESTful api. "
83
+ email: kevinjhaight@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files:
87
+ - LICENSE
88
+ - README.rdoc
89
+ files:
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - lib/restapi_doc.rb
97
+ - lib/restapi_doc/config.rb
98
+ - lib/restapi_doc/config/restapi_doc.yml
99
+ - lib/restapi_doc/method_doc.rb
100
+ - lib/restapi_doc/railtie.rb
101
+ - lib/restapi_doc/resource_doc.rb
102
+ - lib/restapi_doc/tasks/restapi_doc_tasks.rake
103
+ - lib/restapi_doc/template/assets/css/bootstrap-responsive.min.css
104
+ - lib/restapi_doc/template/assets/css/bootstrap.less
105
+ - lib/restapi_doc/template/assets/css/bootstrap.min.css
106
+ - lib/restapi_doc/template/assets/css/prettify.css
107
+ - lib/restapi_doc/template/assets/img/glyphicons-halflings-white.png
108
+ - lib/restapi_doc/template/assets/img/glyphicons-halflings.png
109
+ - lib/restapi_doc/template/assets/js/bootstrap.min.js
110
+ - lib/restapi_doc/template/assets/js/jquery.js
111
+ - lib/restapi_doc/template/assets/js/less.min.js
112
+ - lib/restapi_doc/template/assets/js/prettify.js
113
+ - lib/restapi_doc/template/detail.html.haml
114
+ - lib/restapi_doc/template/index.html.haml
115
+ - restapi_doc.gemspec
116
+ homepage: http://github.com/alayho/restapi_doc
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.17
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: REST API doc generates an easy way to create a twitter style document for
140
+ your RESTful interface
141
+ test_files: []