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

Update to add renderAsString option for ejs templates #67

Merged
merged 4 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add can namespace to EJS helpers by default; add tests; move EJS view…
… registration into can-ejs from can-legacy-view-helpers
  • Loading branch information
bmomberger-bitovi committed Apr 11, 2019
commit 144e8db435e737a49faa9378c075472f09faafff
20 changes: 20 additions & 0 deletions can-ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var each = require("can-util/js/each/each");
var canReflect = require("can-reflect");
var observationReader = require("can-stache-key");
var DOCUMENT = require('can-globals/document/document');
var view = legacyHelpers.view;

var templateId = 0;
// ## Helper methods
Expand Down Expand Up @@ -175,6 +176,7 @@ extend(EJS.prototype, {
EJS.Helpers = function (data, extras) {
this._data = data;
this._extras = extras;
this.can = namespace;
extend(this, extras);
};

Expand Down Expand Up @@ -209,5 +211,23 @@ EJS.from = function(id){
return templates[id];
};

view.register({
suffix: 'ejs',
script: function (id, src) {
return 'can.EJS(function(_CONTEXT,_VIEW) { ' + new EJS({
text: src,
name: id
})
.template.out + ' })';
},
renderer: function (id, text) {
return EJS({
text: text,
name: id
});
}
});


module.exports = EJS;

Loading