raddocs 0.1.4 → 0.2.0
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.
- data/lib/public/application.css +5 -0
- data/lib/raddocs.rb +1 -0
- data/lib/raddocs/app.rb +29 -0
- data/lib/raddocs/configuration.rb +2 -0
- data/lib/raddocs/parameters.rb +16 -0
- data/lib/views/example.haml +15 -3
- data/lib/views/layout.haml +2 -3
- metadata +4 -3
data/lib/public/application.css
CHANGED
data/lib/raddocs.rb
CHANGED
data/lib/raddocs/app.rb
CHANGED
@@ -8,6 +8,17 @@ module Raddocs
|
|
8
8
|
haml :index, :locals => { :index => index }
|
9
9
|
end
|
10
10
|
|
11
|
+
get "/custom-css/*" do
|
12
|
+
file = "#{docs_dir}/styles/#{params[:splat][0]}"
|
13
|
+
|
14
|
+
if !File.exists?(file)
|
15
|
+
raise Sinatra::NotFound
|
16
|
+
end
|
17
|
+
|
18
|
+
content_type :css
|
19
|
+
File.read(file)
|
20
|
+
end
|
21
|
+
|
11
22
|
get "/*" do
|
12
23
|
file = "#{docs_dir}/#{params[:splat][0]}.json"
|
13
24
|
|
@@ -18,6 +29,7 @@ module Raddocs
|
|
18
29
|
file_content = File.read(file)
|
19
30
|
|
20
31
|
example = JSON.parse(file_content)
|
32
|
+
example["parameters"] = Parameters.new(example["parameters"]).parse
|
21
33
|
haml :example, :locals => { :example => example }
|
22
34
|
end
|
23
35
|
|
@@ -37,6 +49,23 @@ module Raddocs
|
|
37
49
|
def api_name
|
38
50
|
Raddocs.configuration.api_name
|
39
51
|
end
|
52
|
+
|
53
|
+
def css_files
|
54
|
+
files = ["#{url_location}/codemirror.css", "#{url_location}/application.css"]
|
55
|
+
|
56
|
+
if Raddocs.configuration.include_bootstrap
|
57
|
+
files << "#{url_location}/bootstrap.min.css"
|
58
|
+
end
|
59
|
+
|
60
|
+
Dir.glob(File.join(docs_dir, "styles", "*.css")).each do |css_file|
|
61
|
+
basename = Pathname.new(css_file).basename
|
62
|
+
files << "#{url_location}/custom-css/#{basename}"
|
63
|
+
end
|
64
|
+
|
65
|
+
files.concat Array(Raddocs.configuration.external_css)
|
66
|
+
|
67
|
+
files
|
68
|
+
end
|
40
69
|
end
|
41
70
|
|
42
71
|
def docs_dir
|
@@ -16,6 +16,8 @@ module Raddocs
|
|
16
16
|
add_setting :docs_dir, :default => "docs"
|
17
17
|
add_setting :docs_mime_type, :default => /text\/docs\+plain/
|
18
18
|
add_setting :api_name, :default => "Api Documentation"
|
19
|
+
add_setting :include_bootstrap, :default => true
|
20
|
+
add_setting :external_css, :default => []
|
19
21
|
|
20
22
|
def settings
|
21
23
|
@settings ||= {}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Raddocs
|
2
|
+
class Parameters
|
3
|
+
def initialize(params)
|
4
|
+
@params = params
|
5
|
+
end
|
6
|
+
|
7
|
+
def parse
|
8
|
+
extra_keys = @params.flat_map(&:keys).uniq - ["name", "description", "required", "scope"]
|
9
|
+
|
10
|
+
{
|
11
|
+
"extra_keys" => extra_keys,
|
12
|
+
"data" => @params
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/views/example.haml
CHANGED
@@ -24,6 +24,9 @@
|
|
24
24
|
});
|
25
25
|
});
|
26
26
|
|
27
|
+
.nav-bar
|
28
|
+
= link_to "« Back to Index", "/"
|
29
|
+
|
27
30
|
%h1== #{example["resource"]} API
|
28
31
|
.article
|
29
32
|
%h2= example["description"]
|
@@ -32,20 +35,29 @@
|
|
32
35
|
%p.explanation
|
33
36
|
= example["explanation"]
|
34
37
|
|
35
|
-
- if example["parameters"].count > 0
|
38
|
+
- if example["parameters"]["data"].count > 0
|
36
39
|
%h3 Parameters
|
37
40
|
%table.parameters
|
38
41
|
%thead
|
39
42
|
%tr
|
40
43
|
%th Name
|
41
44
|
%th Description
|
45
|
+
- example["parameters"]["extra_keys"].each do |key|
|
46
|
+
%th= key
|
42
47
|
%tbody
|
43
|
-
- example["parameters"].each do |param|
|
48
|
+
- example["parameters"]["data"].each do |param|
|
44
49
|
%tr.parameter
|
45
50
|
%td{:class => ("required" if param["required"])}
|
46
|
-
|
51
|
+
- if param["scope"]
|
52
|
+
%span.name #{param['scope']}[#{param["name"]}]
|
53
|
+
- else
|
54
|
+
%span.name= param["name"]
|
47
55
|
%td
|
48
56
|
%span.description= param["description"]
|
57
|
+
- example["parameters"]["extra_keys"].each do |key|
|
58
|
+
%td
|
59
|
+
%span.extras= param[key]
|
60
|
+
|
49
61
|
|
50
62
|
- example["requests"].each_with_index do |request, index|
|
51
63
|
.request{ :id => "request-#{index}" }
|
data/lib/views/layout.haml
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
%html
|
3
3
|
%head
|
4
4
|
%title Raddocs
|
5
|
-
|
6
|
-
|
7
|
-
%link{:rel => "stylesheet", :href => "#{url_location}/application.css"}
|
5
|
+
- css_files.each do |file|
|
6
|
+
%link{:rel => "stylesheet", :href => file}
|
8
7
|
%script(src="#{url_location}/js/jquery-1-7-2.js")
|
9
8
|
%script(src="#{url_location}/js/codemirror.js")
|
10
9
|
%script(src="#{url_location}/js/mode/css/css.js")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raddocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/raddocs/app.rb
|
143
143
|
- lib/raddocs/configuration.rb
|
144
144
|
- lib/raddocs/middleware.rb
|
145
|
+
- lib/raddocs/parameters.rb
|
145
146
|
- lib/raddocs.rb
|
146
147
|
- lib/views/example.haml
|
147
148
|
- lib/views/index.haml
|
@@ -166,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
167
|
version: 1.3.6
|
167
168
|
requirements: []
|
168
169
|
rubyforge_project:
|
169
|
-
rubygems_version: 1.8.
|
170
|
+
rubygems_version: 1.8.23
|
170
171
|
signing_key:
|
171
172
|
specification_version: 3
|
172
173
|
summary: Browse documentation generated by the rspec_api_documentation gem
|