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

Generate Knockout.js virtual elements #958

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 15 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,21 @@ outputs:
</head>
```

Jade supports generating [Knockout](http://knockoutjs.com/) virtual elements, for example:

```jade
//ko if: true
#test
```

outputs:

```html
<!-- ko if: true -->
<div id="test"></div>
<!-- /ko -->
```

<a name="a6-6"/>
### Nesting

Expand Down
5 changes: 5 additions & 0 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Copy link
Member

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.

this.buffer('<!-- ' + comment.val.trim() + ' -->');
this.visit(comment.block);
this.buffer('\\n');
this.buffer('<!-- /ko -->');
} else {
this.buffer('<!--' + comment.val);
this.visit(comment.block);
Expand Down
3 changes: 3 additions & 0 deletions test/cases/comments.knockout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- ko if: true -->
<div id="test"></div>
<!-- /ko -->
3 changes: 3 additions & 0 deletions test/cases/comments.knockout.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

//ko if: true
#test