raddocs 0.5.0 → 1.0.0

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: 51c3f683fc4b32ffe21f3b00883e54ede5f9874d
4
- data.tar.gz: 04fb0bab660edaca38e10723ac9a7ab16ff2b795
3
+ metadata.gz: 5b989901e3d45fb5255c8c9222d1746879b9790b
4
+ data.tar.gz: cc742b1983b7f2e1cdbad403f1e9e35f1197482e
5
5
  SHA512:
6
- metadata.gz: 7236230c824fe40288d3ae3bf972249c056a111789f03db775adecc452b9bdc9d44a92a31fb9adc21c12769cdecdc018d0a1949d6cf9526b0179ad70dbecb18d
7
- data.tar.gz: cd3d939196c54291544192b8e968499f9297947c5526d26ce5dd817c36169c0cd9d6c808d160d3bb6bb543979cff836b68271f24c7edbcd09abd49a6a7f0423a
6
+ metadata.gz: afe31bd9643682f6135d20b25f7d4155e266fd7dee9b4293d1d98c090217f90f6250935c93fb7ffbca154808bc26930c770ee56de33cba4e6c4e1245b7a9629c
7
+ data.tar.gz: 85bf7c3eb4a28549bff99c8a7c5d98495a0104abcbef4b8af1fed83679dd6ac284be03250a323473d8cd869be5d2792bf3aa2ebcb0bd7f9f3230b2d1b5db0fbf
@@ -2,6 +2,7 @@ Encoding.default_external = Encoding::UTF_8
2
2
 
3
3
  require 'sinatra/base'
4
4
  require 'json'
5
+ require 'yaml'
5
6
 
6
7
  require 'raddocs/configuration'
7
8
  require 'raddocs/app'
@@ -1,3 +1,20 @@
1
+ # Load the constant
2
+ module Raddocs
3
+ class App < Sinatra::Base
4
+ class << self
5
+ attr_accessor :markdown
6
+ end
7
+ end
8
+ end
9
+
10
+ begin
11
+ require 'kramdown'
12
+
13
+ Raddocs::App.markdown = true
14
+ rescue LoadError
15
+ # do nothing, we won't load markdown files
16
+ end
17
+
1
18
  module Raddocs
2
19
  # Sinatra app that serves all documentation
3
20
  class App < Sinatra::Base
@@ -22,6 +39,13 @@ module Raddocs
22
39
  File.read(file)
23
40
  end
24
41
 
42
+ if markdown
43
+ get "/guides/*" do
44
+ file = "#{guides_dir}/#{params[:splat][0]}.md"
45
+ erb :guide, locals: { guide: File.read(file) }, layout: false
46
+ end
47
+ end
48
+
25
49
  # Catch all for example pages.
26
50
  # Loads files from the docs dir and appends '.json'.
27
51
  #
@@ -87,6 +111,16 @@ module Raddocs
87
111
  def docs_dir
88
112
  Raddocs.configuration.docs_dir
89
113
  end
114
+
115
+ def guides
116
+ YAML.load(File.read(File.join(guides_dir, "guides.yml"))).map do |guide_hash|
117
+ Guide.new(guide_hash)
118
+ end
119
+ end
120
+
121
+ def guides_dir
122
+ Raddocs.configuration.guides_dir
123
+ end
90
124
  end
91
125
  end
92
126
  end
@@ -29,6 +29,10 @@ module Raddocs
29
29
  # @return [String] defaults to 'doc/api'
30
30
  add_setting :docs_dir, :default => "doc/api"
31
31
 
32
+ # @!attribute guides_dir
33
+ # @return [String] defaults to 'doc/guides'
34
+ add_setting :guides_dir, :default => "doc/guides"
35
+
32
36
  # @!attribute docs_mime_type
33
37
  # @return [Regexp] defaults to Regexp.new("text/docs\+plain")
34
38
  add_setting :docs_mime_type, :default => /text\/docs\+plain/
@@ -62,6 +62,21 @@ module Raddocs
62
62
  end
63
63
  end
64
64
 
65
+ # Guide page model
66
+ class Guide
67
+ attr_reader :title
68
+
69
+ def initialize(attributes)
70
+ @title = attributes.fetch("title")
71
+ @file = attributes.fetch("file")
72
+ end
73
+
74
+ def href
75
+ filename = @file.gsub(".md", "")
76
+ "guides/#{filename}"
77
+ end
78
+ end
79
+
65
80
  # An example's parameters, requires a class because the table can display unknown columns
66
81
  class Parameters
67
82
  attr_reader :extra_keys, :params
@@ -258,6 +273,11 @@ module Raddocs
258
273
  !@request_body.nil?
259
274
  end
260
275
 
