From 72c8fecbc8d52b9798db2897c45280535b207c44 Mon Sep 17 00:00:00 2001 From: Tim Bendt Date: Tue, 30 Oct 2018 14:19:14 -0600 Subject: [PATCH] razor template support tests are passing alphabetization of dependencies updating readme renderFileSync for includes and layouts etc file rendering and cleanup comments --- Readme.md | 1 + lib/consolidate.js | 53 ++++++++++++++++++++++++++++++++++ package.json | 3 +- test/consolidate.js | 1 + test/fixtures/razor/user.razor | 1 + 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/razor/user.razor diff --git a/Readme.md b/Readme.md index e4b6db7..187ace9 100644 --- a/Readme.md +++ b/Readme.md @@ -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) diff --git a/lib/consolidate.js b/lib/consolidate.js index 4663ac3..5024519 100644 --- a/lib/consolidate.js +++ b/lib/consolidate.js @@ -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. */ diff --git a/package.json b/package.json index ade2628..cb34bc0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/consolidate.js b/test/consolidate.js index eb668d9..193f329 100644 --- a/test/consolidate.js +++ b/test/consolidate.js @@ -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'); diff --git a/test/fixtures/razor/user.razor b/test/fixtures/razor/user.razor new file mode 100644 index 0000000..d939f72 --- /dev/null +++ b/test/fixtures/razor/user.razor @@ -0,0 +1 @@ +

@locals.user.name