yard-rest 1.0.5 → 1.1.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/README.markdown CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  originally by [vWorkApp](http://www.vworkapp.com)
4
4
  rewritten for 0.3.0 by [rknLA](http://github.com/rknLA) with substantial help from [lsegal](http://gnuu.org/)
5
- customized by [spape](http://github.com/spape) for the [MAdeK](http://github.com/zhdk/madek) API-Documentation
5
+ customized by [spape](http://github.com/spape) for the [MAdeK](http://github.com/zhdk/madek) [API-Documentation](http://medienarchiv.zhdk.ch/api)
6
6
 
7
7
  A plugin for [Yardoc](http://yardoc.org/) that generates documentation for RESTful web services.
8
8
 
@@ -11,6 +11,10 @@ A plugin for [Yardoc](http://yardoc.org/) that generates documentation for RESTf
11
11
 
12
12
  It also requires the Jeweler gem if you plan to use the rake build tasks.
13
13
 
14
+ ## Fast Example
15
+
16
+ Run 'rake ex:generate' inside this plugin folder and get a look to the generated doc/index.html.
17
+
14
18
  ## Demo
15
19
 
16
20
  Visit [MAdeK-Api-Documetnation](http://medienarchiv.zhdk.ch/api) for a demonstration. Or visit ROR project [MAdeK](http://github.com/zhdk/madek) on github to see how we document our api.
@@ -36,7 +40,7 @@ You may also include yard-rest in your gemfile using:
36
40
  You may need to include the following dependencies as well:
37
41
 
38
42
  gem 'redcarpet'
39
- gem 'yard', '~>0.7.4'
43
+ gem 'yard', '~>0.8.1'
40
44
 
41
45
  If you include yard-rest in your gemfile, you should generate docs using bundle exec:
42
46
 
@@ -60,14 +64,27 @@ In addition to starting your comment with the normal RDoc description. The follo
60
64
 
61
65
  Examples should always be together in the following order: example_request, example_request_description, example_response, example_response_description (as soon as you write a example_request you need a following example_response and the other way around).
62
66
 
67
+ Markdown rendering for the text is activated if a tags text contains a newline (see example).
68
+
63
69
  - @example_request example. An example of the request that is send to the service.
64
70
 
65
71
  - @example_request_description description. The description text for the example request.
66
72
 
67
73
  - @example_response example. An example of the response that is returned from the service.
68
74
 
69
- - @example_response_description example. The description text for the example response.
75
+ - @example_response example.
76
+ ```json
77
+ {
78
+ "examples": [{
79
+ "id":1,
80
+ "title":"Animals",
81
+ "text":"Dogs and cats are some.",
82
+ "highlight":true
83
+ }]
84
+ }
85
+ ```
70
86
 
87
+ - @example_response_description example. The description text for the example response.
71
88
 
72
89
  ## Ignored Documentation
73
90
 
@@ -84,7 +101,7 @@ Both controller *and* methods must have @resource tags to be included in documen
84
101
  # it's a good example of how European action can produce results | some of these carpets are among the finest examples of the period.
85
102
  #
86
103
  class ExamplesController
87
-
104
+
88
105
  ##
89
106
  # Get a collection of examples:
90
107
  #
@@ -107,13 +124,23 @@ Both controller *and* methods must have @resource tags to be included in documen
107
124
  #
108
125
  # @example_request {"highlight": true}
109
126
  # @example_request_description Request only highlighted examples.
110
- # @example_response {"examples": [{"id":1, "title":"Animals", "text":"Dogs and cats are some.", "highlight":true}]}
127
+ # @example_response
128
+ # ```json
129
+ # {
130
+ # "examples": [{
131
+ # "id":1,
132
+ # "title":"Animals",
133
+ # "text":"Dogs and cats are some.",
134
+ # "highlight":true
135
+ # }]
136
+ # }
137
+ # ```
111
138
  # @example_response_description Responds only with highlighted examples.
112
139
  #
113
140
  def index
114
141
  #...
115
142
  end
116
-
143
+
117
144
  ##
118
145
  # Get a collection of examples:
119
146
  #
@@ -130,13 +157,23 @@ Both controller *and* methods must have @resource tags to be included in documen
130
157
  #
131
158
  # @example_request {"id":1}
132
159
  # @example_request_description Just requests the example with id 1.
133
- # @example_response {"example": {"id":1, "title":"Animals", "text":"Dogs and cats are some.", "highlight":true}}
160
+ # @example_response
161
+ # ```json
162
+ # {
163
+ # "example": {
164
+ # "id":1,
165
+ # "title":"Animals",
166
+ # "text":"Dogs and cats are some.",
167
+ # "highlight":true
168
+ # }
169
+ # }
170
+ # ```
134
171
  # @example_response_description Responds with the requested example.
135
172
  #
136
173
  def show
137
174
  #...
138
175
  end
139
-
176
+
140
177
  ##
141
178
  # Create an example:
142
179
  #
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gem.email = ''
11
11
  gem.homepage = "https://github.com/spape/yard-rest-plugin"
12
12
  gem.authors = ['R. Kevin Nelson', 'Aisha Fenton', 'Sebastian Pape']
13
- gem.add_dependency("yard", '~>0.7.4')
13
+ gem.add_dependency("yard", '~>0.8.1')
14
14
  gem.files = Dir.glob("{lib,example,templates}/**/*").concat(["Rakefile"])
15
15
  gem.extra_rdoc_files = ['VERSION', 'README.markdown']
16
16
  end
@@ -31,7 +31,7 @@ end
31
31
  namespace :ex do
32
32
  desc "Generate example docs"
33
33
  task :generate do
34
- `yardoc 'example/*.rb' --backtrace -e ./lib/yard-rest.rb -r example/README.markdown --title 'Sample API'`
34
+ `yardoc 'example/app/controllers/examples_controller.rb' -e ./lib/yard-rest.rb --title "Our App's API" --readme "example/doc/README_FOR_API"`
35
35
  end
36
36
 
37
37
  desc "Clean example docs"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.5
1
+ 1.1.0
@@ -26,7 +26,17 @@ class ExamplesController
26
26
  #
27
27
  # @example_request {"highlight": true}
28
28
  # @example_request_description Request only highlighted examples.
29
- # @example_response {"examples": [{"id":1, "title":"Animals", "text":"Dogs and cats are some.", "highlight":true}]}
29
+ # @example_response
30
+ # ```json
31
+ # {
32
+ # "examples": [{
33
+ # "id":1,
34
+ # "title":"Animals",
35
+ # "text":"Dogs and cats are some.",
36
+ # "highlight":true
37
+ # }]
38
+ # }
39
+ # ```
30
40
  # @example_response_description Responds only with highlighted examples.
31
41
  #
32
42
  def index
@@ -49,7 +59,17 @@ class ExamplesController
49
59
  #
50
60
  # @example_request {"id":1}
51
61
  # @example_request_description Just requests the example with id 1.
52
- # @example_response {"example": {"id":1, "title":"Animals", "text":"Dogs and cats are some.", "highlight":true}}
62
+ # @example_response
63
+ # ```json
64
+ # {
65
+ # "example": {
66
+ # "id":1,
67
+ # "title":"Animals",
68
+ # "text":"Dogs and cats are some.",
69
+ # "highlight":true
70
+ # }
71
+ # }
72
+ # ```
53
73
  # @example_response_description Responds with the requested example.
54
74
  #
55
75
  def show
@@ -6,7 +6,7 @@
6
6
  <h3 class="resource_url"><strong><%= meth.tag(:resource).text %></strong> [<%= meth.tag(:action).text %>]</h3>
7
7
 
8
8
  <div class="parameters">
9
- <% if meth.tags(:required).size %>
9
+ <% if meth.tags(:required).size > 0 %>
10
10
  <div class="required">
11
11
  <h4>Required Parameters</h4>
12
12
  <% meth.tags(:required).each do |required| %>
@@ -21,7 +21,7 @@
21
21
  </div>
22
22
  <% end %>
23
23
 
24
- <% if meth.tags(:optional).size %>
24
+ <% if meth.tags(:optional).size > 0 %>
25
25
  <div class="optional">
26
26
  <h4>Optional Parameters</h4>
27
27
  <% meth.tags(:optional).each do |optional| %>
@@ -37,7 +37,7 @@
37
37
  <% end %>
38
38
  </div><!-- parameters -->
39
39
 
40
- <% if meth.tags(:response_field).size %>
40
+ <% if meth.tags(:response_field).size > 0 %>
41
41
  <div class="response_fields">
42
42
  <h4>Response Fields</h4>
43
43
  <% meth.tags(:response_field).each do |response_field| %>
@@ -52,7 +52,7 @@
52
52
  </div>
53
53
  <% end %>
54
54
 
55
- <% if meth.tags(:example_request).size %>
55
+ <% if meth.tags(:example_request).size > 0 %>
56
56
  <div class="examples">
57
57
  <h4>Examples</h4>
58
58
  <% meth.tags(:example_request).each_with_index do |example_request, i| %>
@@ -60,16 +60,44 @@
60
60
  <% example_request_description = meth.tags(:example_request_description)[i] %>
61
61
  <% example_response = meth.tags(:example_response)[i] %>
62
62
  <% example_response_description = meth.tags(:example_response_description)[i] %>
63
- <span class="description"><%= (example_request_description.nil?) ? "" : example_request_description.text %></span>
63
+ <span class="description">
64
+ <% if example_request_description %>
65
+ <% if example_request_description.text =~ /\n/im %>
66
+ <%= htmlify(example_request_description.text, :markdown) %>
67
+ <% else %>
68
+ <%= example_request_description.text %>
69
+ <% end %>
70
+ <% end %>
71
+ </span>
64
72
  <span class="hash request">
65
73
  <strong class="type">Request</strong>
66
- <%= (example_request.nil?) ? "" : example_request.text %>
74
+ <% if example_request %>
75
+ <% if example_request.text =~ /\n/im %>
76
+ <%= htmlify(example_request.text, :markdown) %>
77
+ <% else %>
78
+ <%= example_request.text %>
79
+ <% end %>
80
+ <% end %>
67
81
  </span>
68
82
  <span class="hash response">
69
83
  <strong class="type">Response</strong>
70
- <%= (example_response.nil?) ? "" : example_response.text %>
84
+ <% if example_response %>
85
+ <% if example_response.text =~ /\n/im %>
86
+ <%= htmlify(example_response.text, :markdown) %>
87
+ <% else %>
88
+ <%= example_response.text %>
89
+ <% end %>
90
+ <% end %>
91
+ </span>
92
+ <span class="description">
93
+ <% if example_response_description %>
94
+ <% if example_response_description.text =~ /\n/im %>
95
+ <%= htmlify(example_response_description.text, :markdown) %>
96
+ <% else %>
97
+ <%= example_response_description.text %>
98
+ <% end %>
99
+ <% end %>
71
100
  </span>
72
- <span class="description"><%= (example_response_description.nil?) ? "" : example_response_description.text %></span>
73
101
  </div>
74
102
  <% end %>
75
103
  </div>
@@ -130,10 +130,38 @@
130
130
  border-top-left-radius: 0;
131
131
  border-top-right-radius: 0;
132
132
  }
133
+
134
+ pre {
135
+ margin: 0;
136
+ }
137
+
138
+ pre code {
139
+ position: relative;
140
+ border: 1px solid transparent;
141
+ border-radius: 6px;
142
+ }
143
+
144
+ pre code:hover {
145
+ background: #d4e5fe;
146
+ }
147
+
148
+ pre code:active {
149
+ background: #c1d8fb;
150
+ }
133
151
  </style>
134
152
  <script type="text/javascript">
135
153
  //<![CDATA[
136
154
 
155
+ function setup_log() {
156
+ $("pre.code.json").attr("title", "click to inspect in browser debugger: console.log()");
157
+ $("pre.code.json").css("cursor", "pointer");
158
+ $("pre.code.json").click(function(){
159
+ var code = $(this).find("code");
160
+ console.log(code.html());
161
+ console.log(JSON.parse(code.html()));
162
+ });
163
+ }
164
+
137
165
  function setup_toc() {
138
166
  if ($('#content').length === 0) return;
139
167
  var _toc = $('<ol class="top"></ol>');
@@ -186,7 +214,10 @@
186
214
  $('#toc').toggleClass('nofloat');
187
215
  });
188
216
  }
189
- $(document).ready(setup_toc);
217
+ $(document).ready(function(){
218
+ setup_toc();
219
+ setup_log();
220
+ });
190
221
  //]]>
191
222
  </script>
192
223
  </head>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-04-30 00:00:00.000000000 Z
14
+ date: 2012-05-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: yard
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.7.4
23
+ version: 0.8.1
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ~>
30
30
  - !ruby/object:Gem::Version
31
- version: 0.7.4
31
+ version: 0.8.1
32
32
  description: A customized plugin for Yardoc that produces API documentation for Restful
33
33
  web services
34
34
  email: ''