Skip to content

Commit 0a76421

Browse files
committed
Update README and add more tests
1 parent 5bc5b5f commit 0a76421

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Do you use Angular? Are you tired of putting your templates in separate files or
33

44
With the angular-jsx library you can use JSX directly in your directives. JSX templates are converted to strings that Angular can understand.
55

6-
## Example
6+
## Example 1
77
### Input
88
```
99
angular.module("foo").directive("bar",
@@ -24,6 +24,34 @@ angular.module("foo").directive("bar",
2424
}
2525
);
2626
```
27+
## Example 2
28+
### Input
29+
```
30+
angular.module("foo").directive("bar",
31+
function() {
32+
return {
33+
template: (
34+
<div>
35+
<h1>Multi-line example</h1>
36+
<div class="bar">This is a bit more <em>advanced</em>.</div>
37+
</div>
38+
)
39+
}
40+
}
41+
);
42+
```
43+
### Output
44+
```
45+
angular.module("foo").directive("bar",
46+
function() {
47+
return {
48+
template: (
49+
"<div>\n <h1>Multi-line example</h1>\n <div class=\"bar\">This is a bit more <em>advanced</em>.</div>\n</div>"
50+
)
51+
}
52+
}
53+
);
54+
```
2755
## Usage
2856
```
2957
var angularjsx = require("angular-jsx");

test/fixtures/1in.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
angular.module("foo").directive("bar",
2+
function() {
3+
return {
4+
template: (
5+
<div>
6+
<h1>Multi-line example</h1>
7+
<div class="bar">This is a bit more <em>advanced</em>.</div>
8+
</div>
9+
)
10+
}
11+
}
12+
);

test/fixtures/1out.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
angular.module("foo").directive("bar",
2+
function() {
3+
return {
4+
template: (
5+
"<div>\n <h1>Multi-line example</h1>\n <div class=\"bar\">This is a bit more <em>advanced</em>.</div>\n</div>"
6+
)
7+
}
8+
}
9+
);

test/test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ describe("angularjsx", function () {
3030
it("should handle parentheses", function () {
3131
assert.equal(angularjsx.convert("var x = {template: (<br/>)}"), "var x = {template: (\"<br/>\")}");
3232
});
33-
it("should parse Angular directive", function () {
33+
it("should parse simple template in Angular directive", function () {
3434
assertFixture(0);
3535
});
3636

37+
it("should parse multi-line template in Angular directive", function () {
38+
assertFixture(1);
39+
});
40+
3741
function assertFixture(index) {
3842
var fs = require("fs");
3943

0 commit comments

Comments
 (0)