276
+ # @return [Boolean] true if request headers are present
277
+ def request_headers?
278
+ request_headers.length > 0
279
+ end
280
+
261
281
  # Request headers must be set
262
282
  # @return [String] Content type of the request
263
283
  def request_content_type
@@ -286,6 +306,11 @@ module Raddocs
286
306
  !@response_body.nil?
287
307
  end
288
308
 
309
+ # @return [Boolean] true if response headers are present
310
+ def response_headers?
311
+ response_headers.length > 0
312
+ end
313
+
289
314
  # Response headers must be set
290
315
  # @return [String] Content type of the response
291
316
  def response_content_type
@@ -1,137 +1,144 @@
1
- :javascript
2
- function mirror(textarea, contentType, options) {
3
- $textarea = $(textarea);
4
- if ($textarea.val() != '') {
5
- if(contentType.indexOf('json') >= 0) {
6
- $textarea.val(JSON.stringify(JSON.parse($textarea.val()), undefined, 2));
7
- options.json = true;
8
- options.mode = 'javascript';
9
- } else if (contentType.indexOf('javascript') >= 0) {
10
- options.mode = 'javascript';
11
- } else if (contentType.indexOf('xml') >= 0) {
12
- options.mode = 'xml';
13
- } else {
14
- options.mode = 'htmlmixed';
15
- }
16
- }
17
- return CodeMirror.fromTextArea(textarea, options);
18
- };
19
-
20
- $(function(){
21
- $(".request .body .content").each(function(i, el) {
22
- el = $(el);
23
- mirror(el.find("textarea")[0], el.data("content-type"), { "readOnly": true, "lineNumbers": true });
24
- });
25
- });
26
-
27
- .nav-bar
28
- = link_to "&laquo; Back to Index", "/"
29
-
30
- %h1== #{example.resource} API
31
- .article
32
- %h2= example.description
33
-
34
- - if example.explanation?
35
- %p.explanation
36
- = example.explanation
37
-
38
- - if example.parameters.present?
39
- %h3 Parameters
40
- %table.parameters
41
- %thead
42
- %tr
43
- %th Name
44
- %th Description
45
- - example.parameters.extra_keys.each do |key|
46
- %th= key
47
- %tbody
48
- - example.parameters.params.each do |param|
49
- %tr.parameter
50
- %td{:class => ("required" if param.required?)}
51
- - if param.scope?
52
- %span.name #{param.scope}[#{param.name}]
53
- - else
54
- %span.name= param.name
55
- %td
56
- %span.description= param.description
57
- - example.parameters.extra_keys.each do |key|
58
- %td
59
- %span.extras= param[key]
60
-
61
- - if example.response_fields.present?
62
- %h3 Response Fields
63
- %table.response-fields
64
- %thead
65
- %tr
66
- %th Name
67
- %th Description
68
- - example.response_fields.extra_keys.each do |key|
69
- %th= key
70
- %tbody
71
- - example.response_fields.fields.each do |field|
72
- %tr.response-field
73
- %td
74
- - if field.scope?
75
- %span.name #{field.scope}[#{field.name}]
76
- - else
77
- %span.name= field.name
78
- %td
79
- %span.description= field.description
80
- - example.response_fields.extra_keys.each do |key|
81
- %td
82
- %span.extras= field[key]
83
-
84
- - example.requests.each_with_index do |request, index|
85
- .request{ :id => "request-#{index}" }
86
- %h3 Request
87
-
88
- %section.headers
89
- %h4 Headers
90
- %pre.headers
91
- :preserve
92
- #{request.request_headers}
93
-
94
- %section.route
95
- %h4 Route
96
- %pre.route.highlight== #{request.request_method} #{request.request_path}
97
-
98
- - if request.request_query_parameters?
99
- %section.query-parameters
100
- %h4 Query Parameters
101
- %pre.query-parameters.highlight
102
- = request.request_query_parameters
103
-
104
- - if request.request_body?
105
- %section.body
106
- %h4 Body
107
- .content{ "data-content-type" => request.request_content_type }
108
- %textarea
109
- :preserve
110
- #{request.request_body}
111
-
112
- - if request.curl?
113
- %section.curl
114
- %h4 cURL
115
- %pre= request.curl
116
-
117
- - if request.response?
118
- .response
119
- %h3 Response
120
-
121
- %section.headers
122
- %h4 Headers
123
- %pre.headers
124
- :preserve
125
- #{request.response_headers}
126
-
127
- %section.status
128
- %h4 Status
129
- %pre.status= request.response_status
130
-
131
- - if request.response_body?
1
+ .row-fluid
2
+ .span4.sidebar
3
+ = haml :nav, locals: { index: index, api_name: api_name }
4
+
5
+ .span10.main
6
+ :javascript
7
+ function mirror(textarea, contentType, options) {
8
+ $textarea = $(textarea);
9
+ if ($textarea.val() != '') {
10
+ if(contentType.indexOf('json') >= 0) {
11
+ $textarea.val(JSON.stringify(JSON.parse($textarea.val()), undefined, 2));
12
+ options.json = true;
13
+ options.mode = 'javascript';
14
+ } else if (contentType.indexOf('javascript') >= 0) {
15
+ options.mode = 'javascript';
16
+ } else if (contentType.indexOf('xml') >= 0) {
17
+ options.mode = 'xml';
18
+ } else {
19
+ options.mode = 'htmlmixed';
20
+ }
21
+ }
22
+ return CodeMirror.fromTextArea(textarea, options);
23
+ };
24
+
25
+ $(function(){
26
+ $(".request .body .content").each(function(i, el) {
27
+ el = $(el);
28
+ mirror(el.find("textarea")[0], el.data("content-type"), { "readOnly": true, "lineNumbers": true });
29
+ });
30
+ });
31
+
32
+ .nav-bar
33
+ = link_to "&laquo; Back to Index", "/"
34
+
35
+ %h1== #{example.resource} API
36
+ .article
37
+ %h2= example.description
38
+
39
+ - if example.explanation?
40
+ %p.explanation
41
+ = example.explanation
42
+
43
+ - if example.parameters.present?
44
+ %h3 Parameters
45
+ %table.parameters
46
+ %thead
47
+ %tr
48
+ %th Name
49
+ %th Description
50
+ - example.parameters.extra_keys.each do |key|
51
+ %th= key
52
+ %tbody
53
+ - example.parameters.params.each do |param|
54
+ %tr.parameter
55
+ %td{:class => ("required" if param.required?)}
56
+ - if param.scope?
57
+ %span.name #{param.scope}[#{param.name}]
58
+ - else
59
+ %span.name= param.name
60
+ %td
61
+ %span.description= param.description
62
+ - example.parameters.extra_keys.each do |key|
63
+ %td
64
+ %span.extras= param[key]
65
+
66
+ - if example.response_fields.present?
67
+ %h3 Response Fields
68
+ %table.response-fields
69
+ %thead
70
+ %tr
71
+ %th Name
72
+ %th Description
73
+ - example.response_fields.extra_keys.each do |key|
74
+ %th= key
75
+ %tbody
76
+ - example.response_fields.fields.each do |field|
77
+ %tr.response-field
78
+ %td
79
+ - if field.scope?
80
+ %span.name #{field.scope}[#{field.name}]
81
+ - else
82
+ %span.name= field.name
83
+ %td
84
+ %span.description= field.description
85
+ - example.response_fields.extra_keys.each do |key|
86
+ %td
87
+ %span.extras= field[key]
88
+
89
+ - example.requests.each_with_index do |request, index|
90
+ .request{ :id => "request-#{index}" }
91
+ %h3 Request
92
+
93
+ - if request.response_headers?
94
+ %section.headers
95
+ %h4 Headers
96
+ %pre.headers
97
+ :preserve
98
+ #{request.request_headers}
99
+
100
+ %section.route
101
+ %h4 Route
102
+ %pre.route.highlight== #{request.request_method} #{request.request_path}
103
+
104
+ - if request.request_query_parameters?
105
+ %section.query-parameters
106
+ %h4 Query Parameters
107
+ %pre.query-parameters.highlight
108
+ = request.request_query_parameters
109
+
110
+ - if request.request_body?
132
111
  %section.body
