Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Razor template syntax support #319

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>