appmake 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appmake.rb +142 -0
- metadata +1 -1
data/lib/appmake.rb
CHANGED
@@ -17,6 +17,9 @@ class Appmake
|
|
17
17
|
FileUtils.touch "css/main.scss"
|
18
18
|
FileUtils.mkdir "js"
|
19
19
|
FileUtils.touch "js/main.js"
|
20
|
+
f = File.new("js/compile_templates.js", "w+")
|
21
|
+
f.puts(COMPILE_TEMPLATES_JS)
|
22
|
+
f.close
|
20
23
|
FileUtils.mkdir "tpl"
|
21
24
|
end
|
22
25
|
|
@@ -116,4 +119,143 @@ function buildModule() {
|
|
116
119
|
return ['module.exports = {', content.join(','), '};'].join('').replace(/(\n|\r|\r\n)/, '');
|
117
120
|
}
|
118
121
|
|
122
|
+
EOS
|
123
|
+
|
124
|
+
DOTJS_JS = <<EOS
|
125
|
+
// doT.js
|
126
|
+
// 2011, Laura Doktorova, https://github.com/olado/doT
|
127
|
+
// Licensed under the MIT license.
|
128
|
+
|
129
|
+
(function() {
|
130
|
+
"use strict";
|
131
|
+
|
132
|
+
var doT = {
|
133
|
+
version: '1.0.0',
|
134
|
+
templateSettings: {
|
135
|
+
evaluate: /\{\{([\s\S]+?\}?)\}\}/g,
|
136
|
+
interpolate: /\{\{=([\s\S]+?)\}\}/g,
|
137
|
+
encode: /\{\{!([\s\S]+?)\}\}/g,
|
138
|
+
use: /\{\{#([\s\S]+?)\}\}/g,
|
139
|
+
useParams: /(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,
|
140
|
+
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
|
141
|
+
defineParams:/^\s*([\w$]+):([\s\S]+)/,
|
142
|
+
conditional: /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
|
143
|
+
iterate: /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
|
144
|
+
varname: 'it',
|
145
|
+
strip: true,
|
146
|
+
append: true,
|
147
|
+
selfcontained: false
|
148
|
+
},
|
149
|
+
template: undefined, //fn, compile template
|
150
|
+
compile: undefined //fn, for express
|
151
|
+
};
|
152
|
+
|
153
|
+
if (typeof module !== 'undefined' && module.exports) {
|
154
|
+
module.exports = doT;
|
155
|
+
} else if (typeof define === 'function' && define.amd) {
|
156
|
+
define(function(){return doT;});
|
157
|
+
} else {
|
158
|
+
(function(){ return this || (0,eval)('this'); }()).doT = doT;
|
159
|
+
}
|
160
|
+
|
161
|
+
function encodeHTMLSource() {
|
162
|
+
var encodeHTMLRules = { "&": "&", "<": "<", ">": ">", '"': '"', "'": ''', "/": '/' },
|
163
|
+
matchHTML = /&(?!#?\w+;)|<|>|"|'|\//g;
|
164
|
+
return function() {
|
165
|
+
return this ? this.replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : this;
|
166
|
+
};
|
167
|
+
}
|
168
|
+
String.prototype.encodeHTML = encodeHTMLSource();
|
169
|
+
|
170
|
+
var startend = {
|
171
|
+
append: { start: "'+(", end: ")+'", endencode: "||'').toString().encodeHTML()+'" },
|
172
|
+
split: { start: "';out+=(", end: ");out+='", endencode: "||'').toString().encodeHTML();out+='"}
|
173
|
+
}, skip = /$^/;
|
174
|
+
|
175
|
+
function resolveDefs(c, block, def) {
|
176
|
+
return ((typeof block === 'string') ? block : block.toString())
|
177
|
+
.replace(c.define || skip, function(m, code, assign, value) {
|
178
|
+
if (code.indexOf('def.') === 0) {
|
179
|
+
code = code.substring(4);
|
180
|
+
}
|
181
|
+
if (!(code in def)) {
|
182
|
+
if (assign === ':') {
|
183
|
+
if (c.defineParams) value.replace(c.defineParams, function(m, param, v) {
|
184
|
+
def[code] = {arg: param, text: v};
|
185
|
+
});
|
186
|
+
if (!(code in def)) def[code]= value;
|
187
|
+
} else {
|
188
|
+
new Function("def", "def['"+code+"']=" + value)(def);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
return '';
|
192
|
+
})
|
193
|
+
.replace(c.use || skip, function(m, code) {
|
194
|
+
if (c.useParams) code = code.replace(c.useParams, function(m, s, d, param) {
|
195
|
+
if (def[d] && def[d].arg && param) {
|
196
|
+
var rw = (d+":"+param).replace(/'|\\/g, '_');
|
197
|
+
def.__exp = def.__exp || {};
|
198
|
+
def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
|
199
|
+
return s + "def.__exp['"+rw+"']";
|
200
|
+
}
|
201
|
+
});
|
202
|
+
var v = new Function("def", "return " + code)(def);
|
203
|
+
return v ? resolveDefs(c, v, def) : v;
|
204
|
+
});
|
205
|
+
}
|
206
|
+
|
207
|
+
function unescape(code) {
|
208
|
+
return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, ' ');
|
209
|
+
}
|
210
|
+
|
211
|
+
doT.template = function(tmpl, c, def) {
|
212
|
+
c = c || doT.templateSettings;
|
213
|
+
var cse = c.append ? startend.append : startend.split, needhtmlencode, sid = 0, indv,
|
214
|
+
str = (c.use || c.define) ? resolveDefs(c, tmpl, def || {}) : tmpl;
|
215
|
+
|
216
|
+
str = ("var out='" + (c.strip ? str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g,' ')
|
217
|
+
.replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,''): str)
|
218
|
+
.replace(/'|\\/g, '\\$&')
|
219
|
+
.replace(c.interpolate || skip, function(m, code) {
|
220
|
+
return cse.start + unescape(code) + cse.end;
|
221
|
+
})
|
222
|
+
.replace(c.encode || skip, function(m, code) {
|
223
|
+
needhtmlencode = true;
|
224
|
+
return cse.start + unescape(code) + cse.endencode;
|
225
|
+
})
|
226
|
+
.replace(c.conditional || skip, function(m, elsecase, code) {
|
227
|
+
return elsecase ?
|
228
|
+
(code ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='") :
|
229
|
+
(code ? "';if(" + unescape(code) + "){out+='" : "';}out+='");
|
230
|
+
})
|
231
|
+
.replace(c.iterate || skip, function(m, iterate, vname, iname) {
|
232
|
+
if (!iterate) return "';} } out+='";
|
233
|
+
sid+=1; indv=iname || "i"+sid; iterate=unescape(iterate);
|
234
|
+
return "';var arr"+sid+"="+iterate+";if(arr"+sid+"){var "+vname+","+indv+"=-1,l"+sid+"=arr"+sid+".length-1;while("+indv+"<l"+sid+"){"
|
235
|
+
+vname+"=arr"+sid+"["+indv+"+=1];out+='";
|
236
|
+
})
|
237
|
+
.replace(c.evaluate || skip, function(m, code) {
|
238
|
+
return "';" + unescape(code) + "out+='";
|
239
|
+
})
|
240
|
+
+ "';return out;")
|
241
|
+
.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r')
|
242
|
+
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '')
|
243
|
+
.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+=');
|
244
|
+
|
245
|
+
if (needhtmlencode && c.selfcontained) {
|
246
|
+
str = "String.prototype.encodeHTML=(" + encodeHTMLSource.toString() + "());" + str;
|
247
|
+
}
|
248
|
+
try {
|
249
|
+
return new Function(c.varname, str);
|
250
|
+
} catch (e) {
|
251
|
+
if (typeof console !== 'undefined') console.log("Could not create a template function: " + str);
|
252
|
+
throw e;
|
253
|
+
}
|
254
|
+
};
|
255
|
+
|
256
|
+
doT.compile = function(tmpl, def) {
|
257
|
+
return doT.template(tmpl, null, def);
|
258
|
+
};
|
259
|
+
}());
|
260
|
+
|
119
261
|
EOS
|