Skip to content

Commit 72c8fec

Browse files
committed
razor template support
tests are passing alphabetization of dependencies updating readme renderFileSync for includes and layouts etc file rendering and cleanup comments
1 parent 819582d commit 72c8fec

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- [pug (formerly jade)](https://github.com/pugjs/pug) [(website)](http://jade-lang.com/)
3838
- [QEJS](https://github.com/jepso/QEJS)
3939
- [ractive](https://github.com/Rich-Harris/Ractive)
40+
- [razor](https://github.com/kinogam/kino.razor)
4041
- [react](https://github.com/facebook/react)
4142
- [slm](https://github.com/slm-lang/slm)
4243
- [squirrelly](https://github.com/nebrelbug/squirrelly) [(website)](https://squirrelly.js.org)

lib/consolidate.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,59 @@ exports.swig.render = function(str, options, cb) {
561561
});
562562
};
563563

564+
/**
565+
* Razor support.
566+
*/
567+
568+
exports.razor = function(path, options, cb) {
569+
return promisify(cb, function(cb) {
570+
var engine = requires.razor;
571+
if (!engine) {
572+
try {
573+
engine = requires.razor = require('razor-tmpl');
574+
575+
} catch (err) {
576+
577+
throw err;
578+
579+
}
580+
}
581+
try {
582+
583+
var tmpl = cache(options) || cache(options, (locals) => {
584+
console.log('Rendering razor file', path);
585+
return engine.renderFileSync(path, locals);
586+
});
587+
cb(null, tmpl(options));
588+
} catch (err) {
589+
cb(err);
590+
}
591+
});
592+
};
593+
594+
/**
595+
* razor string support.
596+
*/
597+
598+
exports.razor.render = function(str, options, cb) {
599+
return promisify(cb, function(cb) {
600+
601+
try {
602+
var engine = requires.razor = require('razor-tmpl');
603+
} catch (err) {
604+
throw err;
605+
}
606+
607+
try {
608+
var tf = engine.compile(str);
609+
var tmpl = cache(options) || cache(options, tf);
610+
cb(null, tmpl(options));
611+
} catch (err) {
612+
cb(err);
613+
}
614+
});
615+
};
616+
564617
/**
565618
* Atpl support.
566619
*/

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"pug": "^2.0.0-beta6",
6666
"qejs": "^3.0.5",
6767
"ractive": "^0.8.4",
68-
"react": "^15.3.2",
68+
"razor-tmpl": "^1.3.1",
69+
"react": "^15.6.2",
6970
"react-dom": "^15.3.2",
7071
"should": "*",
7172
"slm": "^0.5.0",

test/consolidate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ require('./shared').test('marko');
6868
require('./shared').test('bracket');
6969
require('./shared').test('teacup');
7070
require('./shared').test('velocityjs');
71+
require('./shared').test('razor');
7172
require('./shared').test('squirrelly');
7273
require('./shared/partials').test('squirrelly');
7374
require('./shared/helpers').test('squirrelly');

test/fixtures/razor/user.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p> @locals.user.name </p>

0 commit comments

Comments
 (0)