Skip to content

Commit

Permalink
razor template support
Browse files Browse the repository at this point in the history
tests are passing

alphabetization of dependencies

updating readme

renderFileSync for includes and layouts etc

file rendering and cleanup comments
  • Loading branch information
sirtimbly committed Jun 27, 2019
1 parent 819582d commit 72c8fec
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [pug (formerly jade)](https://github.com/pugjs/pug) [(website)](http://jade-lang.com/)
- [QEJS](https://github.com/jepso/QEJS)
- [ractive](https://github.com/Rich-Harris/Ractive)
- [razor](https://github.com/kinogam/kino.razor)
- [react](https://github.com/facebook/react)
- [slm](https://github.com/slm-lang/slm)
- [squirrelly](https://github.com/nebrelbug/squirrelly) [(website)](https://squirrelly.js.org)
Expand Down
53 changes: 53 additions & 0 deletions lib/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,59 @@ exports.swig.render = function(str, options, cb) {
});
};

/**
* Razor support.
*/

exports.razor = function(path, options, cb) {
return promisify(cb, function(cb) {
var engine = requires.razor;
if (!engine) {
try {
engine = requires.razor = require('razor-tmpl');

} catch (err) {

throw err;

}
}
try {

var tmpl = cache(options) || cache(options, (locals) => {
console.log('Rendering razor file', path);
return engine.renderFileSync(path, locals);
});
cb(null, tmpl(options));
} catch (err) {
cb(err);
}
});
};

/**
* razor string support.
*/

exports.razor.render = function(str, options, cb) {
return promisify(cb, function(cb) {

try {
var engine = requires.razor = require('razor-tmpl');
} catch (err) {
throw err;
}

try {
var tf = engine.compile(str);
var tmpl = cache(options) || cache(options, tf);
cb(null, tmpl(options));
} catch (err) {
cb(err);
}
});
};

/**
* Atpl support.
*/
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"pug": "^2.0.0-beta6",
"qejs": "^3.0.5",
"ractive": "^0.8.4",
"react": "^15.3.2",
"razor-tmpl": "^1.3.1",
"react": "^15.6.2",
"react-dom": "^15.3.2",
"should": "*",
"slm": "^0.5.0",
Expand Down
1 change: 1 addition & 0 deletions test/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ require('./shared').test('marko');
require('./shared').test('bracket');
require('./shared').test('teacup');
require('./shared').test('velocityjs');
require('./shared').test('razor');
require('./shared').test('squirrelly');
require('./shared/partials').test('squirrelly');
require('./shared/helpers').test('squirrelly');
1 change: 1 addition & 0 deletions test/fixtures/razor/user.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p> @locals.user.name </p>

0 comments on commit 72c8fec

Please sign in to comment.