angus-sdoc 0.0.1 → 0.0.2

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.
@@ -0,0 +1,317 @@
1
+ require 'json'
2
+
3
+ module Angus
4
+ module SDoc
5
+ class JsonFormatter
6
+
7
+ def self.format(x)
8
+ define_singleton_method("format_#{x}") do |y|
9
+ JSON(send("#{x}_for_json", y))
10
+ end
11
+ end
12
+
13
+ format :glossary
14
+ format :glossary_term
15
+ format :message
16
+ format :operation
17
+ format :proxy_operation
18
+ format :representation
19
+ format :representation_field
20
+ format :request_element
21
+ format :response_element
22
+ format :service
23
+ format :uri_element
24
+
25
+ class << self
26
+ private
27
+
28
+ # Returns a hash with the glossary data.
29
+ #
30
+ # @param [Angus::SDoc::Definitions::Glossary] glossary_definition
31
+ # The glossary definition.
32
+ #
33
+ # @return [Hash]
34
+ # @option return [(see .glossary_term_for_json)] :<term.short_name>
35
+ def glossary_for_json(glossary_definition)
36
+ glossary_definition.terms.inject({}) do |result, term|
37
+ result.merge({ term.short_name => glossary_term_for_json(term) })
38
+ end
39
+ end
40
+
41
+ # Returns a hash with the glossary term data.
42
+ #
43
+ # @param [Angus::SDoc::Definitions::GlossaryTerm] glossary_term_definition
44
+ # The glossary term definition.
45
+ #
46
+ # @return [Hash]
47
+ # @option return [String] :long_name
48
+ # @option return [String] :description
49
+ def glossary_term_for_json(glossary_term_definition)
50
+ {
51
+ :long_name => glossary_term_definition.long_name,
52
+ :description => glossary_term_definition.description
53
+ }
54
+ end
55
+
56
+ # Returns a hash with the message data.
57
+ #
58
+ # @param [Angus::SDoc::Definitions::Message] message_definition
59
+ # The message definition.
60
+ #
61
+ # @return [Hash]
62
+ # @option return [String] :key
63
+ # @option return [String] :description
64
+ # @option return [String] :level
65
+ # @option return [Integer] :status_code
66
+ def message_for_json(message_definition)
67
+ {
68
+ :key => message_definition.key,
69
+ :description => message_definition.description,
70
+ :level => message_definition.level,
71
+ :status_code => message_definition.status_code
72
+ }
73
+ end
74
+
75
+ # Returns a hash with the operation data.
76
+ #
77
+ # @param [Angus::SDoc::Definitions::Operation] operation_definition
78
+ # The operation definition.
79
+ #
80
+ # @return [Hash]
81
+ # @option return [String] :name
82
+ # @option return [String] :description
83
+ # @option return [String] :path
84
+ # @option return [String] :method
85
+ # @option return [Array<(see .uri_element_for_json)>] :uri
86
+ # @option return [Array<(see .request_element_for_json)>] :request
87
+ # @option return [Array<(see .response_element_for_json)>] :response
88
+ # @option return [Array<(see .message_for_json)>] :messages
89
+ def operation_for_json(operation_definition)
90
+ data = {
91
+ :name => operation_definition.name,
92
+ :description => operation_definition.description,
93
+ :path => operation_definition.path,
94
+ :method => operation_definition.method
95
+ }
96
+
97
+ if operation_definition.uri_elements && !operation_definition.uri_elements.empty?
98
+ uri_elements = operation_definition.uri_elements.map do |uri_element|
99
+ uri_element_for_json(uri_element)
100
+ end
101
+ data.merge!({ :uri => uri_elements })
102
+ end
103
+
104
+ if operation_definition.request_elements && !operation_definition.request_elements.empty?
105
+ request_elements = operation_definition.request_elements.map do |request_element|
106
+ request_element_for_json(request_element)
107
+ end
108
+
109
+ data.merge!({ :request => request_elements })
110
+ end
111
+
112
+ if operation_definition.response_elements && !operation_definition.response_elements.empty?
113
+ response_elements = operation_definition.response_elements.map do |response_element|
114
+ response_element_for_json(response_element)
115
+ end
116
+
117
+ data.merge!({:response => response_elements})
118
+ end
119
+
120
+ if operation_definition.messages && !operation_definition.messages.empty?
121
+ messages = operation_definition.messages.map do |message|
122
+ message_for_json(message)
123
+ end
124
+
125
+ data.merge!({:messages => messages})
126
+ end
127
+
128
+ data
129
+ end
130
+
131
+ # Returns a hash with the proxy operation data.
132
+ #
133
+ # @param [Angus::SDoc::Definitions::ProxyOperation] proxy_operation_definition
134
+ # The proxy operation definition.
135
+ #
136
+ # @return [Hash]
137
+ # @option return [String] :path
138
+ # @option return [String] :method
139
+ # @option return [String] :service
140
+ def proxy_operation_for_json(proxy_operation_definition)
141
+ {
142
+ :path => proxy_operation_definition.path,
143
+ :method => proxy_operation_definition.method,
144
+ :service => proxy_operation_definition.service_name
145
+ }
146
+ end
147
+
148
+ # Returns a hash with the representation data.
149
+ #
150
+ # @param [Angus::SDoc::Definitions::Representation] representation_definition
151
+ # The representation definition.
152
+ #
153
+ # @return [Array<(see .representation_field_for_json)>]
154
+ def representation_for_json(representation_definition)
155
+ representation_definition.fields.map do |field|
156
+ representation_field_for_json(field)
157
+ end
158
+ end
159
+
160
+ # Returns a hash with the representation field data.
161
+ #
162
+ # @param [Angus::SDoc::Definitions::RepresentationField] representation_field_definition
163
+ # The representation field definition.
164
+ #
165
+ # @return [Hash]
166
+ # @option return [String] :element
167
+ # @option return [String] :description
168
+ # @option return [Boolean] :required
169
+ # @option return [String] :type
170
+ # @option return [String] :elements_type
171
+ def representation_field_for_json(representation_field_definition)
172
+ data = {
173
+ :field => representation_field_definition.name,
174
+ :description => representation_field_definition.description,
175
+ :required => representation_field_definition.required
176
+ }
177
+
178
+ if representation_field_definition.type
179
+ data.merge!({:type => representation_field_definition.type})
180
+ end
181
+
182
+ if representation_field_definition.elements_type
183
+ data.merge!({:elements_type => representation_field_definition.elements_type})
184
+ end
185
+
186
+ data
187
+ end
188
+
189
+ # Returns a hash with the request element data.
190
+ #
191
+ # @param [Angus::SDoc::Definitions::RequestElement] request_element_definition
192
+ # The request element definition.
193
+ #
194
+ # @return [Hash]
195
+ # @option return [String] :element
196
+ # @option return [String] :description
197
+ # @option return [Boolean] :required
198
+ # @option return [String] :type
199
+ # @option return [String] :elements_type
200
+ def request_element_for_json(request_element_definition)
201
+ data = {
202
+ :element => request_element_definition.name,
203
+ :description => request_element_definition.description,
204
+ :required => request_element_definition.required
205
+ }
206
+
207
+ if request_element_definition.type
208
+ data.merge!({:type => request_element_definition.type})
209
+ end
210
+
211
+ if request_element_definition.elements_type
212
+ data.merge!({:elements_type => request_element_definition.elements_type})
213
+ end
214
+
215
+ data
216
+ end
217
+
218
+ # Returns a hash with the response element data.
219
+ #
220
+ # @param [Angus::SDoc::Definitions::ResponseElement] response_element_definition
221
+ # The response element definition.
222
+ #
223
+ # @return [Hash]
224
+ # @option return [String] :element
225
+ # @option return [String] :description
226
+ # @option return [Boolean] :required
227
+ # @option return [String] :type
228
+ # @option return [String] :elements_type
229
+ def response_element_for_json(response_element_definition)
230
+ data = {
231
+ :element => response_element_definition.name,
232
+ :description => response_element_definition.description,
233
+ :required => response_element_definition.required
234
+ }
235
+
236
+ if response_element_definition.type
237
+ data.merge!({:type => response_element_definition.type})
238
+ end
239
+
240
+ if response_element_definition.elements_type
241
+ data.merge!({:elements_type => response_element_definition.elements_type})
242
+ end
243
+
244
+ data
245
+ end
246
+
247
+ # Generates the json for the service definition.
248
+ #
249
+ # @param [Angus::SDoc::Definitions::Service] service_definition
250
+ # The service definition.
251
+ #
252
+ # @return [Hash]
253
+ # @option return [Hash] :service
254
+ # @option :service [String] :service
255
+ # @option :service [String] :code_name
256
+ # @option :service [String] :version
257
+ # @option return [Hash<(see .uri_element_for_json)>] :operations
258
+ # @option return [Hash<(see .request_element_for_json)>] :proxy_operations
259
+ # @option return [Hash<(see .response_element_for_json)>] :representations
260
+ # @option return [Array<(see .message_for_json)>] :messages
261
+ # @option return [(see .message_for_json)] :glossary
262
+ def service_for_json(service_definition)
263
+ operations = service_definition.operations.inject({}) do |result, (namespace, operations)|
264
+ result[namespace] ||= {}
265
+ operations.each do |operation|
266
+ result[namespace][operation.code_name] = operation_for_json(operation)
267
+ end
268
+ result
269
+ end
270
+
271
+ proxy_operations = service_definition.proxy_operations.inject({}) do |result, operation|
272
+ result.merge({ operation.code_name => proxy_operation_for_json(operation) })
273
+ end
274
+
275
+ representations = service_definition.representations.inject({}) do |result, representation|
276
+ result.merge({ representation.name => representation_for_json(representation) })
277
+ end
278
+
279
+ messages = service_definition.messages.inject({}) do |result, message_data|
280
+ message_name, message = message_data
281
+ result.merge({ message_name => message_for_json(message) })
282
+ end
283
+
284
+ {
285
+ :service => {
286
+ :service => service_definition.name,
287
+ :code_name => service_definition.code_name,
288
+ :version => service_definition.version
289
+ },
290
+ :operations => operations,
291
+ :proxy_operations => proxy_operations,
292
+ :representations => representations,
293
+ :messages => messages,
294
+ :glossary => glossary_for_json(service_definition.glossary)
295
+ }
296
+ end
297
+
298
+ # Returns a hash with the uri element data.
299
+ #
300
+ # @param [Angus::SDoc::Definitions::UriElement] uri_element_definition
301
+ # The uri element definition.
302
+ #
303
+ # @return [Hash]
304
+ # @option return [String] :element
305
+ # @option return [String] :description
306
+ def uri_element_for_json(uri_element_definition)
307
+ {
308
+ :element => uri_element_definition.name,
309
+ :description => uri_element_definition.description
310
+ }
311
+ end
312
+
313
+ end
314
+
315
+ end
316
+ end
317
+ end
@@ -0,0 +1,295 @@
1
+ <%
2
+ glossary_terms_hash = @service.glossary.terms_hash
3
+ %>
4
+
5
+ <html>
6
+ <head>
7
+ <title>Especificaci&oacute;n API de Servicio <%= @service.name %></title>
8
+
9
+ <style type="text/css" media="screen">
10
+ <%= erb :styles %>
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <div class="content">
15
+ <h1>Especificaci&oacute;n API de Servicio <%= @service.name %></h1>
16
+ <h4>Nombre en c&oacute;digo</h4>
17
+ <p><%= @service.code_name %></p>
18
+
19
+ <h3>Operaciones</h3>
20
+ <p>
21
+ En esta secci&oacute;n se describen las operaciones presentadas por este servicio.
22
+ </p>
23
+
24
+ <table>
25
+ <thead>
26
+ <tr>
27
+ <td>&Iacute;ndice de Operaciones</td>
28
+ </tr>
29
+ </thead>
30
+ <tbody>
31
+ <% @service.operations.each do |(controller_name, operations)| %>
32
+ <% operations.each do |operation| %>
33
+ <tr>
34
+ <td>
35
+ <a href="#operation-<%= controller_name %>-<%= operation.code_name %>">
36
+ <%= controller_name %>#<%= operation.code_name %>
37
+ </a>
38
+ </td>
39
+ </tr>
40
+ <% end %>
41
+ <% end %>
42
+ </tbody>
43
+ </table>
44
+
45
+ <% if @service.proxy_operations.any? %>
46
+ <p></p>
47
+ <table>
48
+ <thead>
49
+ <tr><td>Índice de Operaciones Proxy</td></tr>
50
+ </thead>
51
+ <tbody>
52
+ <% @service.proxy_operations.each do |operation| %>
53
+ <tr><td>
54
+ <a href="#proxy-operation-<%= operation.code_name %>">
55
+ <%= operation.code_name %>
56
+ </a>
57
+ </td></tr>
58
+ <% end %>
59
+ </tbody>
60
+ </table>
61
+ <% end %>
62
+
63
+ <% @service.operations.each do |(controller_name, operations)| %>
64
+ <% operations.each do |operation| %>
65
+ <div class="operation" id="operation-<%= controller_name %>-<%= operation.code_name %>">
66
+ <h4>
67
+ <%= operation.name %>
68
+ </h4>
69
+
70
+ <h5>Descripci&oacute;n</h5>
71
+ <p><%= operation.description %></p>
72
+
73
+ <h5>Versiones</h5>
74
+ <p>Presente desde versi&oacute;n inicial</p>
75
+
76
+ <table class="vertical-header split">
77
+ <tbody>
78
+ <tr>
79
+ <td>M&eacute;todo</td>
80
+ <td><%= operation.method %></td>
81
+ </tr>
82
+ <tr>
83
+ <td>URI</td>
84
+ <td><%= operation.path %></td>
85
+ </tr>
86
+ <tr>
87
+ <td>Nombre interno</td>
88
+ <td><%= operation.code_name %></td>
89
+ </tr>
90
+ </tbody>
91
+ </table>
92
+
93
+ <% if !operation.uri_elements.empty? %>
94
+ <h5>Parametros de Path URI</h5>
95
+ <table>
96
+ <thead>
97
+ <tr>
98
+ <td>Par&aacute;metro</td>
99
+ <td>Descripción</td>
100
+ </tr>
101
+ </thead>
102
+ <tbody>
103
+ <% operation.uri_elements.each do |element| %>
104
+ <tr>
105
+ <td><%= element.name %></td>
106
+ <td>
107
+ <%= element.description %>
108
+ </td>
109
+ </tr>
110
+ <% end %>
111
+ </tbody>
112
+ </table>
113
+ <% end %>
114
+
115
+
116
+ <% if !operation.request_elements.empty? %>
117
+ <h5>Elementos de Petici&oacute;n</h5>
118
+ <table>
119
+ <thead>
120
+ <tr>
121
+ <td>Nombre</td>
122
+ <td>Descripci&oacute;n</td>
123
+ <td>Requerido</td>
124
+ </tr>
125
+ </thead>
126
+ <tbody>
127
+ <% operation.request_elements.each do |element| %>
128
+ <tr>
129
+ <td><%= element.name %></td>
130
+ <td>
131
+ <%= element.description %><br />
132
+ Tipo: <%= h_type(element.type, @service) %><br />
133
+ Restricciones: <%= element.constraints %><br />
134
+ Valores Válidos: <%= element.valid_values %><br />
135
+ <% if glossary_terms_hash.include?(element.name)
136
+ glossary_term = glossary_terms_hash[element.name]
137
+ %>
138
+ Glosario:
139
+ <a href="#glossary-term-<%= glossary_term.short_name %>"><%= glossary_term.long_name %></a>
140
+ <br />
141
+ <% end %>
142
+ </td>
143
+ <td><%= element.required %></td>
144
+ </tr>
145
+ <% end %>
146
+ </tbody>
147
+ </table>
148
+ <% end %>
149
+
150
+ <% if !operation.response_elements.empty? %>
151
+ <h5>Elementos de Respuesta</h5>
152
+ <table>
153
+ <thead>
154
+ <tr>
155
+ <td>Nombre</td>
156
+ <td>Descripción</td>
157
+ <td>Requerido</td>
158
+ </tr>
159
+ </thead>
160
+ <tbody>
161
+ <% operation.response_elements.each do |element| %>
162
+ <tr>
163
+ <td><%= element.name %></td>
164
+ <td>
165
+ <%= element.description %><br />
166
+ <% if element.type %>
167
+ Tipo: <%= h_type(element.type, @service) %><br />
168
+ <% else %>
169
+ Contenedor: <%= h_type(element.elements_type, @service) %><br />
170
+ <% end %>
171
+ <% if element.default %>
172
+ Valor por defecto: <%= element.default %>
173
+ <% end %>
174
+ </td>
175
+ <td><%= element.required %></td>
176
+ </tr>
177
+ <% end %>
178
+ </tbody>
179
+ </table>
180
+ <% end %>
181
+
182
+ <% if !operation.messages.empty? %>
183
+ <h5>Mensajes</h5>
184
+ <table>
185
+ <thead>
186
+ <tr>
187
+ <td>Nivel</td>
188
+ <td>Código</td>
189
+ <td>Descripción</td>
190
+ <td>Código de Estado HTTP</td>
191
+ </tr>
192
+ </thead>
193
+ <tbody>
194
+ <% operation.messages.each do |message| %>
195
+ <tr>
196
+ <td><%= message.level %></td>
197
+ <td><%= message.key %></td>
198
+ <td><%= message.description %></td>
199
+ <td><%= message.status_code %></td>
200
+ </tr>
201
+ <% end %>
202
+ </tbody>
203
+ </table>
204
+ <% end %>
205
+ </div>
206
+ <% end %>
207
+ <% end %>
208
+
209
+ <h3>Representaciones</h3>
210
+ <% @service.representations.each do |representation| %>
211
+ <div class="representation" id="representation-<%= representation.name %>">
212
+ <h4><%= representation.name %></h4>
213
+ <table>
214
+ <thead>
215
+ <tr>
216
+ <td>Nombre de Atributo</td>
217
+ <td>Descripci&oacute;n</td>
218
+ <td>Requerido</td>
219
+ </tr>
220
+ </thead>
221
+ <tbody>
222
+ <% representation.fields.each do |field| %>
223
+ <tr>
224
+ <td><%= field.name %></td>
225
+ <td>
226
+ <%= field.description %><br />
227
+ <% if field.type %>
228
+ Tipo: <%= h_type(field.type, @service) %><br />
229
+ <% else %>
230
+ Contenedor: <%= h_type(field.elements_type, @service) %><br />
231
+ <% end %>
232
+ </td>
233
+ <td><%= field.required %></td>
234
+ </tr>
235
+ <% end %>
236
+ </tbody>
237
+ </table>
238
+ </div>
239
+ <% end %>
240
+
241
+ <% if @service.proxy_operations.any? %>
242
+ <h3>Operaciones Proxy</h3>
243
+ <div id="proxy_operations" class="proxy_operations">
244
+ <table>
245
+ <thead>
246
+ <tr>
247
+ <td>Nombre Interno</td>
248
+ <td>Método</td>
249
+ <td>URI</td>
250
+ <td>Servicio</td>
251
+ </tr>
252
+ </thead>
253
+ <tbody>
254
+ <% @service.proxy_operations.each do |operation| %>
255
+ <tr id="proxy-operation-<%= operation.code_name %>">
256
+ <td>
257
+ <%= operation.code_name %>
258
+ </td>
259
+ <td><%= operation.method %></td>
260
+ <td><%= operation.path %></td>
261
+ <td><%= operation.service_name %></td>
262
+ </tr>
263
+ <% end %>
264
+ </tbody>
265
+ </table>
266
+ </div>
267
+ <% end %>
268
+
269
+ <% if @service.glossary.terms.any? %>
270
+ <h3>Glosario</h3>
271
+ <div class="glossary">
272
+ <table>
273
+ <thead>
274
+ <tr>
275
+ <td>Nombre Corto</td>
276
+ <td>Nombre Largo</td>
277
+ <td>Descripción</td>
278
+ </tr>
279
+ </thead>
280
+ <tbody>
281
+ <% @service.glossary.terms.each do |term| %>
282
+ <tr id="glossary-term-<%= term.short_name %>">
283
+ <td><%= term.short_name %></td>
284
+ <td><%= term.long_name %></td>
285
+ <td><%= term.description %></td>
286
+ </tr>
287
+ <% end %>
288
+ </tbody>
289
+ </table>
290
+ </div>
291
+ <% end %>
292
+
293
+ </body>
294
+ </html>
295
+
@@ -0,0 +1,70 @@
1
+ body {
2
+ font-family: Arial;
3
+ font-size: 11pt;
4
+ background-color: #D0D0D0;
5
+ }
6
+
7
+ h1 {
8
+ text-align: center;
9
+ font-size: 24pt;
10
+ font-weight: bold;
11
+ }
12
+
13
+ h3 {
14
+ font-size: 14pt;
15
+ font-weight: bold;
16
+ }
17
+
18
+ h4 {
19
+ font-size: 12pt;
20
+ font-weight: bold;
21
+ }
22
+
23
+ h5 {
24
+ font-size: 11pt;
25
+ font-weight: bold;
26
+ }
27
+
28
+ table {
29
+ border-collapse: collapse;
30
+ border-spacing: 0;
31
+ width: 50em;
32
+ }
33
+
34
+ thead {
35
+ background-color: #EFEFEF;
36
+ font-size: 10pt;
37
+ font-weight: bold;
38
+ }
39
+
40
+ tbody {
41
+ font-size: 11pt;
42
+ }
43
+
44
+ td {
45
+ border: solid 1px #000000;
46
+ margin: 0;
47
+ padding: 4pt 6pt;
48
+ }
49
+
50
+ body > .content {
51
+ margin: 20px 10px;
52
+ border: solid 1px #909090;
53
+ padding: 10px 10px;
54
+ background-color: #FFFFFF;
55
+ }
56
+
57
+ .operation, .representation {
58
+ border-bottom: solid 1px #909090;
59
+ padding-bottom: 4ex;
60
+ }
61
+
62
+ table.vertical-header td:first-child {
63
+ background-color: #EFEFEF;
64
+ font-size: 10pt;
65
+ font-weight: bold;
66
+ }
67
+
68
+ table.split td:first-child {
69
+ width: 40%;
70
+ }
@@ -1,5 +1,5 @@
1
1
  module Angus
2
- module Sdoc
3
- VERSION = "0.0.1"
2
+ module SDoc
3
+ VERSION = '0.0.2'
4
4
  end
5
- end
5
+ end
data/lib/angus/sdoc.rb CHANGED
@@ -1,7 +1,6 @@
1
- require "angus/sdoc/version"
1
+ require 'set'
2
+ require 'yaml'
3
+ require 'pathname'
2
4
 
3
- module Angus
4
- module Sdoc
5
- # Your code goes here...
6
- end
7
- end
5
+ require_relative 'sdoc/version'
6
+ require_relative 'base'