-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Generate Knockout.js virtual elements #958
Conversation
What about passing your own Compiler ? I think it's better in your use case since this kind of things does not belong in the official compiler |
Yes, this feature does not concern an audience as large as that of the vanilla jade compiler, but forking jade just to add this feature is not very nice either... You just lost all new fixes and features that come along in jade without actively maintaining the fork. Is there a way to gracefully extend the compiler to handle what might be considered niche cases? |
Yes, you can pass it as an option - sorry I was unclear :)! |
Got it now! :) So, basically i can have a "patch" compiler that does its stuff and then pass the intermediate result to jade. |
@@ -454,6 +454,11 @@ Compiler.prototype = { | |||
this.buffer('<!--[' + comment.val.trim() + ']>'); | |||
this.visit(comment.block); | |||
this.buffer('<![endif]-->'); | |||
} else if (0 == comment.val.trim().indexOf('ko')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this still work if it was 'ko '
. If so, that would be less likely to catch things that just happened to be comments starting with ko
.
You can do something like: var Compiler = require('jade').Compiler;
function KoCompiler(node, options) {
Compiler.call(this, node, options);
}
KoCompiler.prototype = Object.create(Compiler);
KoCompiler.prototype.constructor = KoCompiler;
var oldVisitBlockComment = Compiler.prototype.visitBlockComment;
KoCompiler.prototype.visitBlockComment = function (comment) {
if (0 == comment.val.trim().indexOf('ko ')) {
this.buffer('<!-- ' + comment.val.trim() + ' -->');
this.visit(comment.block);
this.buffer('\\n');
this.buffer('<!-- /ko -->');
} else {
return oldVisitBlockComment.call(this, comment);
}
}; then just do: jade.renderFile('foo.jade', {compiler: KoCompiler}, callback); |
I don't like the idea of special-casing for any particular framework sorry! Too much of a maintenance burden |
Yes, it makes sense to close this, and ForbesLindesay' comment provides a nice solution for my problem. |
What about using jade mixin? I wrote an example here. https://gist.github.com/nashibao/7889825 mixin if(val)
<!-- ko if: #{val} -->
block
<!-- /ko --> |
Add ability to generate Knockout.js virtual elements from block comments. For example:
outputs: