Skip to content

Commit 0eaa7e0

Browse files
author
zhuqiacheng
committed
add readme and test
1 parent e875ca1 commit 0eaa7e0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ require("html?interpolate!./file.html");
122122
```html
123123
<img src="${require(`./images/gallery.png`)}">
124124

125+
<div>${require('./components/gallery.html')}</div>
126+
```
127+
And if you only want to use `require` in template and any other `${}` are not to be translate you can set `interpolate` flag to `require`, like so:
128+
129+
```js
130+
require("html?interpolate=require!./file.ftl");
131+
```
132+
133+
```html
134+
135+
<#list list as list>
136+
<a href="${list.href!}" />${list.name}</a>
137+
</#list>
138+
139+
<img src="${require(`./images/gallery.png`)}">
140+
125141
<div>${require('./components/gallery.html')}</div>
126142
```
127143

test/loaderTest.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,11 @@ describe("loader", function() {
119119
'module.exports = "<img src=\\"" + ("Hello " + (1 + 1)) + "\\">";'
120120
);
121121
});
122+
it("should enable interpolations when using interpolate=require flag and only require function to be translate", function() {
123+
loader.call({
124+
query: "?interpolate=require"
125+
}, '<a href="${list.href}"><img src="${require(\'./test.jpg\')}" />').should.be.eql(
126+
'module.exports = "<a href="${list.href}"><img src=\\"" + require(\'./test.jpg\') + "\\">";'
127+
);
128+
});
122129
});

0 commit comments

Comments
 (0)