Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some post-rigging directives to the output (will be used when …
…generating sourcemaps, etc)
- Loading branch information
Damon Oehlman
committed
Oct 12, 2012
1 parent
0204e4a
commit e6c377a
Showing
11 changed files
with
121 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
exports.decode = function(text) { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var _ = require('underscore'); | ||
|
||
exports.encode = function(rigger, matchData, sourceLine, callback) { | ||
callback(null, { | ||
filename: matchData[3], | ||
start: sourceLine | ||
}); | ||
}; | ||
|
||
exports.decode = function(text) { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
var async = require('async'), | ||
debug = require('debug')('rigger'), | ||
_ = require('underscore'), | ||
reCommentInclude = /^(.*)?\=(.*)$/, | ||
actionDirectives = { | ||
'include': { | ||
pre: ['INC'], | ||
post: ['EOI'] | ||
} | ||
}, | ||
trailingComments = { | ||
'/*': ' */' | ||
}; | ||
|
||
exports.decode = function(input) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
|
||
require('./' + directive.toLowerCase()).decode.apply(null, args); | ||
}; | ||
|
||
exports.wrap = function(rigger, output, matchData, sourceLine, callback) { | ||
var action = matchData[2], | ||
directives = actionDirectives[action], | ||
allDirectives = (directives.pre || []).concat(directives.post || []), | ||
commentLeader = matchData[0].replace(reCommentInclude, '$1'), | ||
commentTrailer = trailingComments[commentLeader] || ''; | ||
|
||
// if we don't have directives, then trigger the callback joining the lines | ||
if (! directives) return callback(null, output.join(rigger.lineEnding)); | ||
|
||
// run the directives | ||
async.map( | ||
allDirectives, | ||
function(code, itemCallback) { | ||
var encoder = require('./' + code.toLowerCase()).encode; | ||
|
||
// if we have no encoder, then proceed to the next item | ||
if (! encoder) return itemCallback(null, { code: code }); | ||
|
||
// trigger the encoder, and pass on the result | ||
encoder(rigger, matchData, sourceLine, function(err, data) { | ||
itemCallback(err, err ? null : _.defaults(data, { code: code })); | ||
}); | ||
}, | ||
function(err, results) { | ||
if (err) return callback(err); | ||
|
||
// iterate through the results and format appropriately | ||
_.filter(results, _.identity).forEach(function(result) { | ||
var directive = result.code.toUpperCase(), | ||
isPre = (directives.pre || []).indexOf(result.code) >= 0, | ||
arrayTweak = Array.prototype[isPre ? 'unshift' : 'push']; | ||
|
||
// remove the directive from the result | ||
delete result.code; | ||
|
||
// add the directive line | ||
arrayTweak.call( | ||
output, | ||
commentLeader + ' ' + directive + '>>> ' + | ||
JSON.stringify(result) + commentTrailer | ||
); | ||
}); | ||
|
||
// return the output | ||
callback(null, output.join(rigger.lineEnding)); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--reporter spec | ||
--timeout 30s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
// INC>>> {"filename":"noincludes-notavailable : noincludes","start":0} | ||
function Test() { | ||
} | ||
} | ||
// EOI>>> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/* INC>>> {"filename":"noincludes","start":0} */ | ||
body { | ||
background: red; | ||
} | ||
} | ||
/* EOI>>> {} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
// ::[INC|noincludes|1-]:: | ||
function Test() { | ||
} | ||
// ::[EOI]:: | ||
|
||
var a = 10; | ||
// ::[INC|../includes/simple|1-]:: | ||
var a = 10; | ||
// ::[EOI]:: |