-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daded06
commit f48ee4d
Showing
14 changed files
with
233 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,108 @@ | ||
etpl-loader | ||
=========== | ||
|
||
[![NPM version](https://img.shields.io/npm/v/etpl-loader.svg)](https://www.npmjs.com/package/etpl-loader) | ||
[![NPM downloads](https://img.shields.io/npm/dm/etpl-loader.svg)](https://www.npmjs.com/package/etpl-loader) | ||
[![Build Status](https://travis-ci.org/d-band/etpl-loader.svg?branch=master)](https://travis-ci.org/d-band/etpl-loader) | ||
[![Coverage Status](https://coveralls.io/repos/github/d-band/etpl-loader/badge.svg?branch=master)](https://coveralls.io/github/d-band/etpl-loader?branch=master) | ||
[![Dependency Status](https://david-dm.org/d-band/etpl-loader.svg)](https://david-dm.org/d-band/etpl-loader) | ||
|
||
## Install | ||
|
||
``` | ||
npm i etpl-loader -S | ||
``` | ||
``` | ||
|
||
## Usage | ||
|
||
**index.tpl** | ||
``` | ||
<p><%=name%></p> | ||
<p><%=email%></p> | ||
<ul> | ||
<%for (var i=0; i<skills.length; i++) {var skill = skills[i];%> | ||
<li><%-skill%></li> | ||
<%}%> | ||
</ul> | ||
<div> | ||
<%projects.forEach((project) => {%> | ||
<div> | ||
<h3><%-project.name%></h3> | ||
<p><%=project.description%></p> | ||
</div> | ||
<%});%> | ||
</div> | ||
<%include('footer.tpl')%> | ||
``` | ||
|
||
**footer.tpl** | ||
``` | ||
<div>Copyright © <%=site.year%> <%=site.name%>. All Rights Reserved.</div> | ||
``` | ||
|
||
**index.js** | ||
``` | ||
import tpl from './index.tpl'; | ||
window.ENCODE = (str) => { | ||
return String(str) | ||
.replace(/&/g, '&') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>'); | ||
}; | ||
document.getElementById('root').innerHTML = tpl({ | ||
name: 'hello', | ||
email: 'hello@example.com', | ||
skills: [ | ||
'<a href="https://en.wikipedia.org/wiki/JavaScript">JavaScript</a>', | ||
'<a href="https://www.oracle.com/java/">Java</a>', | ||
'<a href="https://en.wikipedia.org/wiki/C%2B%2B">C++</a>', | ||
'<a href="https://golang.org">Go</a>' | ||
], | ||
projects: [{ | ||
name: '<a href="https://github.com/d-band/etpl-loader">etpl-loader</a>', | ||
description: 'Ejs template webpack loader.' | ||
}, { | ||
name: '<a href="https://github.com/d-band/dool">dool</a>', | ||
description: 'Build tool based on webpack.' | ||
}, { | ||
name: '<a href="https://github.com/d-band/yax">yax</a>', | ||
description: 'Yet another store using redux.' | ||
}], | ||
site: { | ||
name: 'D-Band', | ||
year: '2018' | ||
} | ||
}); | ||
``` | ||
|
||
**webpack.config.js** | ||
``` | ||
module.exports = { | ||
module: { | ||
rules: [{ | ||
test: /\.tpl$/, | ||
use: 'etpl-loader' | ||
}] | ||
} | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
|Name|Type|Default|Description| | ||
|:--:|:--:|:-----:|:----------| | ||
|**`globals`|`{Array}`|`['window', 'console']`|Global variables| | ||
|**`encode`|`{String}`|`'ENCODE'`|Encode function name| | ||
|
||
## Report a issue | ||
|
||
* [All issues](https://github.com/d-band/etpl-loader/issues) | ||
* [New issue](https://github.com/d-band/etpl-loader/issues/new) | ||
|
||
## License | ||
|
||
etpl-loader is available under the terms of the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div>Copyright © <%=site.year%> <%=site.name%>. All Rights Reserved.</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Simple</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script src="dist/index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
import tpl from './template.tpl'; | ||
import tpl from './index.tpl'; | ||
|
||
console.log(tpl({ | ||
window.ENCODE = (str) => { | ||
return String(str) | ||
.replace(/&/g, '&') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>'); | ||
}; | ||
|
||
document.getElementById('root').innerHTML = tpl({ | ||
name: 'hello', | ||
code: 'world', | ||
list: ['a', 'b', 'c'] | ||
})); | ||
email: 'hello@example.com', | ||
skills: [ | ||
'<a href="https://en.wikipedia.org/wiki/JavaScript">JavaScript</a>', | ||
'<a href="https://www.oracle.com/java/">Java</a>', | ||
'<a href="https://en.wikipedia.org/wiki/C%2B%2B">C++</a>', | ||
'<a href="https://golang.org">Go</a>' | ||
], | ||
projects: [{ | ||
name: '<a href="https://github.com/d-band/etpl-loader">etpl-loader</a>', | ||
description: 'Ejs template webpack loader.' | ||
}, { | ||
name: '<a href="https://github.com/d-band/dool">dool</a>', | ||
description: 'Build tool based on webpack.' | ||
}, { | ||
name: '<a href="https://github.com/d-band/yax">yax</a>', | ||
description: 'Yet another store using redux.' | ||
}], | ||
site: { | ||
name: 'D-Band', | ||
year: '2018' | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<p><%=name%></p> | ||
<p><%=email%></p> | ||
<ul> | ||
<%for (var i=0; i<skills.length; i++) {var skill = skills[i];%> | ||
<li><%-skill%></li> | ||
<%}%> | ||
</ul> | ||
<div> | ||
<%projects.forEach((project) => {%> | ||
<div> | ||
<h3><%-project.name%></h3> | ||
<p><%=project.description%></p> | ||
</div> | ||
<%});%> | ||
</div> | ||
<%include('footer.tpl')%> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.