appmake 0.0.26 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/appmake +1 -1
- data/lib/appmake/version.rb +1 -1
- data/lib/appmake.rb +34 -5
- data/templates/bin/compile_templates.js.tt +64 -0
- data/templates/css/app.scss.tt +6 -0
- data/templates/css/body.scss.tt +2 -0
- data/templates/js/app.js.tt +4 -0
- data/templates/js/lib/doT.js.tt +135 -0
- data/templates/public/index.html.tt +11 -0
- data/templates/tpl/welcome.html.tt +2 -0
- metadata +8 -1
data/bin/appmake
CHANGED
data/lib/appmake/version.rb
CHANGED
data/lib/appmake.rb
CHANGED
@@ -1,9 +1,38 @@
|
|
1
|
+
require "thor"
|
1
2
|
require "appmake/version"
|
2
3
|
|
3
4
|
module Appmake
|
4
|
-
class Appmake
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
class Appmake < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
File.dirname(File.dirname(__FILE__))
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "init", "initialize new application"
|
13
|
+
def init
|
14
|
+
empty_directory "bin"
|
15
|
+
template"templates/bin/compile_templates.js.tt", "bin/compile_templates.js"
|
16
|
+
|
17
|
+
empty_directory "css"
|
18
|
+
template"templates/css/app.scss.tt", "css/app.scss"
|
19
|
+
template"templates/css/body.scss.tt", "css/body.scss"
|
20
|
+
|
21
|
+
empty_directory "js"
|
22
|
+
template"templates/js/lib/doT.js.tt", "js/lib/doT.js"
|
23
|
+
template"templates/js/app.js.tt", "js/app.js"
|
24
|
+
|
25
|
+
empty_directory "tpl"
|
26
|
+
template "templates/tpl/welcome.html.tt", "tpl/welcome.html"
|
27
|
+
|
28
|
+
empty_directory "public"
|
29
|
+
template "templates/public/index.html.tt", "public/index.html"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "watch", "watch for files to compile"
|
33
|
+
def watch
|
34
|
+
js_listener = Listeners::Js.new
|
35
|
+
js_listener.start
|
36
|
+
end
|
37
|
+
end
|
9
38
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
var app_dir = __dirname + '/../',
|
2
|
+
tpl_dir = app_dir + 'tpl/',
|
3
|
+
js_dir = app_dir + 'js/',
|
4
|
+
|
5
|
+
fs = require('fs'),
|
6
|
+
dot = require('../js/lib/doT.js'),
|
7
|
+
|
8
|
+
templates = {};
|
9
|
+
|
10
|
+
walk();
|
11
|
+
fs.writeFile(js_dir + 'templates.js', buildModule(templates));
|
12
|
+
|
13
|
+
|
14
|
+
function walk(subdir) {
|
15
|
+
var dir = tpl_dir,
|
16
|
+
files;
|
17
|
+
|
18
|
+
if (subdir)
|
19
|
+
dir += subdir;
|
20
|
+
|
21
|
+
files = fs.readdirSync(dir);
|
22
|
+
files.forEach(function (filename) {
|
23
|
+
var stats = fs.statSync(dir + filename);
|
24
|
+
|
25
|
+
if (stats.isDirectory()) {
|
26
|
+
if (subdir) filename = subdir + filename;
|
27
|
+
filename += '/';
|
28
|
+
|
29
|
+
walk(filename);
|
30
|
+
}
|
31
|
+
|
32
|
+
if (!isHTML(filename))
|
33
|
+
return;
|
34
|
+
|
35
|
+
readFile(filename, subdir, fs.readFileSync(dir + filename));
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
function readFile (filename, dir, data) {
|
40
|
+
var name = filename.split('.').slice(0, -1).join('.'),
|
41
|
+
compiled = dot.template(data).toString().replace(/^function anonymous/, 'function ');
|
42
|
+
|
43
|
+
if (dir)
|
44
|
+
name = dir + name;
|
45
|
+
|
46
|
+
templates[name] = compiled;
|
47
|
+
}
|
48
|
+
|
49
|
+
function isHTML(name) {
|
50
|
+
if (!~name.indexOf('.'))
|
51
|
+
return false;
|
52
|
+
|
53
|
+
return name.split('.').slice(-1)[0].toLowerCase() === 'html';
|
54
|
+
}
|
55
|
+
|
56
|
+
function buildModule() {
|
57
|
+
var content = [],
|
58
|
+
n;
|
59
|
+
|
60
|
+
for (n in templates)
|
61
|
+
content.push('"' + n + '": ' + templates[n]);
|
62
|
+
|
63
|
+
return ['module.exports = {', content.join(','), '};'].join('').replace(/(\n|\r|\r\n)/, '');
|
64
|
+
}
|
@@ -0,0 +1,135 @@
|
|
1
|
+
// doT.js
|
2
|
+
// 2011, Laura Doktorova, https://github.com/olado/doT
|
3
|
+
// Licensed under the MIT license.
|
4
|
+
|
5
|
+
(function() {
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
var doT = {
|
9
|
+
version: '1.0.0',
|
10
|
+
templateSettings: {
|
11
|
+
evaluate: /\{\{([\s\S]+?\}?)\}\}/g,
|
12
|
+
interpolate: /\{\{=([\s\S]+?)\}\}/g,
|
13
|
+
encode: /\{\{!([\s\S]+?)\}\}/g,
|
14
|
+
use: /\{\{#([\s\S]+?)\}\}/g,
|
15
|
+
useParams: /(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,
|
16
|
+
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
|
17
|
+
defineParams:/^\s*([\w$]+):([\s\S]+)/,
|
18
|
+
conditional: /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
|
19
|
+
iterate: /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
|
20
|
+
varname: 'it',
|
21
|
+
strip: true,
|
22
|
+
append: true,
|
23
|
+
selfcontained: false
|
24
|
+
},
|
25
|
+
template: undefined, //fn, compile template
|
26
|
+
compile: undefined //fn, for express
|
27
|
+
};
|
28
|
+
|
29
|
+
if (typeof module !== 'undefined' && module.exports) {
|
30
|
+
module.exports = doT;
|
31
|
+
} else if (typeof define === 'function' && define.amd) {
|
32
|
+
define(function(){return doT;});
|
33
|
+
} else {
|
34
|
+
(function(){ return this || (0,eval)('this'); }()).doT = doT;
|
35
|
+
}
|
36
|
+
|
37
|
+
function encodeHTMLSource() {
|
38
|
+
var encodeHTMLRules = { "&": "&", "<": "<", ">": ">", '"': '"', "'": ''', "/": '/' },
|
39
|
+
matchHTML = /&(?!#?\w+;)|<|>|"|'|\//g;
|
40
|
+
return function() {
|
41
|
+
return this ? this.replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : this;
|
42
|
+
};
|
43
|
+
}
|
44
|
+
String.prototype.encodeHTML = encodeHTMLSource();
|
45
|
+
|
46
|
+
var startend = {
|
47
|
+
append: { start: "'+(", end: ")+'", endencode: "||'').toString().encodeHTML()+'" },
|
48
|
+
split: { start: "';out+=(", end: ");out+='", endencode: "||'').toString().encodeHTML();out+='"}
|
49
|
+
}, skip = /$^/;
|
50
|
+
|
51
|
+
function resolveDefs(c, block, def) {
|
52
|
+
return ((typeof block === 'string') ? block : block.toString())
|
53
|
+
.replace(c.define || skip, function(m, code, assign, value) {
|
54
|
+
if (code.indexOf('def.') === 0) {
|
55
|
+
code = code.substring(4);
|
56
|
+
}
|
57
|
+
if (!(code in def)) {
|
58
|
+
if (assign === ':') {
|
59
|
+
if (c.defineParams) value.replace(c.defineParams, function(m, param, v) {
|
60
|
+
def[code] = {arg: param, text: v};
|
61
|
+
});
|
62
|
+
if (!(code in def)) def[code]= value;
|
63
|
+
} else {
|
64
|
+
new Function("def", "def['"+code+"']=" + value)(def);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
return '';
|
68
|
+
})
|
69
|
+
.replace(c.use || skip, function(m, code) {
|
70
|
+
if (c.useParams) code = code.replace(c.useParams, function(m, s, d, param) {
|
71
|
+
if (def[d] && def[d].arg && param) {
|
72
|
+
var rw = (d+":"+param).replace(/'|\\/g, '_');
|
73
|
+
def.__exp = def.__exp || {};
|
74
|
+
def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
|
75
|
+
return s + "def.__exp['"+rw+"']";
|
76
|
+
}
|
77
|
+
});
|
78
|
+
var v = new Function("def", "return " + code)(def);
|
79
|
+
return v ? resolveDefs(c, v, def) : v;
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
83
|
+
function unescape(code) {
|
84
|
+
return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, ' ');
|
85
|
+
}
|
86
|
+
|
87
|
+
doT.template = function(tmpl, c, def) {
|
88
|
+
c = c || doT.templateSettings;
|
89
|
+
var cse = c.append ? startend.append : startend.split, needhtmlencode, sid = 0, indv,
|
90
|
+
str = (c.use || c.define) ? resolveDefs(c, tmpl, def || {}) : tmpl;
|
91
|
+
|
92
|
+
str = ("var out='" + (c.strip ? str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g,' ')
|
93
|
+
.replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,''): str)
|
94
|
+
.replace(/'|\\/g, '\\$&')
|
95
|
+
.replace(c.interpolate || skip, function(m, code) {
|
96
|
+
return cse.start + unescape(code) + cse.end;
|
97
|
+
})
|
98
|
+
.replace(c.encode || skip, function(m, code) {
|
99
|
+
needhtmlencode = true;
|
100
|
+
return cse.start + unescape(code) + cse.endencode;
|
101
|
+
})
|
102
|
+
.replace(c.conditional || skip, function(m, elsecase, code) {
|
103
|
+
return elsecase ?
|
104
|
+
(code ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='") :
|
105
|
+
(code ? "';if(" + unescape(code) + "){out+='" : "';}out+='");
|
106
|
+
})
|
107
|
+
.replace(c.iterate || skip, function(m, iterate, vname, iname) {
|
108
|
+
if (!iterate) return "';} } out+='";
|
109
|
+
sid+=1; indv=iname || "i"+sid; iterate=unescape(iterate);
|
110
|
+
return "';var arr"+sid+"="+iterate+";if(arr"+sid+"){var "+vname+","+indv+"=-1,l"+sid+"=arr"+sid+".length-1;while("+indv+"<l"+sid+"){"
|
111
|
+
+vname+"=arr"+sid+"["+indv+"+=1];out+='";
|
112
|
+
})
|
113
|
+
.replace(c.evaluate || skip, function(m, code) {
|
114
|
+
return "';" + unescape(code) + "out+='";
|
115
|
+
})
|
116
|
+
+ "';return out;")
|
117
|
+
.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r')
|
118
|
+
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '')
|
119
|
+
.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+=');
|
120
|
+
|
121
|
+
if (needhtmlencode && c.selfcontained) {
|
122
|
+
str = "String.prototype.encodeHTML=(" + encodeHTMLSource.toString() + "());" + str;
|
123
|
+
}
|
124
|
+
try {
|
125
|
+
return new Function(c.varname, str);
|
126
|
+
} catch (e) {
|
127
|
+
if (typeof console !== 'undefined') console.log("Could not create a template function: " + str);
|
128
|
+
throw e;
|
129
|
+
}
|
130
|
+
};
|
131
|
+
|
132
|
+
doT.compile = function(tmpl, def) {
|
133
|
+
return doT.template(tmpl, null, def);
|
134
|
+
};
|
135
|
+
}());
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<!doctype>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title></title>
|
5
|
+
<meta http=equiv="Content-Type" content="text/html; charset=UTF-8">
|
6
|
+
<link rel="stylesheet" type="text/css" href="app.css">
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<script type="text/javascript" src="app.js"></script>
|
10
|
+
</body>
|
11
|
+
</html>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appmake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.27
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -92,6 +92,13 @@ files:
|
|
92
92
|
- bin/appmake
|
93
93
|
- lib/appmake.rb
|
94
94
|
- lib/appmake/version.rb
|
95
|
+
- templates/bin/compile_templates.js.tt
|
96
|
+
- templates/css/app.scss.tt
|
97
|
+
- templates/css/body.scss.tt
|
98
|
+
- templates/js/app.js.tt
|
99
|
+
- templates/js/lib/doT.js.tt
|
100
|
+
- templates/public/index.html.tt
|
101
|
+
- templates/tpl/welcome.html.tt
|
95
102
|
homepage: https://github.com/sebastiansito/appmake
|
96
103
|
licenses: []
|
97
104
|
post_install_message:
|