mails 0.0.8 → 1.0.0
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/README.ja.md +146 -0
- package/README.md +196 -148
- package/README.zh.md +160 -0
- package/dist/cli.js +668 -0
- package/dist/index.js +411 -0
- package/package.json +39 -26
- package/skill.md +213 -0
- package/.npmignore +0 -7
- package/LICENSE +0 -19
- package/README.en.md +0 -106
- package/bin/cli +0 -3
- package/index.js +0 -6
- package/libs/cli.js +0 -58
- package/libs/mail.js +0 -25
- package/libs/render.js +0 -13
- package/libs/serve.js +0 -59
package/LICENSE
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2013 turing
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
|
11
|
-
all copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
THE SOFTWARE.
|
package/README.en.md
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
##  mails 
|
|
2
|
-
|
|
3
|
-
send beautiful emails made easy, with responsive templates built in.
|
|
4
|
-
|
|
5
|
-
mails supports [ink](http://zurb.com/ink) responsive email template now!
|
|
6
|
-
|
|
7
|
-
### Installation
|
|
8
|
-
````
|
|
9
|
-
$ npm install mails
|
|
10
|
-
````
|
|
11
|
-
|
|
12
|
-
### Example
|
|
13
|
-
````javascript
|
|
14
|
-
var mails = require('mails');
|
|
15
|
-
|
|
16
|
-
// use built in templates
|
|
17
|
-
mail.render('basic', {
|
|
18
|
-
name: 'mySite',
|
|
19
|
-
banner: 'http://mysite.com/banner.jpg'
|
|
20
|
-
}, function(err,html){
|
|
21
|
-
if (!err) {
|
|
22
|
-
console.log(html);
|
|
23
|
-
} else {
|
|
24
|
-
console.log(err);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
````
|
|
28
|
-
### Built-in themes
|
|
29
|
-
mails supports several kinds of themes, they are:
|
|
30
|
-
|
|
31
|
-
- ink themes:
|
|
32
|
-
- basic
|
|
33
|
-
- hero
|
|
34
|
-
- newsletter
|
|
35
|
-
- sidebar
|
|
36
|
-
- sidebar-hero
|
|
37
|
-
- mails theme:
|
|
38
|
-
- one
|
|
39
|
-
|
|
40
|
-
#### built-in theme useage:
|
|
41
|
-
````javascript
|
|
42
|
-
var mails = require('mails');
|
|
43
|
-
|
|
44
|
-
mails.render('basic', {
|
|
45
|
-
name: 'mySite',
|
|
46
|
-
banner: 'http://mysite.com/banner.jpg'
|
|
47
|
-
}, function(err, html){
|
|
48
|
-
// do sth.
|
|
49
|
-
});
|
|
50
|
-
````
|
|
51
|
-
#### built-in theme variables:
|
|
52
|
-
take a look:
|
|
53
|
-
(screenshots coming soon...)
|
|
54
|
-
|
|
55
|
-
### Templates as NPM modules
|
|
56
|
-
you can also push templates as NPM modules, like this:
|
|
57
|
-
````javascript
|
|
58
|
-
var mails = require('mails');
|
|
59
|
-
|
|
60
|
-
// using templates named `single` under module `mails-mailmao`
|
|
61
|
-
mails.render('mails-mailmao/single', {
|
|
62
|
-
name: 'mySite',
|
|
63
|
-
banner: 'http://mysite.com/banner.jpg'
|
|
64
|
-
}, function(err, html){
|
|
65
|
-
// do sth.
|
|
66
|
-
});
|
|
67
|
-
````
|
|
68
|
-
please feel free to publish your templates to NPM.
|
|
69
|
-
|
|
70
|
-
### API
|
|
71
|
-
check this file: `index.js`
|
|
72
|
-
|
|
73
|
-
### Contributing
|
|
74
|
-
- Fork this repo
|
|
75
|
-
- Clone your repo
|
|
76
|
-
- Install dependencies
|
|
77
|
-
- Checkout a feature branch
|
|
78
|
-
- Feel free to add your features
|
|
79
|
-
- Make sure your features are fully tested
|
|
80
|
-
- Open a pull request, and enjoy <3
|
|
81
|
-
|
|
82
|
-
### MIT license
|
|
83
|
-
Copyright (c) 2013 turing
|
|
84
|
-
|
|
85
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
86
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
87
|
-
in the Software without restriction, including without limitation the rights
|
|
88
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
89
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
90
|
-
furnished to do so, subject to the following conditions:
|
|
91
|
-
|
|
92
|
-
The above copyright notice and this permission notice shall be included in
|
|
93
|
-
all copies or substantial portions of the Software.
|
|
94
|
-
|
|
95
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
96
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
97
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
98
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
99
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
100
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
101
|
-
THE SOFTWARE.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-

|
|
106
|
-
generated using [docor](https://github.com/turingou/docor.git) @ 0.1.0. brought to you by [turingou](https://github.com/turingou)
|
package/bin/cli
DELETED
package/index.js
DELETED
package/libs/cli.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
var fs = require('fs'),
|
|
2
|
-
path = require('path'),
|
|
3
|
-
exeq = require('exeq'),
|
|
4
|
-
consoler = require('consoler'),
|
|
5
|
-
optimist = require('optimist'),
|
|
6
|
-
argv = optimist.argv,
|
|
7
|
-
serve = require('./serve');
|
|
8
|
-
|
|
9
|
-
var commands = {
|
|
10
|
-
init: function(self, pkg, dir) {
|
|
11
|
-
var init = exeq([
|
|
12
|
-
'git clone https://github.com/turingou/mails-scaffold.git .',
|
|
13
|
-
'rm -rf .git',
|
|
14
|
-
'npm install'
|
|
15
|
-
]);
|
|
16
|
-
init.on('done', function(count) {
|
|
17
|
-
return consoler.success('another mail theme created, enjoy!');
|
|
18
|
-
});
|
|
19
|
-
init.run();
|
|
20
|
-
},
|
|
21
|
-
watch: function(self, pkg, dir) {
|
|
22
|
-
if (!pkg) return consoler.error('configs required');
|
|
23
|
-
pkg = pkg.toString();
|
|
24
|
-
fs.readFile(path.resolve(dir, pkg), function(err, file) {
|
|
25
|
-
if (err) return consoler.log('404', 'configs not found');
|
|
26
|
-
try {
|
|
27
|
-
var data = JSON.parse(file);
|
|
28
|
-
if (!data['view engine']) return consoler.error('view engine required');
|
|
29
|
-
try {
|
|
30
|
-
var engine = require(data['view engine']),
|
|
31
|
-
port = argv.p && !isNaN(parseInt(argv.p, 10)) ? parseInt(argv.p, 10) : 3001;
|
|
32
|
-
self.server = serve(dir, {
|
|
33
|
-
port: port,
|
|
34
|
-
engine: engine,
|
|
35
|
-
data: data,
|
|
36
|
-
pkg: path.resolve(dir, pkg)
|
|
37
|
-
});
|
|
38
|
-
return consoler.success('Mails is watching: http://localhost:' + port);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
consoler.error('view engine required');
|
|
41
|
-
consoler.error(err);
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
} catch (err) {
|
|
45
|
-
return consoler.error('configs format must be json');
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// mails(1)
|
|
52
|
-
exports = module.exports = function() {
|
|
53
|
-
var arguments = argv._,
|
|
54
|
-
command = arguments[0];
|
|
55
|
-
if (!command) return false;
|
|
56
|
-
if (!commands[command]) return false;
|
|
57
|
-
return commands[command](this, arguments[1], process.cwd());
|
|
58
|
-
};
|
package/libs/mail.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var nodemailer = require("nodemailer"),
|
|
2
|
-
render = require('./render').render;
|
|
3
|
-
|
|
4
|
-
// 发送邮件
|
|
5
|
-
exports.mail = function(params, callback) {
|
|
6
|
-
var smtpTransport = nodemailer.createTransport("SMTP", params);
|
|
7
|
-
return smtpTransport.sendMail({
|
|
8
|
-
from: params.from,
|
|
9
|
-
to: params.to,
|
|
10
|
-
subject: params.subject,
|
|
11
|
-
html: params.html
|
|
12
|
-
}, function(error, response) {
|
|
13
|
-
callback(error, response);
|
|
14
|
-
return smtpTransport.close();
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// 根据某个主题渲染并发送邮件
|
|
19
|
-
exports.send = function(tpl, params, callback) {
|
|
20
|
-
return render(tpl, params, function(err, html){
|
|
21
|
-
if (err) return callback(err);
|
|
22
|
-
params.html = html;
|
|
23
|
-
return exports.mail(params, callback);
|
|
24
|
-
});
|
|
25
|
-
};
|
package/libs/render.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
var render = require('pkghub-render'),
|
|
2
|
-
juice = require('juice').juiceContent;
|
|
3
|
-
|
|
4
|
-
// 根据给定的主题名称或者文件名称渲染邮件
|
|
5
|
-
// e.g: exports.render('mails-flat/message', {...}, callback);
|
|
6
|
-
module.exports = function(template, data, callback) {
|
|
7
|
-
var href = {};
|
|
8
|
-
render(template, data, function(err, html, dest){
|
|
9
|
-
if (err) return callback(err);
|
|
10
|
-
href.url = 'file://' + dest;
|
|
11
|
-
juice(html, href, callback);
|
|
12
|
-
});
|
|
13
|
-
}
|
package/libs/serve.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
var fs = require('fs'),
|
|
2
|
-
Tao = require('tao'),
|
|
3
|
-
path = require('path'),
|
|
4
|
-
render = require('./render');
|
|
5
|
-
|
|
6
|
-
var socketclient = function(port, html) {
|
|
7
|
-
return html + "<script src=\"http://localhost:" + (port + 1) + "/socket.io/socket.io.js\"></script><script>var socket = io.connect('http://localhost:" + (port + 1) + "');socket.on('updated', function (result) { window.location.reload(); });</script>";
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// 开发 mails 主题的辅助工具
|
|
11
|
-
// 监听本地文件变动,并实时刷新页面
|
|
12
|
-
exports = module.exports = function(dir, params, callback) {
|
|
13
|
-
|
|
14
|
-
// 初始化服务
|
|
15
|
-
var server = new Tao({
|
|
16
|
-
dir: dir,
|
|
17
|
-
port: params.port,
|
|
18
|
-
socket: true
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// 直接访问时渲染页面
|
|
22
|
-
server.use(function(req, res, next) {
|
|
23
|
-
if (req.url === '/') return res.end('ok');
|
|
24
|
-
return next();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
server.use(function(req, res, next) {
|
|
28
|
-
var file = req._parsedUrl.pathname,
|
|
29
|
-
afterfix = file.substr(file.lastIndexOf('.') + 1);
|
|
30
|
-
fs.exists(path.join(dir, file), function(exist) {
|
|
31
|
-
if (!exist) return res.end('404');
|
|
32
|
-
if (afterfix === 'json') return res.end(fs.readFileSync(path.join(dir, file)));
|
|
33
|
-
render._render({
|
|
34
|
-
template: path.join(dir, file),
|
|
35
|
-
data: JSON.parse(fs.readFileSync(params.pkg)),
|
|
36
|
-
engine: {
|
|
37
|
-
name: params.data['view engine'],
|
|
38
|
-
_engine: params.engine
|
|
39
|
-
}
|
|
40
|
-
}, function(err, html) {
|
|
41
|
-
if (err) return res.end('render error: ' + err.toString());
|
|
42
|
-
res.end(socketclient(server.configs.port, html));
|
|
43
|
-
});
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// 检测到模板变动时刷新页面
|
|
48
|
-
server.watch(function(event, file, stat) {
|
|
49
|
-
if (!(params.engine && event !== 'removed')) return false;
|
|
50
|
-
server.emit('updated', {
|
|
51
|
-
stat: 'ok',
|
|
52
|
-
file: file
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
server.run();
|
|
57
|
-
|
|
58
|
-
return server;
|
|
59
|
-
};
|