Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Rename exportSourcemap to generateSourceMap
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Dec 15, 2015
1 parent 553bd8c commit fe2578b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Options can be passed to the parser as an optional second argument to both the a

```js
var options = {
exportSourcemap: true
generateSourceMap: true
}
protagonist.parse('# My API', options, callback);
```
Expand All @@ -60,7 +60,7 @@ The available options are:
Name | Description
---------------------- | ----------------------------------------------------------
`requireBlueprintName` | Require parsed blueprints have a title (default: false)
`exportSourcemap` | Enable sourcemap generation (default: false)
`generateSourceMap` | Enable sourcemap generation (default: false)
`type` | Set the output structure type as either `ast` or `refract` (default: `refract`)

### Parsing Result
Expand Down
5 changes: 3 additions & 2 deletions src/options_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using namespace protagonist;
//static const std::string RenderDescriptionsOptionKey = "renderDescriptions";
static const std::string RequireBlueprintNameOptionKey = "requireBlueprintName";
static const std::string ExportSourcemapOptionKey = "exportSourcemap";
static const std::string GenerateSourceMapOptionKey = "generateSourceMap";
static const std::string TypeOptionKey = "type";

static const std::string TypeOptionAst = "ast";
Expand Down Expand Up @@ -35,7 +36,7 @@ OptionsResult* protagonist::ParseOptionsObject(Handle<Object> optionsObject) {
else
optionsResult->options &= snowcrash::RequireBlueprintNameOption;
}
else if (ExportSourcemapOptionKey == *strKey) {
else if (ExportSourcemapOptionKey == *strKey || GenerateSourceMapOptionKey == *strKey) {
// ExportSourcemapOption
if (value->IsTrue())
optionsResult->options |= snowcrash::ExportSourcemapOption;
Expand Down Expand Up @@ -64,7 +65,7 @@ OptionsResult* protagonist::ParseOptionsObject(Handle<Object> optionsObject) {
std::stringstream ss;
ss << "unrecognized option '" << *strKey << "', expected: ";
ss << "'" << RequireBlueprintNameOptionKey << "', '";
ss << ExportSourcemapOptionKey << "' or '" << TypeOptionKey << '"';
ss << GenerateSourceMapOptionKey << "' or '" << TypeOptionKey << '"';

optionsResult->error = ss.str().c_str();
return optionsResult;
Expand Down
23 changes: 23 additions & 0 deletions test/sourcemap-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ describe "Parser sourcemap", ->
sourcemap_fixture = require './fixtures/sample-api-sourcemap.json'
sourcemap_parsed = null

# Read & parse blueprint fixture
before (done) ->

fixture_path = path.join __dirname, './fixtures/sample-api.apib'

fs.readFile fixture_path, 'utf8', (err, data) ->
return done err if err

protagonist.parse data, { type: 'ast', generateSourceMap: true }, (err, result) ->
return done err if err

sourcemap_parsed = result.sourcemap
done()

# Parser Sourcemap should conform to recent source map serialization JSON media type
it '`sourcemap` field conforms to `vnd.apiblueprint.sourcemap+json; version=4.0`', ->
assert.deepEqual sourcemap_fixture, sourcemap_parsed

describe "Parser sourcemap with old option name", ->

sourcemap_fixture = require './fixtures/sample-api-sourcemap.json'
sourcemap_parsed = null

# Read & parse blueprint fixture
before (done) ->

Expand Down
2 changes: 1 addition & 1 deletion tools/protagonist.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (typeof args == 'undefined' || args.length !== 1) {
fs.readFile(args[0], 'utf8', function (err, data) {
if (err) throw err;

protagonist.parse(data, {exportSourcemap: true}, function (err, result) {
protagonist.parse(data, {generateSourceMap: true}, function (err, result) {
if (err) {
console.log(JSON.stringify(err, null, 2));
process.exit(err.code);
Expand Down

0 comments on commit fe2578b

Please sign in to comment.