Skip to content

Commit

Permalink
Merge pull request #59 from ahx/alias-parser
Browse files Browse the repository at this point in the history
Add DSS.alias(newName, oldName) to alias a parser.
  • Loading branch information
darcyclarke committed May 5, 2015
2 parents c548838 + b2e203d commit 403af13
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions dss.js
Expand Up @@ -31,6 +31,16 @@ var dss = (function(){
_dss.parsers[name] = callback;
};

/*
* Add an alias for a parser
*
* @param (String) The name of the new variable
* @param (String) The name of the existing parser to use
*/
_dss.alias = function(newName, oldName){
_dss.parsers[newName] = _dss.parsers[oldName];
};

/*
* Trim whitespace from string
*
Expand Down Expand Up @@ -202,7 +212,7 @@ var dss = (function(){
variable = _dss.parsers[name],
index = block.indexOf(line);
line = {};
line[name] = (variable) ? variable.apply(null, [index, description, block, file]) : '';
line[name] = (variable) ? variable.apply(null, [index, description, block, file, name]) : '';

if(temp[name]){
if(!_dss.isArray(temp[name]))
Expand Down Expand Up @@ -383,13 +393,14 @@ dss.parser('state', function(i, line, block, file){
});

// Describe parsing markup
dss.parser('markup', function(i, line, block, file){
dss.parser('markup', function(i, line, block, file, parserName){

// find the next instance of a parser (if there is one based on the @ symbol)
// in order to isolate the current multi-line parser
var nextParserIndex = block.indexOf('* @', i+1),
markupLength = nextParserIndex > -1 ? nextParserIndex - i : block.length,
markup = block.split('').splice(i, markupLength).join('');
markup = block.split('').splice(i, markupLength).join(''),
parserMarker = '@' + parserName;

markup = (function(markup){
var ret = [],
Expand All @@ -406,7 +417,7 @@ dss.parser('markup', function(i, line, block, file){
if (lines.length <= 2)
line = dss.trim(line);

if (line && line != '@markup')
if (line && line != parserMarker)
ret.push(line);

});
Expand Down

0 comments on commit 403af13

Please sign in to comment.