133
112
  %h4 Body
134
- .content{ "data-content-type" => request.response_content_type }
113
+ .content{ "data-content-type" => request.request_content_type }
135
114
  %textarea
136
115
  :preserve
137
- #{request.response_body}
116
+ #{request.request_body}
117
+
118
+ - if request.curl?
119
+ %section.curl
120
+ %h4 cURL
121
+ %pre= request.curl
122
+
123
+ - if request.response?
124
+ .response
125
+ %h3 Response
126
+
127
+ - if request.response_headers?
128
+ %section.headers
129
+ %h4 Headers
130
+ %pre.headers
131
+ :preserve
132
+ #{request.response_headers}
133
+
134
+ %section.status
135
+ %h4 Status
136
+ %pre.status= request.response_status
137
+
138
+ - if request.response_body?
139
+ %section.body
140
+ %h4 Body
141
+ .content{ "data-content-type" => request.response_content_type }
142
+ %textarea
143
+ :preserve
144
+ #{request.response_body}
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= api_name %></title>
5
+ <% css_files.each do |file| %>
6
+ <link rel="stylesheet" href="<%= file %>" />
7
+ <% end %>
8
+
9
+ <script src="#{url_location}/js/jquery-1-7-2.js"></script>
10
+ <script src="#{url_location}/js/codemirror.js"></script>
11
+ <script src="#{url_location}/js/mode/css/css.js"></script>
12
+ <script src="#{url_location}/js/mode/htmlmixed/htmlmixed.js"></script>
13
+ <script src="#{url_location}/js/mode/javascript/javascript.js"></script>
14
+ <script src="#{url_location}/js/mode/xml/xml.js"></script>
15
+
16
+ <style>
17
+ td.required .name:after {
18
+ float: right;
19
+ content: "required";
20
+ font-weight: normal;
21
+ color: #F08080;
22
+ }
23
+
24
+ p {
25
+ padding: 15px;
26
+ font-size: 130%;
27
+ }
28
+
29
+ nav {
30
+ margin-bottom: 15px;
31
+ }
32
+ </style>
33
+ </head>
34
+ <body>
35
+
36
+ <div class="container">
37
+ <nav>
38
+ <%= link_to "&laquo; Back to Index", "/" %>
39
+ </nav>
40
+
41
+ <%= Kramdown::Document.new(guide, input: "GFM", syntax_highlighter_opts: { line_numbers: false }).to_html %>
42
+ </div>
43
+ </body>
44
+ </html>
@@ -1,5 +1,11 @@
1
1
  %h1= api_name
