@kosatyi/ejs 0.0.1-alpha.1 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENCE +21 -0
- package/README.md +134 -1
- package/dist/ejs.cjs +18 -28
- package/dist/ejs.js +18 -28
- package/dist/ejs.mjs +21 -29
- package/package.json +3 -5
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Stepan Kosatyi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# EJS
|
|
2
|
+
|
|
3
|
+
Embedded JavaScript templates
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
You can get EJS via [npm](http://npmjs.com).
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
$ npm install @kosatyi/ejs --save
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const ejs = require('@kosatyi/ejs');
|
|
22
|
+
|
|
23
|
+
// path where templates is located (views by default so you can skip this step)
|
|
24
|
+
ejs.configure({
|
|
25
|
+
path: 'views'
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// add custom template helper functions
|
|
29
|
+
ejs.helpers({
|
|
30
|
+
ucase(text){
|
|
31
|
+
return String(text).toUpperCase()
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// load index.ejs template from `views` folder
|
|
36
|
+
ejs.render('page/index',{
|
|
37
|
+
posts:[{
|
|
38
|
+
title:'Post Title',
|
|
39
|
+
content:"<p>post content</p>"
|
|
40
|
+
}]
|
|
41
|
+
}).then((content)=>{
|
|
42
|
+
console.log(content)
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Use with Express
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
$ npm install @kosatyi/ejs --save
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const express = require('express')
|
|
55
|
+
const ejs = require('@kosatyi/ejs')
|
|
56
|
+
const app = express()
|
|
57
|
+
app.engine('ejs', ejs.__express)
|
|
58
|
+
app.set('views', 'views')
|
|
59
|
+
app.set('view engine', 'ejs')
|
|
60
|
+
app.set('view options', {
|
|
61
|
+
watch: true,
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
or use `ejs` alias
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
$ npm install ejs@npm:@kosatyi/ejs --save
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
// const ejs = require('ejs')
|
|
73
|
+
const express = require('express')
|
|
74
|
+
const app = express()
|
|
75
|
+
app.set('views', 'views')
|
|
76
|
+
app.set('view engine', 'ejs')
|
|
77
|
+
app.set('view options', {
|
|
78
|
+
watch: true,
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Template Example
|
|
83
|
+
|
|
84
|
+
**layout/default.ejs**
|
|
85
|
+
|
|
86
|
+
```ejs
|
|
87
|
+
<html>
|
|
88
|
+
<head>
|
|
89
|
+
<title><%-get('title')%></title>
|
|
90
|
+
<% block('resources',()=>{ %>
|
|
91
|
+
<link rel="stylesheet" type="text/css" href="/dist/styles.css">
|
|
92
|
+
<% }) %>
|
|
93
|
+
</head>
|
|
94
|
+
<body>
|
|
95
|
+
<header>
|
|
96
|
+
<% block('header',()=>{ %>
|
|
97
|
+
<h1><%-get('title')%></h1>
|
|
98
|
+
<% }) %>
|
|
99
|
+
</header>
|
|
100
|
+
<main>
|
|
101
|
+
<% block('content') %>
|
|
102
|
+
</main>
|
|
103
|
+
<footer>
|
|
104
|
+
<% block('footer',()=>{ %>
|
|
105
|
+
Copyright
|
|
106
|
+
<% }) %>
|
|
107
|
+
</footer>
|
|
108
|
+
</body>
|
|
109
|
+
</html>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**page/index.ejs**
|
|
113
|
+
|
|
114
|
+
```ejs
|
|
115
|
+
<% extend('layout/default') %>
|
|
116
|
+
|
|
117
|
+
<% set('title','Page Title') %>
|
|
118
|
+
|
|
119
|
+
<% block('resources',(parent)=>{ %>
|
|
120
|
+
<% parent() %>
|
|
121
|
+
<script defer src="/dist/framework.js"></script>
|
|
122
|
+
<% }) %>
|
|
123
|
+
|
|
124
|
+
<% block('content',()=>{ %>
|
|
125
|
+
|
|
126
|
+
<% each('posts',(post)=>{ %>
|
|
127
|
+
<article>
|
|
128
|
+
<h3><%-post.title%></h3>
|
|
129
|
+
<div><%=post.content%></div>
|
|
130
|
+
</article>
|
|
131
|
+
<% }) %>
|
|
132
|
+
|
|
133
|
+
<% }) %>
|
|
134
|
+
```
|
package/dist/ejs.cjs
CHANGED
|
@@ -905,41 +905,31 @@ function init(options) {
|
|
|
905
905
|
view.cache = Cache(config);
|
|
906
906
|
view.template = Template(config, view.cache, view.compile);
|
|
907
907
|
return view;
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
* @param callback
|
|
915
|
-
* @return {*}
|
|
916
|
-
* @private
|
|
917
|
-
*/
|
|
908
|
+
},
|
|
909
|
+
__express: function __express(name, options, callback) {
|
|
910
|
+
if (isFunction(options)) {
|
|
911
|
+
callback = options;
|
|
912
|
+
options = {};
|
|
913
|
+
}
|
|
918
914
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
915
|
+
options = options || {};
|
|
916
|
+
var settings = options.settings || {};
|
|
917
|
+
var viewPath = settings['views'];
|
|
918
|
+
var viewOptions = settings['view options'] || {};
|
|
919
|
+
var filename = path__default["default"].relative(viewPath, name);
|
|
920
|
+
viewOptions.path = viewPath;
|
|
921
|
+
view.configure(viewOptions);
|
|
922
|
+
return view.render(filename, options).then(function (content) {
|
|
923
|
+
callback(null, content);
|
|
924
|
+
})["catch"](function (error) {
|
|
925
|
+
callback(error);
|
|
926
|
+
});
|
|
923
927
|
}
|
|
924
|
-
|
|
925
|
-
options = options || {};
|
|
926
|
-
var settings = options.settings || {};
|
|
927
|
-
var viewPath = settings['views'];
|
|
928
|
-
var viewOptions = settings['view options'] || {};
|
|
929
|
-
var filename = path__default["default"].relative(viewPath, name);
|
|
930
|
-
viewOptions.path = viewPath;
|
|
931
|
-
view.configure(viewOptions);
|
|
932
|
-
return view.render(filename, options).then(function (content) {
|
|
933
|
-
callback(null, content);
|
|
934
|
-
})["catch"](function (error) {
|
|
935
|
-
callback(error);
|
|
936
|
-
});
|
|
937
928
|
};
|
|
938
929
|
/**
|
|
939
930
|
*
|
|
940
931
|
*/
|
|
941
932
|
|
|
942
|
-
|
|
943
933
|
view.configure(options || {});
|
|
944
934
|
/**
|
|
945
935
|
*
|
package/dist/ejs.js
CHANGED
|
@@ -901,41 +901,31 @@
|
|
|
901
901
|
view.cache = Cache(config);
|
|
902
902
|
view.template = Template(config, view.cache, view.compile);
|
|
903
903
|
return view;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
* @param callback
|
|
911
|
-
* @return {*}
|
|
912
|
-
* @private
|
|
913
|
-
*/
|
|
904
|
+
},
|
|
905
|
+
__express: function __express(name, options, callback) {
|
|
906
|
+
if (isFunction(options)) {
|
|
907
|
+
callback = options;
|
|
908
|
+
options = {};
|
|
909
|
+
}
|
|
914
910
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
911
|
+
options = options || {};
|
|
912
|
+
var settings = options.settings || {};
|
|
913
|
+
var viewPath = settings['views'];
|
|
914
|
+
var viewOptions = settings['view options'] || {};
|
|
915
|
+
var filename = path.relative(viewPath, name);
|
|
916
|
+
viewOptions.path = viewPath;
|
|
917
|
+
view.configure(viewOptions);
|
|
918
|
+
return view.render(filename, options).then(function (content) {
|
|
919
|
+
callback(null, content);
|
|
920
|
+
})["catch"](function (error) {
|
|
921
|
+
callback(error);
|
|
922
|
+
});
|
|
919
923
|
}
|
|
920
|
-
|
|
921
|
-
options = options || {};
|
|
922
|
-
var settings = options.settings || {};
|
|
923
|
-
var viewPath = settings['views'];
|
|
924
|
-
var viewOptions = settings['view options'] || {};
|
|
925
|
-
var filename = path.relative(viewPath, name);
|
|
926
|
-
viewOptions.path = viewPath;
|
|
927
|
-
view.configure(viewOptions);
|
|
928
|
-
return view.render(filename, options).then(function (content) {
|
|
929
|
-
callback(null, content);
|
|
930
|
-
})["catch"](function (error) {
|
|
931
|
-
callback(error);
|
|
932
|
-
});
|
|
933
924
|
};
|
|
934
925
|
/**
|
|
935
926
|
*
|
|
936
927
|
*/
|
|
937
928
|
|
|
938
|
-
|
|
939
929
|
view.configure(options || {});
|
|
940
930
|
/**
|
|
941
931
|
*
|
package/dist/ejs.mjs
CHANGED
|
@@ -871,35 +871,27 @@ function init(options) {
|
|
|
871
871
|
view.template = Template(config, view.cache, view.compile);
|
|
872
872
|
return view
|
|
873
873
|
},
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
return view
|
|
896
|
-
.render(filename, options)
|
|
897
|
-
.then((content) => {
|
|
898
|
-
callback(null, content);
|
|
899
|
-
})
|
|
900
|
-
.catch((error) => {
|
|
901
|
-
callback(error);
|
|
902
|
-
})
|
|
874
|
+
__express(name, options, callback) {
|
|
875
|
+
if (isFunction(options)) {
|
|
876
|
+
callback = options;
|
|
877
|
+
options = {};
|
|
878
|
+
}
|
|
879
|
+
options = options || {};
|
|
880
|
+
const settings = options.settings || {};
|
|
881
|
+
const viewPath = settings['views'];
|
|
882
|
+
const viewOptions = settings['view options'] || {};
|
|
883
|
+
const filename = path.relative(viewPath, name);
|
|
884
|
+
viewOptions.path = viewPath;
|
|
885
|
+
view.configure(viewOptions);
|
|
886
|
+
return view
|
|
887
|
+
.render(filename, options)
|
|
888
|
+
.then((content) => {
|
|
889
|
+
callback(null, content);
|
|
890
|
+
})
|
|
891
|
+
.catch((error) => {
|
|
892
|
+
callback(error);
|
|
893
|
+
})
|
|
894
|
+
},
|
|
903
895
|
};
|
|
904
896
|
/**
|
|
905
897
|
*
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@kosatyi/ejs",
|
|
3
3
|
"description": "EJS Templates",
|
|
4
4
|
"homepage": "https://github.com/kosatyi/ejs",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.5",
|
|
6
6
|
"main": "dist/ejs.cjs",
|
|
7
7
|
"module": "dist/ejs.mjs",
|
|
8
8
|
"browser": "dist/ejs.js",
|
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
"chokidar": "^3.5.3"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
"build.js"
|
|
15
|
+
"dist"
|
|
17
16
|
],
|
|
18
17
|
"scripts": {
|
|
19
|
-
"gulp": "cd test && node build",
|
|
20
18
|
"build": "rollup -c",
|
|
21
19
|
"watch": "rollup -c -w",
|
|
22
20
|
"version": "npm run build",
|
|
@@ -25,7 +23,7 @@
|
|
|
25
23
|
},
|
|
26
24
|
"devDependencies": {
|
|
27
25
|
"@babel/preset-env": "^7.18.6",
|
|
28
|
-
"@kosatyi/rollup": "
|
|
26
|
+
"@kosatyi/rollup": "^0.0.1"
|
|
29
27
|
},
|
|
30
28
|
"directories": {
|
|
31
29
|
"test": "test"
|