useless-doc 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,9 +19,19 @@ module Useless
19
19
  # @!attribute [r] resources
20
20
  # @return [Array<Resource>] the resources included in the API.
21
21
  #
22
+ # @!attribute [r] concept
23
+ # @return [Stage] a `Core::Stage` instance for the API concept.
24
+ #
25
+ # @!attribute [r] specification
26
+ # @return [Stage] a `Core::Stage` instance for the API specification.
27
+ #
28
+ # @!attribute [r] implementation
29
+ # @return [Stage] a `Core::Stage` instance for the API implementation.
30
+ #
22
31
  class API
23
32
 
24
- attr_accessor :name, :url, :description, :timestamp, :resources
33
+ attr_accessor :name, :url, :description, :timestamp, :resources,
34
+ :concept, :specification, :implementation
25
35
 
26
36
  # @param [Hash] attrs corresponds to the class's instance attributes.
27
37
  #
@@ -31,6 +41,9 @@ module Useless
31
41
  @description = attrs[:description]
32
42
  @timestamp = attrs[:timestamp]
33
43
  @resources = attrs[:resources] || []
44
+ @concept = attrs[:concept]
45
+ @specification = attrs[:specification]
46
+ @implementation = attrs[:implementation]
34
47
  end
35
48
  end
36
49
  end
@@ -0,0 +1,29 @@
1
+ module Useless
2
+ module Doc
3
+ module Core
4
+
5
+ # `Core::Stage` documents credit and progress of a stage in the
6
+ # development of an API. For example, a stage is one of "concept",
7
+ # "specification" or "implementation" in `Core::API`.
8
+ #
9
+ # @!attribute [r] credit
10
+ # @return [Array<String>] names of the people responsible for this
11
+ # stage.
12
+ #
13
+ # @!attribute [r] progress
14
+ # @return [String] a string identifying how far the stage has
15
+ # progressed.
16
+ #
17
+ class Stage
18
+ attr_accessor :credit, :progress
19
+
20
+ # @param [Hash] attrs corresponds to the class's instance attributes.
21
+ #
22
+ def initialize(attrs = {})
23
+ @credit = attrs[:credit] || []
24
+ @progress = attrs[:progress]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -48,7 +48,24 @@ module Useless
48
48
  'url' => api.url,
49
49
  'description' => api.description,
50
50
  'timestamp' => api.timestamp ? api.timestamp.iso8601 : nil,
51
- 'resources' => api.resources.map { |resource| resource(resource) }
51
+ 'resources' => api.resources.map { |resource| resource(resource) },
52
+ 'concept' => stage(api.concept),
53
+ 'specification' => stage(api.specification),
54
+ 'implementation' => stage(api.implementation)
55
+ end
56
+ end
57
+
58
+ # Converts +Core::Stage+ instance to a JSON representation.
59
+ #
60
+ # @param [Core::Stage] stage the stage to be converted to JSON.
61
+ #
62
+ # @return [String] a JSON representation of the specified stage.
63
+ #
64
+ def self.stage(stage)
65
+ if stage
66
+ hash_to_json \
67
+ 'credit' => stage.credit,
68
+ 'progress' => stage.progress
52
69
  end
53
70
  end
54
71
 
@@ -6,6 +6,7 @@ require 'useless/doc/core/header'
6
6
  require 'useless/doc/core/request'
7
7
  require 'useless/doc/core/resource'
8
8
  require 'useless/doc/core/response'
9
+ require 'useless/doc/core/stage'
9
10
 
10
11
  module Useless
11
12
  module Doc
@@ -86,12 +87,43 @@ module Useless
86
87
  nil
87
88
  end
88
89
 
90
+ if hash['concept']
91
+ concept = stage hash['concept']
92
+ end
93
+
94
+ if hash['specification']
95
+ specification = stage hash['specification']
96
+ end
97
+
98
+ if hash['implementation']
99
+ implementation = stage hash['implementation']
100
+ end
101
+
89
102
  Useless::Doc::Core::API.new \
90
- name: hash['name'],
91
- url: hash['url'],
92
- timestamp: timestamp,
93
- description: hash['description'],
94
- resources: resources
103
+ name: hash['name'],
104
+ url: hash['url'],
105
+ timestamp: timestamp,
106
+ description: hash['description'],
107
+ resources: resources,
108
+ concept: concept,
109
+ specification: specification,
110
+ implementation: implementation
111
+ end
112
+
113
+ # Converts a JSON representation to an instance of +Core::Stage+
114
+ #
115
+ # @param [String, Hash] json the JSON representation to be converted to
116
+ # a stage.
117
+ #
118
+ # @return [Core::Resource] the stage corresponding to the specified
119
+ # JSON.
120
+ #
121
+ def self.stage(json)
122
+ hash = json_to_hash json
123
+
124
+ Useless::Doc::Core::Stage.new \
125
+ credit: hash['credit'],
126
+ progress: hash['progress']
95
127
  end