2
2
 
3
+ %h2 Guides
4
+ %ul.guides
5
+ - guides.each do |guide|
6
+ %li.guide
7
+ = link_to guide.title, "/#{guide.href}"
8
+
3
9
  - index.resources.each do |resource|
4
10
  .resource
5
11
  %h2= resource.name
@@ -2,14 +2,17 @@
2
2
  %html
3
3
  %head
4
4
  %title= api_name
5
+
5
6
  - css_files.each do |file|
6
7
  %link{:rel => "stylesheet", :href => file}
8
+
7
9
  %script(src="#{url_location}/js/jquery-1-7-2.js")
8
10
  %script(src="#{url_location}/js/codemirror.js")
9
11
  %script(src="#{url_location}/js/mode/css/css.js")
10
12
  %script(src="#{url_location}/js/mode/htmlmixed/htmlmixed.js")
11
13
  %script(src="#{url_location}/js/mode/javascript/javascript.js")
12
14
  %script(src="#{url_location}/js/mode/xml/xml.js")
15
+
13
16
  :css
14
17
  td.required .name:after {
15
18
  float: right;
@@ -22,10 +25,7 @@
22
25
  padding: 15px;
23
26
  font-size: 130%;
24
27
  }
28
+
25
29
  %body
26
30
  .container
27
- .row-fluid
28
- .span4.sidebar
29
- = haml :nav, locals: { index: index, api_name: api_name }
30
- .span8.main
31
- = yield
31
+ = yield
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raddocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Oestrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2016-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.3.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.3.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: haml
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -37,9 +31,6 @@ dependencies:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
33
  version: '4.0'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 4.0.4
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +38,6 @@ dependencies:
47
38
  - - "~>"
48
39
  - !ruby/object:Gem::Version
49
40
  version: '4.0'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 4.0.4
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: json
55
43
  requirement: !ruby/object:Gem::Requirement
@@ -57,9 +45,6 @@ dependencies:
57
45
  - - "~>"
58
46
  - !ruby/object:Gem::Version
59
47
  version: '1.8'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.8.1
63
48
  type: :runtime
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
@@ -67,9 +52,6 @@ dependencies:
67
52
  - - "~>"
68
53
  - !ruby/object:Gem::Version
69
54
  version: '1.8'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 1.8.1
73
55
  - !ruby/object:Gem::Dependency
74
56
  name: rspec
75
57
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +108,20 @@ dependencies:
126
108
  - - "~>"
127
109
  - !ruby/object:Gem::Version
128
110
  version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: kramdown
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
129
125
  description: Browse documentation generated by the rspec_api_documentation gem
130
126
  email:
131
127
  - eric@oestrich.org
@@ -148,6 +144,7 @@ files:
148
144
  - lib/raddocs/middleware.rb
149
145
  - lib/raddocs/models.rb
150
146
  - lib/views/example.haml
147
+ - lib/views/guide.erb
151
148
  - lib/views/index.haml
152
149
  - lib/views/layout.haml
153
150
  - lib/views/nav.haml
@@ -171,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
168
  version: 1.3.6
172
169
  requirements: []
173
170
  rubyforge_project:
174
- rubygems_version: 2.2.2
171
+ rubygems_version: 2.5.1
175
172
  signing_key:
176
173
  specification_version: 4
177
174
  summary: rspec_api_documentation browser