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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bfe483d12b61ff4f45099d88d9c8718f821174d
4
- data.tar.gz: 582aaeb27ea6b21ddf24123401431dcb1e2f04aa
3
+ metadata.gz: 73da5aca8b695e550bfc631d3f42fe6e6a585e2f
4
+ data.tar.gz: 39f4d0400b003afa6800405a4b3c3d00e7de5007
5
5
  SHA512:
6
- metadata.gz: f466a7b4fa9578aa603d39e1b19c833ee8f4063625bce6a03fc36d196aa208d21f6854eb729f6997fae0cd037d276064f19ef7bb1fb397ec57603986db8c7611
7
- data.tar.gz: e50172ab4831f655fe508f9416241af2767968d8aaf560361832ef5353f69d4c8fbab3b498a722fc9102cb86234af52aaeaf2d359463d04b1f2bddbe8724c70f
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 <code>mount Apidocs::Engine => "/apidocs"</code> to your applications <code>routes.rb</code>
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
- $("#nav-button").click(function () {
3
- $.get(this.getAttribute("href"), function (data) {
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
+ });
@@ -19,4 +19,9 @@ pre {
19
19
  #main-content h2 a,
20
20
  #main-content h1 a {
21
21
  display: none;
22
+ }
23
+
24
+ ul#search-list li {
25
+ text-overflow: ellipsis;
26
+ overflow: hidden;
22
27
  }
@@ -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="Search">
17
+ <input type="text" value='<%= @searchinput %>' class="search-query" id="search-input" placeholder="Filter">
18
18
  </div>
19
19
  </form>
20
20
  </div>
@@ -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 entry point for on fly document generation
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 = @options.dry_run
24
- @store.main = @options.main_page
25
- @store.title = @options.title
26
- @store.path = @options.op_dir
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)).select {|r| r[:reqs] =~ /#/}
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
- { verb: r[:verb],
43
- path: r[:path].sub('(.:format)',''),
44
- class_name: gen_class_name(r),
45
- action_name: gen_action_name(r)
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
@@ -1,3 +1,3 @@
1
1
  module Apidocs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-15 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails