@kosatyi/ejs 0.0.1-alpha.2 → 0.0.6

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.
Files changed (2) hide show
  1. package/README.md +126 -4
  2. package/package.json +3 -5
package/README.md CHANGED
@@ -2,10 +2,132 @@
2
2
 
3
3
  Embedded JavaScript templates
4
4
 
5
- ![npm](https://img.shields.io/npm/v/@kosatyi/ejs.svg)
6
- ![downloads](https://img.shields.io/npm/dt/@kosatyi/ejs.svg)
7
- ![license](https://img.shields.io/npm/l/@kosatyi/ejs.svg)
8
- ![github-issues](https://img.shields.io/github/issues/kosatyi/ejs.svg)
5
+ [![npm](https://img.shields.io/npm/v/@kosatyi/ejs.svg)](https://www.npmjs.com/package/@kosatyi/ejs)
6
+ [![github-issues](https://img.shields.io/github/issues/kosatyi/ejs.svg)](https://github.com/kosatyi/ejs/issues)
7
+ [![license](https://img.shields.io/npm/l/@kosatyi/ejs.svg)](https://github.com/kosatyi/ejs/blob/master/LICENCE)
9
8
 
9
+ ## Install
10
10
 
11
+ You can get EJS via [npm](http://npmjs.com).
11
12
 
13
+ ```bash
14
+ $ npm install @kosatyi/ejs --save
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ const ejs = require('@kosatyi/ejs');
21
+
22
+ // path where templates is located
23
+ ejs.configure({
24
+ path: 'views'
25
+ })
26
+
27
+ // add custom template helper functions
28
+ ejs.helpers({
29
+ ucase(text){
30
+ return String(text).toUpperCase()
31
+ }
32
+ })
33
+
34
+ // load index.ejs template from `views` folder
35
+ ejs.render('page/index',{
36
+ posts:[{
37
+ title:'Post Title',
38
+ content:"<p>post content</p>"
39
+ }]
40
+ }).then((content)=>{
41
+ console.log(content)
42
+ })
43
+ ```
44
+
45
+
46
+ ## Use with Express
47
+
48
+ ```bash
49
+ $ npm install @kosatyi/ejs --save
50
+ ```
51
+
52
+ ```js
53
+ const express = require('express')
54
+ const ejs = require('@kosatyi/ejs')
55
+ const app = express()
56
+ app.engine('ejs', ejs.__express)
57
+ app.set('views', 'views')
58
+ app.set('view engine', 'ejs')
59
+ app.set('view options', {
60
+ watch: true,
61
+ })
62
+ ```
63
+
64
+ or use `ejs` alias
65
+
66
+ ```bash
67
+ $ npm install ejs@npm:@kosatyi/ejs --save
68
+ ```
69
+
70
+ ```js
71
+ // const ejs = require('ejs')
72
+ const express = require('express')
73
+ const app = express()
74
+ app.set('views', 'views')
75
+ app.set('view engine', 'ejs')
76
+ app.set('view options', {
77
+ watch: true,
78
+ })
79
+ ```
80
+
81
+ ## Template Example
82
+
83
+ **layout/default.ejs**
84
+
85
+ ```ejs
86
+ <html>
87
+ <head>
88
+ <title><%-get('title')%></title>
89
+ <% block('resources',()=>{ %>
90
+ <link rel="stylesheet" type="text/css" href="/dist/styles.css">
91
+ <% }) %>
92
+ </head>
93
+ <body>
94
+ <header>
95
+ <% block('header',()=>{ %>
96
+ <h1><%-get('title')%></h1>
97
+ <% }) %>
98
+ </header>
99
+ <main>
100
+ <% block('content') %>
101
+ </main>
102
+ <footer>
103
+ <% block('footer',()=>{ %>
104
+ Copyright
105
+ <% }) %>
106
+ </footer>
107
+ </body>
108
+ </html>
109
+ ```
110
+
111
+ **page/index.ejs**
112
+
113
+ ```ejs
114
+ <% extend('layout/default') %>
115
+
116
+ <% set('title','Page Title') %>
117
+
118
+ <% block('resources',(parent)=>{ %>
119
+ <% parent() %>
120
+ <script defer src="/dist/framework.js"></script>
121
+ <% }) %>
122
+
123
+ <% block('content',()=>{ %>
124
+
125
+ <% each('posts',(post)=>{ %>
126
+ <article>
127
+ <h3><%-post.title%></h3>
128
+ <div><%=post.content%></div>
129
+ </article>
130
+ <% }) %>
131
+
132
+ <% }) %>
133
+ ```
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.1-alpha.2",
5
+ "version": "0.0.6",
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": "github:kosatyi/rollup"
26
+ "@kosatyi/rollup": "^0.0.1"
29
27
  },
30
28
  "directories": {
31
29
  "test": "test"