apidocs 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/app/assets/javascripts/apidocs/apidocs.js +4 -5
- data/app/assets/stylesheets/apidocs/apidocs.css.scss +5 -0
- data/app/controllers/apidocs/apidocs_controller.rb +17 -0
- data/app/views/apidocs/apidocs/index.html.erb +1 -1
- data/app/views/layouts/apidocs/application.html.erb +1 -1
- data/lib/apidocs.rb +30 -12
- data/lib/apidocs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73da5aca8b695e550bfc631d3f42fe6e6a585e2f
|
4
|
+
data.tar.gz: 39f4d0400b003afa6800405a4b3c3d00e7de5007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf08c415f14ea8dd154fad843d3c4ca715f68818518651f8db950bcfeed07f8f9cfb917a573f34e26bfd6519b7961bcda6cd3c8c47492fd5d5aa7e16c4d0239d
|
7
|
+
data.tar.gz: 5755ff5c3718c667e12368713b4e956fe9221ac9df9c6dbeee8861414f05e2a2f5425d6e12899d87d4253855f0f3e43e56c9037eaa5e029ca6b28d35841b5fb8
|
data/README.md
CHANGED
@@ -6,4 +6,13 @@ Generates and serves HTML documentation out of your routing and controllers for
|
|
6
6
|
Installation
|
7
7
|
=======
|
8
8
|
|
9
|
-
Add
|
9
|
+
Add ```mount Apidocs::Engine => "/apidocs"``` to your applications ```routes.rb```
|
10
|
+
|
11
|
+
Configuration
|
12
|
+
=======
|
13
|
+
|
14
|
+
Apidocs.configure do |config|
|
15
|
+
config.regex_filter = /api/ # filter routes
|
16
|
+
config.http_username = 'admin' # optional http basic authorization
|
17
|
+
config.http_password = '5ebe2294ecd0e0f08eab7690d2a6ee69' # md5 hash for password
|
18
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
$(function () {
|
2
|
-
$(
|
3
|
-
|
4
|
-
$("#main-content").html(data);
|
5
|
-
});
|
2
|
+
$('.nav-button').click(function () {
|
3
|
+
window.location.href = this.getAttribute("href") + '&search=' + $('#search-input').val();
|
6
4
|
return false;
|
7
5
|
});
|
8
6
|
$('#search-input').fastLiveFilter('#search-list');
|
9
|
-
|
7
|
+
$('#search-input').trigger('change');
|
8
|
+
});
|
@@ -2,8 +2,15 @@ require_dependency "apidocs/application_controller"
|
|
2
2
|
|
3
3
|
module Apidocs
|
4
4
|
class ApidocsController < ApplicationController
|
5
|
+
before_action :authenticate
|
6
|
+
|
5
7
|
def index
|
6
8
|
@routes = routes_rdoc
|
9
|
+
|
10
|
+
if params[:search]
|
11
|
+
@searchinput = params[:search]
|
12
|
+
end
|
13
|
+
|
7
14
|
if params[:path]
|
8
15
|
@route = routes_rdoc[params[:path]]
|
9
16
|
else
|
@@ -22,11 +29,21 @@ module Apidocs
|
|
22
29
|
end
|
23
30
|
|
24
31
|
private
|
32
|
+
|
25
33
|
def routes_rdoc
|
26
34
|
Rails.cache.fetch("routes_rdoc_html") do
|
27
35
|
routes = Apidocs::ApiDocs.new.generate_html
|
28
36
|
routes.group_by { |r| r[:path] }
|
29
37
|
end
|
30
38
|
end
|
39
|
+
|
40
|
+
def authenticate
|
41
|
+
if Apidocs.configuration.http_username && Apidocs.configuration.http_password
|
42
|
+
authenticate_or_request_with_http_basic do |u, p|
|
43
|
+
u == Apidocs.configuration.http_username && Digest::MD5.hexdigest(p) == Apidocs.configuration.http_password
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
31
47
|
end
|
32
48
|
end
|
49
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% content_for :nav do %>
|
2
2
|
<ul id="search-list" class="list-unstyled">
|
3
3
|
<% @routes.each do |path, route| %>
|
4
|
-
<li><%= link_to path, root_path(path: path), class: 'nav-button' %></li>
|
4
|
+
<li><%= link_to path, root_path(path: path), class: 'nav-button', title: path %></li>
|
5
5
|
<% end %>
|
6
6
|
</ul>
|
7
7
|
<% end %>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
<%= link_to 'APIDOC', root_path, class: 'navbar-brand' %>
|
15
15
|
<form class="navbar-form navbar-left" role="search">
|
16
16
|
<div class="form-group">
|
17
|
-
<input type="text" class="search-query" id="search-input" placeholder="
|
17
|
+
<input type="text" value='<%= @searchinput %>' class="search-query" id="search-input" placeholder="Filter">
|
18
18
|
</div>
|
19
19
|
</form>
|
20
20
|
</div>
|
data/lib/apidocs.rb
CHANGED
@@ -6,7 +6,7 @@ module Apidocs
|
|
6
6
|
require 'fileutils'
|
7
7
|
# This is class comment
|
8
8
|
class ApiDocs < RDoc::RDoc
|
9
|
-
# generate_html
|
9
|
+
# generate_html entry point for on fly document generation
|
10
10
|
def generate_html
|
11
11
|
FileUtils.rm_rf(Rails.root.join('tmp/apidocs'))
|
12
12
|
options = ["app/controllers", "--op=#{Rails.root.join('tmp/apidocs')}"]
|
@@ -20,10 +20,10 @@ module Apidocs
|
|
20
20
|
@last_modified = setup_output_dir @options.op_dir, @options.force_update
|
21
21
|
|
22
22
|
@store.encoding = @options.encoding if @options.respond_to? :encoding
|
23
|
-
@store.dry_run
|
24
|
-
@store.main
|
25
|
-
@store.title
|
26
|
-
@store.path
|
23
|
+
@store.dry_run = @options.dry_run
|
24
|
+
@store.main = @options.main_page
|
25
|
+
@store.title = @options.title
|
26
|
+
@store.path = @options.op_dir
|
27
27
|
|
28
28
|
@start_time = Time.now
|
29
29
|
@store.load_cache
|
@@ -31,18 +31,19 @@ module Apidocs
|
|
31
31
|
|
32
32
|
parse_files @options.files
|
33
33
|
@store.complete @options.visibility
|
34
|
-
|
34
|
+
Apidocs.configuration.regex_filter
|
35
35
|
all_routes = Rails.application.routes.routes
|
36
36
|
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
|
37
|
-
routes = inspector.send(:collect_routes, inspector.send(:filter_routes, nil))
|
37
|
+
routes = inspector.send(:collect_routes, inspector.send(:filter_routes, nil))\
|
38
|
+
.select { |r| r[:reqs] =~ /#/ and (r[:path] =~ Apidocs.configuration.regex_filter) if Apidocs.configuration.regex_filter}
|
38
39
|
|
39
40
|
formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new)
|
40
41
|
|
41
42
|
routes = routes.map do |r|
|
42
|
-
{
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
{verb: r[:verb],
|
44
|
+
path: r[:path].sub('(.:format)', ''),
|
45
|
+
class_name: gen_class_name(r),
|
46
|
+
action_name: gen_action_name(r)
|
46
47
|
}
|
47
48
|
end
|
48
49
|
|
@@ -51,7 +52,7 @@ module Apidocs
|
|
51
52
|
r[:html_comment] = doc ? doc.accept(formatter) : ""
|
52
53
|
end
|
53
54
|
|
54
|
-
routes.select {|r| r[:class_name] != "ApidocsController" }
|
55
|
+
routes.select { |r| r[:class_name] != "ApidocsController" }
|
55
56
|
end
|
56
57
|
|
57
58
|
private
|
@@ -71,6 +72,23 @@ module Apidocs
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
75
|
+
class Configuration
|
76
|
+
attr_accessor :regex_filter, :http_username, :http_password
|
77
|
+
def initialize
|
78
|
+
@regex_filter = /.*/
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class << self
|
83
|
+
attr_writer :configuration
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.configuration
|
87
|
+
@configuration ||= Configuration.new
|
88
|
+
end
|
74
89
|
|
90
|
+
def self.configure
|
91
|
+
yield(configuration)
|
92
|
+
end
|
75
93
|
|
76
94
|
end
|
data/lib/apidocs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apidocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Motsak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|