useless-doc 0.6.5 → 0.7.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: ba3662a9c3ab173c8820de546884c0bd66fb088e
4
- data.tar.gz: 694e5e39110439e113372740c7ce0b7bf297825f
3
+ metadata.gz: 8ef1a097ee5d9addd33af7c1fe5c79364d438284
4
+ data.tar.gz: d85d7c813564eddc5718549d7c205684760f481a
5
5
  SHA512:
6
- metadata.gz: 1f51ce037bc2fa57ad44a202a0db3debd8ce793d4d994e2f4a788b2e41b81f8718609a9b14a17b80a0758204d5acb84bac6cf300c5f7c2d73f1655686965b0b4
7
- data.tar.gz: 9ce2dddf8b6deb173baa43cd8df40aa23b52498af3522f2d3e60a4b9e1f94b7553041416c169945fe88944159b2649ea8212cda6d374da1eb648d8b1bf501c97
6
+ metadata.gz: 4225d239755a926606513739e7ede9d92d4d289d1c6802cd0753429c434ae19f6a7d1e35812472ecf76c2c7d8ff315b23d0b6dabbc37d5c7ad98a516371b8053
7
+ data.tar.gz: 4a5273f15009e401bea7b39a8d672cf202ab7108f38a1fede74b48dd73bf7043070fda87420f3240246ebf56a259ae19a7a7b46344556a33f6fd50f5eae7dc3f
@@ -34,15 +34,21 @@ module Useless
34
34
  #
35
35
  # @!attribute [r] required
36
36
  # @return [Boolean] whether or not the attribute is required. If it
37
- # is required, and the attribute is omitted, the response should have
38
- # a 4xx code. +true+ is the default value.
37
+ # is required, and the attribute is omitted, the response should
38
+ # have a 4xx code. +true+ is the default value.
39
39
  #
40
40
  # @!attribute [r] description
41
41
  # @return [String] a description of the attribute.
42
42
  #
43
+ # @!attribute [r] attributes
44
+ # @return [Array<Body::Attribute>] documentation for the
45
+ # sub-attributes of this attribute. An empty array is the default
46
+ # value.
47
+ #
43
48
  class Attribute
44
49
 
45
- attr_reader :key, :type, :required, :default, :description
50
+ attr_reader :key, :type, :required, :default, :description,
51
+ :attributes
46
52
 
47
53
  # @param [Hash] attrs corresponds to the class's instance attributes.
48
54
  #
@@ -52,6 +58,7 @@ module Useless
52
58
  @required = attrs.key?(:required) ? attrs[:required] : true
53
59
  @default = attrs[:default]
54
60
  @description = attrs[:description]
61
+ @attributes = attrs[:attributes] || []
55
62
  end
56
63
  end
57
64
  end
@@ -325,8 +325,11 @@ module Useless
325
325
  @attributes[:content_type] = value
326
326
  end
327
327
 
328
- def attribute(key, description, attributes = {})
329
- attribute = Doc::Core::Body::Attribute.new attributes.merge(key: key, description: description)
328
+ def attribute(key, description, attributes = {}, &block)
329
+ subbody = Body.build({}, &block)
330
+ attribute = Doc::Core::Body::Attribute.new attributes.merge(
331
+ key: key, description: description, attributes: subbody.attributes
332
+ )
330
333
  @attributes[:attributes] << attribute
331
334
  end
332
335
  end
@@ -156,7 +156,8 @@ module Useless
156
156
  'type' => attribute.type,
157
157
  'required' => attribute.required,
158
158
  'default' => attribute.default,
159
- 'description' => attribute.description
159
+ 'description' => attribute.description,
160
+ 'attributes' => attribute.attributes.map { |attribute| body_attribute(attribute) }
160
161
  end
161
162
  end
162
163
 
@@ -234,12 +234,17 @@ module Useless
234
234
  def self.body_attribute(json)
235
235
  hash = json_to_hash json
236
236
 
237
+ attributes = (hash['attributes'] || []).map do |json|
238
+ body_attribute json
239
+ end
240
+
237
241
  Useless::Doc::Core::Body::Attribute.new \
238
242
  key: hash['key'],
239
243
  type: hash['type'],
240
244
  required: hash['required'],
241
245
  default: hash['default'],
242
- description: hash['description']
246
+ description: hash['description'],
247
+ attributes: attributes
243
248
  end
244
249
  end
245
250
  end
@@ -175,7 +175,8 @@ module Useless
175
175
  class Response
176
176
  extend Forwardable
177
177
 
