redsnow 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/README.md +12 -0
- data/ext/snowcrash/bin/snowcrash +0 -0
- data/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.c +5 -2
- data/ext/snowcrash/snowcrash.gyp +7 -2
- data/ext/snowcrash/src/ActionParser.h +141 -81
- data/ext/snowcrash/src/AssetParser.h +19 -11
- data/ext/snowcrash/src/Blueprint.h +44 -14
- data/ext/snowcrash/src/BlueprintParser.h +65 -51
- data/ext/snowcrash/src/BlueprintSourcemap.h +254 -0
- data/ext/snowcrash/src/BlueprintUtility.h +3 -24
- data/ext/snowcrash/src/CBlueprint.cc +40 -31
- data/ext/snowcrash/src/CBlueprint.h +54 -58
- data/ext/snowcrash/src/CBlueprintSourcemap.cc +620 -0
- data/ext/snowcrash/src/CBlueprintSourcemap.h +342 -0
- data/ext/snowcrash/src/CSourceAnnotation.cc +14 -0
- data/ext/snowcrash/src/CodeBlockUtility.h +42 -5
- data/ext/snowcrash/src/HeadersParser.h +84 -42
- data/ext/snowcrash/src/ParameterParser.h +110 -68
- data/ext/snowcrash/src/ParametersParser.h +26 -28
- data/ext/snowcrash/src/PayloadParser.h +164 -83
- data/ext/snowcrash/src/ResourceGroupParser.h +35 -41
- data/ext/snowcrash/src/ResourceParser.h +142 -97
- data/ext/snowcrash/src/SectionParser.h +15 -14
- data/ext/snowcrash/src/SectionParserData.h +11 -2
- data/ext/snowcrash/src/SectionProcessor.h +42 -18
- data/ext/snowcrash/src/Serialize.cc +2 -0
- data/ext/snowcrash/src/Serialize.h +3 -1
- data/ext/snowcrash/src/SerializeJSON.cc +608 -16
- data/ext/snowcrash/src/SerializeJSON.h +4 -1
- data/ext/snowcrash/src/SerializeYAML.cc +367 -19
- data/ext/snowcrash/src/SerializeYAML.h +4 -1
- data/ext/snowcrash/src/SymbolTable.h +12 -1
- data/ext/snowcrash/src/ValuesParser.h +12 -11
- data/ext/snowcrash/src/Version.h +1 -1
- data/ext/snowcrash/src/csnowcrash.cc +7 -3
- data/ext/snowcrash/src/csnowcrash.h +4 -2
- data/ext/snowcrash/src/snowcrash.cc +10 -11
- data/ext/snowcrash/src/snowcrash.h +3 -3
- data/ext/snowcrash/src/snowcrash/snowcrash.cc +38 -8
- data/ext/snowcrash/tools/homebrew/snowcrash.rb +1 -1
- data/lib/redsnow.rb +41 -2
- data/lib/redsnow/binding.rb +93 -8
- data/lib/redsnow/blueprint.rb +48 -25
- data/lib/redsnow/parseresult.rb +9 -2
- data/lib/redsnow/sourcemap.rb +369 -0
- data/lib/redsnow/version.rb +1 -1
- data/test/fixtures/sample-api-ast.json +1 -1
- data/test/fixtures/sample-api-sourcemap.json +169 -0
- data/test/redsnow_binding_test.rb +19 -2
- data/test/redsnow_options_test.rb +42 -0
- data/test/redsnow_parseresult_test.rb +5 -1
- data/test/redsnow_test.rb +5 -0
- metadata +11 -2
@@ -10,12 +10,15 @@
|
|
10
10
|
#define SNOWCRASH_SERIALIZE_JSON_H
|
11
11
|
|
12
12
|
#include <ostream>
|
13
|
-
#include "
|
13
|
+
#include "BlueprintSourcemap.h"
|
14
14
|
|
15
15
|
namespace snowcrash {
|
16
16
|
|
17
17
|
// Naive JSON serialization to ostream
|
18
18
|
void SerializeJSON(const snowcrash::Blueprint& blueprint, std::ostream &os);
|
19
|
+
|
20
|
+
// Naive Sourcmap JSON serialization to ostream
|
21
|
+
void SerializeSourceMapJSON(const snowcrash::SourceMap<snowcrash::Blueprint>& blueprint, std::ostream &os);
|
19
22
|
}
|
20
23
|
|
21
24
|
#endif
|
@@ -17,6 +17,7 @@ static std::string ReservedCharacters = "#-[]:|>!*&%@`,{}?\'";
|
|
17
17
|
static std::string NormalizeStringValue(const std::string& value, bool& needsQuotation)
|
18
18
|
{
|
19
19
|
std::string normalizedValue = value;
|
20
|
+
|
20
21
|
if (normalizedValue.find("\"") != std::string::npos)
|
21
22
|
normalizedValue = EscapeDoubleQuotes(normalizedValue);
|
22
23
|
|
@@ -24,6 +25,7 @@ static std::string NormalizeStringValue(const std::string& value, bool& needsQuo
|
|
24
25
|
normalizedValue = EscapeNewlines(normalizedValue);
|
25
26
|
|
26
27
|
needsQuotation = (normalizedValue != value);
|
28
|
+
|
27
29
|
if (!needsQuotation) {
|
28
30
|
for (std::string::const_iterator it = value.begin() ; it < value.end() ; ++it){
|
29
31
|
needsQuotation = ReservedCharacters.find(*it) != std::string::npos;
|
@@ -37,7 +39,7 @@ static std::string NormalizeStringValue(const std::string& value, bool& needsQuo
|
|
37
39
|
|
38
40
|
|
39
41
|
/** Insert array item mark */
|
40
|
-
static void ArrayItemLeadIn(size_t level, std::ostream &os)
|
42
|
+
static void ArrayItemLeadIn(size_t level, std::ostream &os, bool withTrailingSpace = true)
|
41
43
|
{
|
42
44
|
if (level < 1)
|
43
45
|
return;
|
@@ -45,7 +47,11 @@ static void ArrayItemLeadIn(size_t level, std::ostream &os)
|
|
45
47
|
for (size_t i = 0; i < level - 1; ++i)
|
46
48
|
os << " ";
|
47
49
|
|
48
|
-
os << "-
|
50
|
+
os << "-";
|
51
|
+
|
52
|
+
if (withTrailingSpace) {
|
53
|
+
os << " ";
|
54
|
+
}
|
49
55
|
}
|
50
56
|
|
51
57
|
/** Serialize key value pair */
|
@@ -81,10 +87,63 @@ static void serialize(const std::string& key, const std::string& value, size_t l
|
|
81
87
|
os << key << ":\n";
|
82
88
|
}
|
83
89
|
|
90
|
+
/** Serialize source map without key into output stream */
|
91
|
+
static void serialize(const SourceMapBase& set, size_t level, std::ostream &os)
|
92
|
+
{
|
93
|
+
if (!set.sourceMap.empty()) {
|
94
|
+
size_t i = 0;
|
95
|
+
os << std::endl;
|
96
|
+
|
97
|
+
for (mdp::RangeSet<mdp::BytesRange>::const_iterator it = set.sourceMap.begin(); it != set.sourceMap.end(); ++i, ++it) {
|
98
|
+
|
99
|
+
ArrayItemLeadIn(level, os, false);
|
100
|
+
os << "\n";
|
101
|
+
ArrayItemLeadIn(level + 1, os);
|
102
|
+
os << it->location << "\n";
|
103
|
+
ArrayItemLeadIn(level + 1, os);
|
104
|
+
os << it->length << "\n";
|
105
|
+
}
|
106
|
+
} else {
|
107
|
+
os << " []\n";
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
/** Serialize a key and source map value into output stream. */
|
112
|
+
static void serialize(const std::string& key, const SourceMapBase& value, size_t level, std::ostream &os, bool keyLevelIsZero = false)
|
113
|
+
{
|
114
|
+
if (key.empty())
|
115
|
+
return;
|
116
|
+
|
117
|
+
if (!keyLevelIsZero) {
|
118
|
+
for (size_t i = 0; i < level; ++i)
|
119
|
+
os << " ";
|
120
|
+
}
|
121
|
+
|
122
|
+
os << key << ":";
|
123
|
+
serialize(value, level + 1, os);
|
124
|
+
}
|
125
|
+
|
126
|
+
/** Serializes source map collection */
|
127
|
+
static void serializeSourceMapCollection(const Collection<SourceMap<KeyValuePair> >::type& collection, size_t level, std::ostream &os)
|
128
|
+
{
|
129
|
+
for (Collection<SourceMap<KeyValuePair> >::const_iterator it = collection.begin();
|
130
|
+
it != collection.end();
|
131
|
+
++it) {
|
132
|
+
|
133
|
+
// Array item
|
134
|
+
ArrayItemLeadIn(level + 1, os, false);
|
135
|
+
|
136
|
+
// Source Map
|
137
|
+
serialize(*it, level + 2, os);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
84
141
|
/** Serializes key value collection */
|
85
142
|
static void serializeKeyValueCollection(const Collection<KeyValuePair>::type& collection, size_t level, std::ostream &os)
|
86
143
|
{
|
87
|
-
for (Collection<KeyValuePair>::const_iterator it = collection.begin();
|
144
|
+
for (Collection<KeyValuePair>::const_iterator it = collection.begin();
|
145
|
+
it != collection.end();
|
146
|
+
++it) {
|
88
147
|
|
89
148
|
// Array item
|
90
149
|
ArrayItemLeadIn(level + 1, os);
|
@@ -108,14 +167,32 @@ static void serialize(const Collection<Metadata>::type& metadata, std::ostream &
|
|
108
167
|
serializeKeyValueCollection(metadata, 0, os);
|
109
168
|
}
|
110
169
|
|
170
|
+
/** Serialize Metadata source map */
|
171
|
+
static void serialize(const Collection<SourceMap<Metadata> >::type& metadata, std::ostream &os)
|
172
|
+
{
|
173
|
+
serialize(SerializeKey::Metadata, std::string(), 0, os);
|
174
|
+
|
175
|
+
if (metadata.empty())
|
176
|
+
return;
|
177
|
+
|
178
|
+
serializeSourceMapCollection(metadata, 0, os);
|
179
|
+
}
|
180
|
+
|
181
|
+
|
111
182
|
/** Serialize Headers */
|
112
|
-
static void serialize(const
|
183
|
+
static void serialize(const Headers& headers, size_t level, std::ostream &os)
|
113
184
|
{
|
114
185
|
serializeKeyValueCollection(headers, level, os);
|
115
186
|
}
|
116
187
|
|
188
|
+
/** Serialize Headers source map */
|
189
|
+
static void serialize(const Collection<SourceMap<Header> >::type& headers, size_t level, std::ostream &os)
|
190
|
+
{
|
191
|
+
serializeSourceMapCollection(headers, level, os);
|
192
|
+
}
|
193
|
+
|
117
194
|
/** Serialize Parameters */
|
118
|
-
static void serialize(const
|
195
|
+
static void serialize(const Parameters& parameters, size_t level, std::ostream &os)
|
119
196
|
{
|
120
197
|
for (Collection<Parameter>::const_iterator it = parameters.begin(); it != parameters.end(); ++it) {
|
121
198
|
|
@@ -143,15 +220,57 @@ static void serialize(const Collection<Parameter>::type& parameters, size_t leve
|
|
143
220
|
// Values
|
144
221
|
serialize(SerializeKey::Values, std::string(), level + 1, os);
|
145
222
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
++val_it) {
|
223
|
+
for (Collection<Value>::const_iterator val_it = it->values.begin();
|
224
|
+
val_it != it->values.end();
|
225
|
+
++val_it) {
|
150
226
|
|
151
|
-
|
227
|
+
ArrayItemLeadIn(level + 2, os);
|
152
228
|
|
153
|
-
|
154
|
-
|
229
|
+
serialize(SerializeKey::Value, *val_it, 0, os);
|
230
|
+
}
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
/** Serialize Parameters source map */
|
235
|
+
static void serialize(const Collection<SourceMap<Parameter> >::type& parameters, size_t level, std::ostream &os)
|
236
|
+
{
|
237
|
+
for (Collection<SourceMap<Parameter> >::const_iterator it = parameters.begin();
|
238
|
+
it != parameters.end();
|
239
|
+
++it) {
|
240
|
+
|
241
|
+
// Array item
|
242
|
+
ArrayItemLeadIn(level + 1, os);
|
243
|
+
|
244
|
+
// Key / name
|
245
|
+
serialize(SerializeKey::Name, it->name, level + 1, os, true);
|
246
|
+
|
247
|
+
// Description
|
248
|
+
serialize(SerializeKey::Description, it->description, level + 1, os);
|
249
|
+
|
250
|
+
// Type
|
251
|
+
serialize(SerializeKey::Type, it->type, level + 1, os);
|
252
|
+
|
253
|
+
// Required
|
254
|
+
serialize(SerializeKey::Required, it->use, level + 1, os);
|
255
|
+
|
256
|
+
// Default
|
257
|
+
serialize(SerializeKey::Default, it->defaultValue, level + 1, os);
|
258
|
+
|
259
|
+
// Example
|
260
|
+
serialize(SerializeKey::Example, it->exampleValue, level + 1, os);
|
261
|
+
|
262
|
+
// Values
|
263
|
+
serialize(SerializeKey::Values, std::string(), level + 1, os);
|
264
|
+
|
265
|
+
for (Collection<SourceMap<Value> >::const_iterator val_it = it->values.collection.begin();
|
266
|
+
val_it != it->values.collection.end();
|
267
|
+
++val_it) {
|
268
|
+
|
269
|
+
// Array item
|
270
|
+
ArrayItemLeadIn(level + 2, os);
|
271
|
+
|
272
|
+
// Source Map
|
273
|
+
serialize(*val_it, level + 3, os);
|
155
274
|
}
|
156
275
|
}
|
157
276
|
}
|
@@ -167,15 +286,22 @@ static void serialize(const Payload& payload, size_t level, bool array, std::ost
|
|
167
286
|
os << "- ";
|
168
287
|
else
|
169
288
|
os << " ";
|
170
|
-
|
289
|
+
|
171
290
|
// Name
|
172
291
|
serialize(SerializeKey::Name, payload.name, 0, os);
|
173
|
-
|
292
|
+
|
293
|
+
// Symbol Reference
|
294
|
+
if (!payload.symbol.empty()) {
|
295
|
+
serialize(SerializeKey::Reference, "", level, os);
|
296
|
+
serialize(SerializeKey::Id, payload.symbol, level + 1, os);
|
297
|
+
}
|
298
|
+
|
174
299
|
// Description
|
175
300
|
serialize(SerializeKey::Description, payload.description, level, os);
|
176
301
|
|
177
302
|
// Headers
|
178
303
|
serialize(SerializeKey::Headers, std::string(), level, os);
|
304
|
+
|
179
305
|
if (!payload.headers.empty()) {
|
180
306
|
serialize(payload.headers, level, os);
|
181
307
|
}
|
@@ -185,13 +311,50 @@ static void serialize(const Payload& payload, size_t level, bool array, std::ost
|
|
185
311
|
|
186
312
|
// Schema
|
187
313
|
serialize(SerializeKey::Schema, payload.schema, level, os);
|
314
|
+
}
|
315
|
+
|
316
|
+
/** Serialize Payload source map */
|
317
|
+
static void serialize(const SourceMap<Payload>& payload, size_t level, bool array, std::ostream &os)
|
318
|
+
{
|
319
|
+
for (size_t i = 0; i < level - 1; i++) {
|
320
|
+
os << " ";
|
321
|
+
}
|
322
|
+
|
323
|
+
if (array)
|
324
|
+
os << "- ";
|
325
|
+
else
|
326
|
+
os << " ";
|
327
|
+
|
328
|
+
// Name
|
329
|
+
serialize(SerializeKey::Name, payload.name, level, os, true);
|
330
|
+
|
331
|
+
// Symbol Reference
|
332
|
+
if (!payload.symbol.sourceMap.empty()) {
|
333
|
+
serialize(SerializeKey::Reference, payload.symbol, level, os);
|
334
|
+
}
|
188
335
|
|
336
|
+
// Description
|
337
|
+
serialize(SerializeKey::Description, payload.description, level, os);
|
338
|
+
|
339
|
+
// Headers
|
340
|
+
serialize(SerializeKey::Headers, std::string(), level, os);
|
341
|
+
|
342
|
+
if (!payload.headers.collection.empty()) {
|
343
|
+
serialize(payload.headers.collection, level, os);
|
344
|
+
}
|
345
|
+
|
346
|
+
// Body
|
347
|
+
serialize(SerializeKey::Body, payload.body, level, os);
|
348
|
+
|
349
|
+
// Schema
|
350
|
+
serialize(SerializeKey::Schema, payload.schema, level, os);
|
189
351
|
}
|
190
352
|
|
191
|
-
|
353
|
+
/** Serialize Transaction Example */
|
192
354
|
static void serialize(const TransactionExample& example, std::ostream &os)
|
193
355
|
{
|
194
356
|
os << " - "; // indent 4
|
357
|
+
|
195
358
|
// Name
|
196
359
|
serialize(SerializeKey::Name, example.name, 0, os);
|
197
360
|
|
@@ -200,16 +363,60 @@ static void serialize(const TransactionExample& example, std::ostream &os)
|
|
200
363
|
|
201
364
|
// Requests
|
202
365
|
serialize(SerializeKey::Requests, std::string(), 4, os);
|
366
|
+
|
203
367
|
if (!example.requests.empty()) {
|
204
|
-
for (Collection<Request>::const_iterator it = example.requests.begin();
|
368
|
+
for (Collection<Request>::const_iterator it = example.requests.begin();
|
369
|
+
it != example.requests.end();
|
370
|
+
++it) {
|
371
|
+
|
205
372
|
serialize(*it, 5, true, os);
|
206
373
|
}
|
207
374
|
}
|
208
375
|
|
209
376
|
// Responses
|
210
377
|
serialize(SerializeKey::Responses, std::string(), 4, os);
|
378
|
+
|
211
379
|
if (!example.responses.empty()) {
|
212
|
-
for (Collection<Response>::const_iterator it = example.responses.begin();
|
380
|
+
for (Collection<Response>::const_iterator it = example.responses.begin();
|
381
|
+
it != example.responses.end();
|
382
|
+
++it) {
|
383
|
+
|
384
|
+
serialize(*it, 5, true, os);
|
385
|
+
}
|
386
|
+
}
|
387
|
+
}
|
388
|
+
|
389
|
+
/** Serialize Transaction Example source map */
|
390
|
+
static void serialize(const SourceMap<TransactionExample>& example, std::ostream &os)
|
391
|
+
{
|
392
|
+
os << " - "; // indent 4
|
393
|
+
|
394
|
+
// Name
|
395
|
+
serialize(SerializeKey::Name, example.name, 4, os, true);
|
396
|
+
|
397
|
+
// Description
|
398
|
+
serialize(SerializeKey::Description, example.description, 4, os);
|
399
|
+
|
400
|
+
// Requests
|
401
|
+
serialize(SerializeKey::Requests, std::string(), 4, os);
|
402
|
+
|
403
|
+
if (!example.requests.collection.empty()) {
|
404
|
+
for (Collection<SourceMap<Request> >::const_iterator it = example.requests.collection.begin();
|
405
|
+
it != example.requests.collection.end();
|
406
|
+
++it) {
|
407
|
+
|
408
|
+
serialize(*it, 5, true, os);
|
409
|
+
}
|
410
|
+
}
|
411
|
+
|
412
|
+
// Responses
|
413
|
+
serialize(SerializeKey::Responses, std::string(), 4, os);
|
414
|
+
|
415
|
+
if (!example.responses.collection.empty()) {
|
416
|
+
for (Collection<SourceMap<Response> >::const_iterator it = example.responses.collection.begin();
|
417
|
+
it != example.responses.collection.end();
|
418
|
+
++it) {
|
419
|
+
|
213
420
|
serialize(*it, 5, true, os);
|
214
421
|
}
|
215
422
|
}
|
@@ -231,15 +438,51 @@ static void serialize(const Action& action, std::ostream &os)
|
|
231
438
|
|
232
439
|
// Parameters
|
233
440
|
serialize(SerializeKey::Parameters, std::string(), 3, os);
|
441
|
+
|
234
442
|
if (!action.parameters.empty())
|
235
443
|
serialize(action.parameters, 3, os);
|
236
444
|
|
237
445
|
// Examples
|
238
446
|
serialize(SerializeKey::Examples, std::string(), 3, os);
|
447
|
+
|
239
448
|
if (!action.examples.empty()) {
|
240
449
|
for (Collection<TransactionExample>::const_iterator it = action.examples.begin();
|
241
450
|
it != action.examples.end();
|
242
451
|
++it) {
|
452
|
+
|
453
|
+
serialize(*it, os);
|
454
|
+
}
|
455
|
+
}
|
456
|
+
}
|
457
|
+
|
458
|
+
/** Serialize Action source map */
|
459
|
+
static void serialize(const SourceMap<Action>& action, std::ostream &os)
|
460
|
+
{
|
461
|
+
os << " - "; // indent 3
|
462
|
+
|
463
|
+
// Name
|
464
|
+
serialize(SerializeKey::Name, action.name, 3, os, true);
|
465
|
+
|
466
|
+
// Description
|
467
|
+
serialize(SerializeKey::Description, action.description, 3, os);
|
468
|
+
|
469
|
+
// HTTP method
|
470
|
+
serialize(SerializeKey::Method, action.method, 3, os);
|
471
|
+
|
472
|
+
// Parameters
|
473
|
+
serialize(SerializeKey::Parameters, std::string(), 3, os);
|
474
|
+
|
475
|
+
if (!action.parameters.collection.empty())
|
476
|
+
serialize(action.parameters.collection, 3, os);
|
477
|
+
|
478
|
+
// Examples
|
479
|
+
serialize(SerializeKey::Examples, std::string(), 3, os);
|
480
|
+
|
481
|
+
if (!action.examples.collection.empty()) {
|
482
|
+
for (Collection<SourceMap<TransactionExample> >::const_iterator it = action.examples.collection.begin();
|
483
|
+
it != action.examples.collection.end();
|
484
|
+
++it) {
|
485
|
+
|
243
486
|
serialize(*it, os);
|
244
487
|
}
|
245
488
|
}
|
@@ -261,11 +504,13 @@ static void serialize(const Resource& resource, std::ostream &os)
|
|
261
504
|
|
262
505
|
// Model
|
263
506
|
serialize(SerializeKey::Model, std::string(), 2, os);
|
507
|
+
|
264
508
|
if (!resource.model.name.empty())
|
265
509
|
serialize(resource.model, 3, false, os);
|
266
510
|
|
267
511
|
// Parameters
|
268
512
|
serialize(SerializeKey::Parameters, std::string(), 2, os);
|
513
|
+
|
269
514
|
if (!resource.parameters.empty())
|
270
515
|
serialize(resource.parameters, 2, os);
|
271
516
|
|
@@ -275,7 +520,50 @@ static void serialize(const Resource& resource, std::ostream &os)
|
|
275
520
|
if (resource.actions.empty())
|
276
521
|
return;
|
277
522
|
|
278
|
-
for (Collection<Action>::const_iterator it = resource.actions.begin();
|
523
|
+
for (Collection<Action>::const_iterator it = resource.actions.begin();
|
524
|
+
it != resource.actions.end();
|
525
|
+
++it) {
|
526
|
+
|
527
|
+
serialize(*it, os);
|
528
|
+
}
|
529
|
+
}
|
530
|
+
|
531
|
+
/** Serialize Resource source map */
|
532
|
+
static void serialize(const SourceMap<Resource>& resource, std::ostream &os)
|
533
|
+
{
|
534
|
+
os << " - "; // indent 2
|
535
|
+
|
536
|
+
// Name
|
537
|
+
serialize(SerializeKey::Name, resource.name, 2, os, true);
|
538
|
+
|
539
|
+
// Description
|
540
|
+
serialize(SerializeKey::Description, resource.description, 2, os);
|
541
|
+
|
542
|
+
// URI Template
|
543
|
+
serialize(SerializeKey::URITemplate, resource.uriTemplate, 2, os);
|
544
|
+
|
545
|
+
// Model
|
546
|
+
serialize(SerializeKey::Model, std::string(), 2, os);
|
547
|
+
|
548
|
+
if (!resource.model.name.sourceMap.empty())
|
549
|
+
serialize(resource.model, 3, false, os);
|
550
|
+
|
551
|
+
// Parameters
|
552
|
+
serialize(SerializeKey::Parameters, std::string(), 2, os);
|
553
|
+
|
554
|
+
if (!resource.parameters.collection.empty())
|
555
|
+
serialize(resource.parameters.collection, 2, os);
|
556
|
+
|
557
|
+
// Actions
|
558
|
+
serialize(SerializeKey::Actions, std::string(), 2, os);
|
559
|
+
|
560
|
+
if (resource.actions.collection.empty())
|
561
|
+
return;
|
562
|
+
|
563
|
+
for (Collection<SourceMap<Action> >::const_iterator it = resource.actions.collection.begin();
|
564
|
+
it != resource.actions.collection.end();
|
565
|
+
++it) {
|
566
|
+
|
279
567
|
serialize(*it, os);
|
280
568
|
}
|
281
569
|
}
|
@@ -297,7 +585,35 @@ static void serialize(const ResourceGroup& group, std::ostream &os)
|
|
297
585
|
if (group.resources.empty())
|
298
586
|
return;
|
299
587
|
|
300
|
-
for (Collection<Resource>::const_iterator it = group.resources.begin();
|
588
|
+
for (Collection<Resource>::const_iterator it = group.resources.begin();
|
589
|
+
it != group.resources.end();
|
590
|
+
++it) {
|
591
|
+
|
592
|
+
serialize(*it, os);
|
593
|
+
}
|
594
|
+
}
|
595
|
+
|
596
|
+
/** Serialize Resource Group source map */
|
597
|
+
static void serialize(const SourceMap<ResourceGroup>& group, std::ostream &os)
|
598
|
+
{
|
599
|
+
os << "- "; // indent 1
|
600
|
+
|
601
|
+
// Name
|
602
|
+
serialize(SerializeKey::Name, group.name, 1, os, true);
|
603
|
+
|
604
|
+
// Description
|
605
|
+
serialize(SerializeKey::Description, group.description, 1, os);
|
606
|
+
|
607
|
+
// Resources
|
608
|
+
serialize(SerializeKey::Resources, std::string(), 1, os);
|
609
|
+
|
610
|
+
if (group.resources.collection.empty())
|
611
|
+
return;
|
612
|
+
|
613
|
+
for (Collection<SourceMap<Resource> >::const_iterator it = group.resources.collection.begin();
|
614
|
+
it != group.resources.collection.end();
|
615
|
+
++it) {
|
616
|
+
|
301
617
|
serialize(*it, os);
|
302
618
|
}
|
303
619
|
}
|
@@ -319,6 +635,7 @@ static void serialize(const Blueprint& blueprint, std::ostream &os)
|
|
319
635
|
|
320
636
|
// Resource Groups
|
321
637
|
serialize(SerializeKey::ResourceGroups, std::string(), 0, os);
|
638
|
+
|
322
639
|
if (blueprint.resourceGroups.empty())
|
323
640
|
return;
|
324
641
|
|
@@ -330,7 +647,38 @@ static void serialize(const Blueprint& blueprint, std::ostream &os)
|
|
330
647
|
}
|
331
648
|
}
|
332
649
|
|
650
|
+
/** Serialize Blueprint source map */
|
651
|
+
static void serialize(const SourceMap<Blueprint>& blueprint, std::ostream &os)
|
652
|
+
{
|
653
|
+
// Metadata
|
654
|
+
serialize(blueprint.metadata.collection, os);
|
655
|
+
|
656
|
+
// API Name
|
657
|
+
serialize(SerializeKey::Name, blueprint.name, 0, os);
|
658
|
+
|
659
|
+
// API Description
|
660
|
+
serialize(SerializeKey::Description, blueprint.description, 0, os);
|
661
|
+
|
662
|
+
// Resource Groups
|
663
|
+
serialize(SerializeKey::ResourceGroups, std::string(), 0, os);
|
664
|
+
|
665
|
+
if (blueprint.resourceGroups.collection.empty())
|
666
|
+
return;
|
667
|
+
|
668
|
+
for (Collection<SourceMap<ResourceGroup> >::type::const_iterator it = blueprint.resourceGroups.collection.begin();
|
669
|
+
it != blueprint.resourceGroups.collection.end();
|
670
|
+
++it) {
|
671
|
+
|
672
|
+
serialize(*it, os);
|
673
|
+
}
|
674
|
+
}
|
675
|
+
|
333
676
|
void snowcrash::SerializeYAML(const snowcrash::Blueprint& blueprint, std::ostream &os)
|
334
677
|
{
|
335
678
|
serialize(blueprint, os);
|
336
679
|
}
|
680
|
+
|
681
|
+
void snowcrash::SerializeSourceMapYAML(const snowcrash::SourceMap<snowcrash::Blueprint>& blueprint, std::ostream &os)
|
682
|
+
{
|
683
|
+
serialize(blueprint, os);
|
684
|
+
}
|