96
128
 
97
129
  # Converts a JSON represntation to an instance of +Core::Resource+
@@ -32,6 +32,45 @@
32
32
  <section class="main description">
33
33
  <article class="description api">
34
34
  {{{description}}}
35
+
36
+ <table class="stages">
37
+ <thead>
38
+ <th>Specification</th>
39
+ <th>Implementation</th>
40
+ <th>Concept</th>
41
+ <tbody>
42
+ <tr>
43
+ <td>
44
+ {{#specification}}
45
+ {{progress}}
46
+ {{/specification}}
47
+ </td>
48
+ <td>
49
+ {{#implementation}}
50
+ {{progress}}
51
+ {{/implementation}}
52
+ </td>
53
+ <td class="concept-credit" rowspan=2>
54
+ {{#concept}}
55
+ {{credit}}
56
+ {{/concept}}
57
+ </td>
58
+ </tr>
59
+
60
+ <tr>
61
+ <td>
62
+ {{#specification}}
63
+ {{credit}}
64
+ {{/specification}}
65
+ </td>
66
+ <td class="implementation-credit">
67
+ {{#implementation}}
68
+ {{credit}}
69
+ {{/implementation}}
70
+ </td>
71
+ </tr>
72
+ </tbody>
73
+ </table>
35
74
  </article>
36
75
  </section>
37
76
 
@@ -163,3 +163,19 @@ table td:last-child, table th:last-child {
163
163
  table tbody tr:last-child td, table tbody tr:last-child th {
164
164
  border-bottom-width: 0;
165
165
  }
166
+
167
+ table.stages {
168
+ margin-top: 2em;
169
+ }
170
+
171
+ table.stages td, table.stages th {
172
+ padding: 0.5em 1em;
173
+ }
174
+
175
+ table.stages td.implementation-credit {
176
+ border-right: 1px solid #DDD;
177
+ }
178
+
179
+ table.stages td.concept-credit {
180
+ border-bottom-width: 0;
181
+ }
@@ -89,6 +89,24 @@ module Useless
89
89
  def resources
90
90
  @api.resources.map{ |resource| Godel::Resource.new(resource, @router) }
91
91
  end
92
+
93
+ def concept
94
+ if @api.concept
95
+ Godel::Stage.new(@api.concept)
96
+ end
97
+ end
98
+
99
+ def specification
100
+ if @api.specification
101
+ Godel::Stage.new(@api.specification)
102
+ end
103
+ end
104
+
105
+ def implementation
106
+ if @api.implementation
107
+ Godel::Stage.new(@api.implementation)
108
+ end
109
+ end
92
110
  end
93
111
 
94
112
  class Resource < Mustache
@@ -160,6 +178,23 @@ module Useless
160
178
  headers.any?
161
179
  end
162
180
  end
181
+
182
+ class Stage
183
+ def initialize(stage)
184
+ @stage = stage
185
+ end
186
+
187
+ def progress
188
+ @stage.progress.
189
+ split('-').
190
+ map { |word| word.capitalize }.
191
+ join(' ')
192
+ end
193
+
194
+ def credit
195
+ @stage.credit.join(', ')
196
+ end
197
+ end
163
198
  end
164
199
  end
165
200
  end
@@ -1,5 +1,5 @@
1
1
  module Useless
2
2
  module Doc
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
@@ -3,6 +3,18 @@
3
3
  "url": "twonk.useless.io",
4
4
  "timestamp": "2013-03-06T23:13:00-05:00",
5
5
  "description": "Twonk information. Duh.",
6
+ "concept": {
7
+ "credit": ["John Henry"],
8
+ "progress": "complete"
9
+ },
10
+ "specification": {
11
+ "credit": ["Bill Wever"],
12
+ "progress": "in-progress"
13
+ },
14
+ "implementation": {
15
+ "credit": ["Bill Wever", "John Henry"],
16
+ "progress": "pending"
17
+ },
6
18
  "resources": [
7
19
  {
8
20
  "path": "/twonks/:id",
@@ -7,6 +7,7 @@ require 'useless/doc/core/header'
7
7
  require 'useless/doc/core/request'
8
8
  require 'useless/doc/core/resource'
9
9
  require 'useless/doc/core/response'
10
+ require 'useless/doc/core/stage'
10
11
  require 'useless/doc/serialization/dump'
11
12
  require 'useless/doc/serialization/load'
12
13
 
@@ -53,6 +54,18 @@ describe Useless::Doc::Serialization::Dump do
53
54
 
54
55
  describe '.api' do
55
56
  it 'should convert the specified Core::API instance to JSON' do
57
+ concept = Useless::Doc::Core::Stage.new \
58
+ credit: ['Joe Blue'],
59
+ progress: 'complete'
60
+
61
+ specification = Useless::Doc::Core::Stage.new \
62
+ credit: ['Bill Grey'],
63
+ progress: 'in-progress'
64
+
65
+ implementation = Useless::Doc::Core::Stage.new \
66
+ credit: ['Bill Grey', 'Joe Blue'],
67
+ progress: 'pending'
68
+
56
69
  resource = Useless::Doc::Core::Resource.new \
57
70
  path: '/twiddles',
58
71
  description: 'The full lot of twiddles.',
@@ -63,7 +76,10 @@ describe Useless::Doc::Serialization::Dump do
63
76
  url: 'twiddles.useless.io',
64
77
  timestamp: Time.parse('2013-03-06 11:13 PM'),
65
78
  description: 'Pretty much, like, everything you\'re looking for',
66
- resources: [resource]
79
+ resources: [resource],
80
+ concept: concept,
81
+ specification: specification,
82
+ implementation: implementation
67
83
 
68
84
  json = Useless::Doc::Serialization::Dump.api(api)
69
85
  hash = Useless::Doc::Serialization::Load.json_to_hash(json)
@@ -72,6 +88,18 @@ describe Useless::Doc::Serialization::Dump do
72
88
  hash['timestamp'].should == Time.parse('2013-03-06 11:13 PM').iso8601
73
89
  hash['description'].should == 'Pretty much, like, everything you\'re looking for'
74
90
 
91
+ concept_hash = Useless::Doc.load.json_to_hash(hash['concept'])
92
+ concept_hash['credit'].should == ['Joe Blue']
93
+ concept_hash['progress'].should == 'complete'
94
+
95
+ specification_hash = Useless::Doc.load.json_to_hash(hash['specification'])
96
+ specification_hash['credit'].should == ['Bill Grey']
97
+ specification_hash['progress'].should == 'in-progress'
98
+
99
+ implementation_hash = Useless::Doc.load.json_to_hash(hash['implementation'])
100
+ implementation_hash['credit'].should == ['Bill Grey', 'Joe Blue']
101
+ implementation_hash['progress'].should == 'pending'
102
+
75
103
  resource_hash = Useless::Doc::Serialization::Load.json_to_hash(hash['resources'][0])
76
104
  resource_hash['path'].should == '/twiddles'
77
105
  resource_hash['description'].should == 'The full lot of twiddles.'
@@ -61,6 +61,12 @@ describe Useless::Doc::Serialization::Load do
61
61
  api.url.should == 'twonk.useless.io'
62
62
  api.timestamp.should == Time.parse('2013-03-06T23:13:00-05:00')
63
63
  api.description.should == 'Twonk information. Duh.'
64
+ api.concept.credit.should == ['John Henry']
65
+ api.concept.progress.should == 'complete'
66
+ api.specification.credit.should == ['Bill Wever']
67
+ api.specification.progress.should == 'in-progress'
68
+ api.implementation.credit.should == ['Bill Wever', 'John Henry']
69
+ api.implementation.progress.should == 'pending'
64
70
  api.resources.first.path.should == '/twonks/:id'
65
71
  api.resources.first.description.should == 'The most critical aspect.'
66
72
  end
@@ -114,6 +114,26 @@ describe Useless::Doc::UI::Godel do
114
114
  as.find { |a| a.content == 'POST' }['href'].should == '/twonks/:id/werp#POST'
115
115
  td_content.should include 'Make dem werps.'
116
116
  end
117
+
118
+ it 'should display concept information' do
119
+ stages = @doc.css('table.stages').first.content
120
+ stages.should include 'Concept'
121
+ stages.should include 'John Henry'
122
+ end
123
+
124
+ it 'should display specification information' do
125
+ stages = @doc.css('table.stages').first.content
126
+ stages.should include 'Specification'
127
+ stages.should include 'Bill Wever'
128
+ stages.should include 'In Progress'
129
+ end
130
+
131
+ it 'should display implementation information' do
132
+ stages = @doc.css('table.stages').first.content
133
+ stages.should include 'Implementation'
134
+ stages.should include 'Bill Wever, John Henry'
135
+ stages.should include 'Pending'
136
+ end
117
137
  end
118
138
 
119
139
  context 'for a Core::Resource instance' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useless-doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.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-03-08 00:00:00.000000000 Z
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oj
@@ -192,6 +192,7 @@ files:
192
192
  - lib/useless/doc/core/request.rb
193
193
  - lib/useless/doc/core/resource.rb
194
194
  - lib/useless/doc/core/response.rb
195
+ - lib/useless/doc/core/stage.rb
195
196
  - lib/useless/doc/dsl.rb
196
197
  - lib/useless/doc/proxy.rb
197
198
  - lib/useless/doc/proxy/css.rb