178
- def_delegators :@response, :code, :description, :headers, :body
178
+ def_delegators :@response, :code, :description, :headers, :body,
179
+ :attributes
179
180
 
180
181
  def initialize(response)
181
182
  @response = response
@@ -96,6 +96,26 @@
96
96
  <td>{{required}}</td>
97
97
  <td>{{default}}</td>
98
98
  </tr>
99
+
100
+ {{#attributes}}
101
+ <tr class="sub-attribute">
102
+ <td>{{key}}</td>
103
+ <td>{{description}}</td>
104
+ <td>{{type}}</td>
105
+ <td>{{required}}</td>
106
+ <td>{{default}}</td>
107
+ </tr>
108
+
109
+ {{#attributes}}
110
+ <tr class="sub-sub-attribute">
111
+ <td>{{key}}</td>
112
+ <td>{{description}}</td>
113
+ <td>{{type}}</td>
114
+ <td>{{required}}</td>
115
+ <td>{{default}}</td>
116
+ </tr>
117
+ {{/attributes}}
118
+ {{/attributes}}
99
119
  {{/attributes}}
100
120
  </tbody>
101
121
  </table>
@@ -153,6 +173,26 @@
153
173
  <td>{{required}}</td>
154
174
  <td>{{default}}</td>
155
175
  </tr>
176
+
177
+ {{#attributes}}
178
+ <tr class="sub-attribute">
179
+ <td>{{key}}</td>
180
+ <td>{{description}}</td>
181
+ <td>{{type}}</td>
182
+ <td>{{required}}</td>
183
+ <td>{{default}}</td>
184
+ </tr>
185
+
186
+ {{#attributes}}
187
+ <tr class="sub-sub-attribute">
188
+ <td>{{key}}</td>
189
+ <td>{{description}}</td>
190
+ <td>{{type}}</td>
191
+ <td>{{required}}</td>
192
+ <td>{{default}}</td>
193
+ </tr>
194
+ {{/attributes}}
195
+ {{/attributes}}
156
196
  {{/attributes}}
157
197
  </tbody>
158
198
  </table>
@@ -37,6 +37,10 @@ h3 span.status-message {
37
37
  font-weight: normal;
38
38
  }
39
39
 
40
+ h4 {
41
+ font-size: 1.25em;
42
+ }
43
+
40
44
  h4 span.content-type {
41
45
  font-weight: normal;
42
46
  font-family: 'Open Sans';
@@ -191,6 +195,22 @@ table tbody tr:last-child td, table tbody tr:last-child th {
191
195
  border-bottom-width: 0;
192
196
  }
193
197
 
198
+ table tr.sub-attribute {
199
+ background-color: #EEE;
200
+ }
201
+
202
+ table tr.sub-attribute td:first-child {
203
+ padding-left: 1.5em;
204
+ }
205
+
206
+ table tr.sub-sub-attribute {
207
+ background-color: #DDD;
208
+ }
209
+
210
+ table tr.sub-sub-attribute td:first-child {
211
+ padding-left: 3em;
212
+ }
213
+
194
214
  table.stages {
195
215
  margin-top: 2em;
196
216
  }
@@ -1,5 +1,5 @@
1
1
  module Useless
2
2
  module Doc
3
- VERSION = '0.6.5'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
@@ -48,7 +48,27 @@
48
48
  "key": "created_by",
49
49
  "type": "object",
50
50
  "required": true,
51
- "description": "The short name of the user who created the twonk."
51
+ "description": "The user who created this twonk.",
52
+ "attributes": [
53
+ {
54
+ "key": "id",
55
+ "type": "number",
56
+ "required": true,
57
+ "description": "The unique ID of the user."
58
+ },
59
+ {
60
+ "key": "short_name",
61
+ "type": "string",
62
+ "required": true,
63
+ "description": "A user-friendly handle for the user."
64
+ }
65
+ ]
66
+ },
67
+ {
68
+ "key": "title",
69
+ "type": "string",
70
+ "required": false,
71
+ "description": "The formal title of this twonk"
52
72
  }
53
73
  ]
54
74
  }
@@ -62,6 +62,9 @@ describe Useless::Doc::DSL::API do
62
62
  attribute 'name', 'The name of the widget', required: true
63
63
  attribute 'age', 'The age of the widget. If missing, the widget was never born',
64
64
  type: :number, required: false
65
+ attribute 'owner', 'The owner of this widget', type: 'object' do
66
+ attribute 'nickname', 'The nickname of the owner'
67
+ end
65
68
  end
66
69
  end
67
70
  end
@@ -110,6 +113,7 @@ describe Useless::Doc::DSL::API do
110
113
  collection.requests[0].method.should == 'GET'
111
114
  collection.requests[0].headers[0].description.should == 'The twiddle threshold.'
112
115
  collection.requests[0].responses[1].code.should == 200
116
+ collection.requests[0].responses[1].body.attributes[2].attributes[0].key.should == 'nickname'
113
117
  collection.requests[1].method.should == 'POST'
114
118
  collection.requests[1].description.should == 'Creates a new widget'
115
119
  collection.requests[1].body.content_type.should == 'application/json'
@@ -112,12 +112,20 @@ describe Useless::Doc::Serialization::Dump do
112
112
  key: 'Type',
113
113
  description: 'The response type.'
114
114
 
115
+ get_response_body_subattribute = Useless::Doc::Core::Body::Attribute.new \
116
+ key: 'nickname',
117
+ type: 'string',
118
+ required: true,
119
+ default: nil,
120
+ description: 'The nickname of the user'
121
+
115
122
  get_response_body_attribute = Useless::Doc::Core::Body::Attribute.new \
116
123
  key: 'name',
117
124
  type: 'string',
118
125
  required: true,
119
126
  default: nil,
120
- description: 'The name of the twiddle.'
127
+ description: 'The name of the twiddle.',
128
+ attributes: [get_response_body_subattribute]
121
129
 
122
130
  get_response_body = Useless::Doc::Core::Body.new \
123
131
  content_type: 'application/json',
@@ -193,6 +201,13 @@ describe Useless::Doc::Serialization::Dump do
193
201
  get_request_body_attribute_hash['required'].should == true
194
202
  get_request_body_attribute_hash['default'].should be_nil
195
203
  get_request_body_attribute_hash['description'].should == 'The name of the twiddle.'
204
+
205
+ get_request_body_subattribute_hash = Useless::Doc::Serialization::Load.json_to_hash(get_request_body_attribute_hash['attributes'][0])
206
+ get_request_body_subattribute_hash['key'].should == 'nickname'
207
+ get_request_body_subattribute_hash['type'].should == 'string'
208
+ get_request_body_subattribute_hash['required'].should == true
209
+ get_request_body_subattribute_hash['default'].should be_nil
210
+ get_request_body_subattribute_hash['description'].should == 'The nickname of the user'
196
211
  end
197
212
  end
198
213
 
@@ -119,7 +119,9 @@ describe Useless::Doc::Serialization::Load do
119
119
  get.responses[1].body.attributes[1].type.should == 'object'
120
120
  get.responses[1].body.attributes[1].required.should be_true
121
121
  get.responses[1].body.attributes[1].default.should be_nil
122
- get.responses[1].body.attributes[1].description.should == 'The short name of the user who created the twonk.'
122
+ get.responses[1].body.attributes[1].description.should == 'The user who created this twonk.'
123
+ get.responses[1].body.attributes[1].attributes[0].key.should == 'id'
124
+ get.responses[1].body.attributes[1].attributes[1].key.should == 'short_name'
123
125
 
124
126
  put = resource.requests.last
125
127
  put.method.should == 'PUT'
@@ -188,7 +188,7 @@ describe Useless::Doc::UI::Godel do
188
188
  it 'should add body information to a table' do
189
189
  [
190
190
  { key: 'name', description: 'The name of the twonk.' },
191
- { key: 'created_by', description: 'The short name of the user who created the twonk.' },
191
+ { key: 'created_by', description: 'The user who created this twonk.' },
192
192
  { key: 'hoinked_by', description: 'The ID of the person who hoinked this twonk.' }
193
193
  ].each do |attribute|
194
194
  @doc.css('table').find do |table|
@@ -198,6 +198,18 @@ describe Useless::Doc::UI::Godel do
198
198
  end
199
199
  end
200
200
 
201
+ it 'should add body sub-attributes to a special table row' do
202
+ [
203
+ { key: 'id', description: 'The unique ID of the user.' },
204
+ { key: 'short_name', description: 'A user-friendly handle for the user.' },
205
+ ].each do |attribute|
206
+ @doc.css('table tr.sub-attribute').find do |table|
207
+ table.content.match(attribute[:key]) and
208
+ table.content.match(attribute[:description])
209
+ end.should_not be_nil
210
+ end
211
+ end
212
+
201
213
  it 'should add header information to a table' do
202
214
  @doc.css('table').find do |table|
203
215
  table.content.match('User-Agent') and
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useless-doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Hyland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-06 00:00:00.000000000 Z
11
+ date: 2013-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj