haml_coffee_template 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +29 -0
- data/lib/haml_coffee_template.rb +17 -0
- data/lib/haml_coffee_template/compiler.rb +49 -0
- data/lib/haml_coffee_template/configuration.rb +11 -0
- data/lib/haml_coffee_template/hamlcoffee.js +2276 -0
- data/lib/haml_coffee_template/processor.rb +31 -0
- data/lib/haml_coffee_template/railtie.rb +18 -0
- data/lib/haml_coffee_template/version.rb +3 -0
- data/lib/haml_coffee_template/wrapper.js +16 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 668cea02355744741f5b02a27f905a9e95755341aa9a6f5e4167ef7aeae66c0d
|
4
|
+
data.tar.gz: 79f3ea79a9c9caed1725c622c992ef57f07944e1cd8c6f84183f92073abafeae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8760a5e9d988d7caf1aaecff963c8ac6eb765150e994b952646530be23756a18ebd271856f0dc8f55ecc17ed6cb2415f62a4b8c2e33159961032c3314efa7247
|
7
|
+
data.tar.gz: 52c68eff01a36c83e701ef60b60e3cd975af73807e17ae5fd8f64bc12692238f73c324080cc85cecfe311d656c08a219794bbd54bbb2e420b57dfd0db22f722c
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Haml Coffee Template
|
2
|
+
|
3
|
+
Add [haml-coffee](https://github.com/netzpirat/haml-coffee) template support to your Rails asset pipeline.
|
4
|
+
|
5
|
+
This project is very similar to [Haml Coffee Assets](https://github.com/emilioforrer/haml_coffee_assets) but it does not monkey-patch Rails core classes.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Include in project's `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'haml_coffee_template'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
* Create template files with extension `.hamlc`
|
18
|
+
```haml
|
19
|
+
%div
|
20
|
+
Hello #{@who}
|
21
|
+
```
|
22
|
+
* Require template in javascript or coffeescript files that are processed via Sprockets
|
23
|
+
```coffeescript
|
24
|
+
#= require hello
|
25
|
+
document.write JST['hello']({who: "world"})
|
26
|
+
```
|
27
|
+
|
28
|
+
## Advanced usage
|
29
|
+
Compiler can be configured using HamlCoffeeTemplate::Configuration class.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative "haml_coffee_template/version"
|
2
|
+
require_relative "haml_coffee_template/processor"
|
3
|
+
require_relative "haml_coffee_template/configuration"
|
4
|
+
require_relative "haml_coffee_template/compiler"
|
5
|
+
require_relative "haml_coffee_template/railtie" if defined?(::Rails) && !ENV["HAML_COFFEE_TEMPLATE_DISABLE_AUTOCONFIGURE"]
|
6
|
+
|
7
|
+
module HamlCoffeeTemplate
|
8
|
+
def self.configuration
|
9
|
+
@configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration=(obj)
|
13
|
+
@configuration = obj
|
14
|
+
end
|
15
|
+
|
16
|
+
self.configuration = Configuration.new
|
17
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "coffee_script"
|
2
|
+
|
3
|
+
module HamlCoffeeTemplate
|
4
|
+
class Compiler
|
5
|
+
attr_reader :runtime
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@runtime = ExecJS.compile(runtime_source)
|
9
|
+
end
|
10
|
+
|
11
|
+
def template(name, source)
|
12
|
+
runtime.call(
|
13
|
+
"HamlCoffeeTemplate.template",
|
14
|
+
source,
|
15
|
+
name,
|
16
|
+
HamlCoffeeTemplate.configuration.namespace,
|
17
|
+
HamlCoffeeTemplate.configuration.compiler_options
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def compile(source)
|
22
|
+
runtime.call(
|
23
|
+
"HamlCoffeeTemplate.compile",
|
24
|
+
source,
|
25
|
+
HamlCoffeeTemplate.configuration.compiler_options
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def runtime_source
|
30
|
+
[coffeescript_source, hamlcoffee_source, wrapper_source].join(";")
|
31
|
+
end
|
32
|
+
|
33
|
+
def coffeescript_source
|
34
|
+
File.read(CoffeeScript::Source.path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def hamlcoffee_source
|
38
|
+
File.read(HamlCoffeeTemplate.configuration.hamlcoffee_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def wrapper_source
|
42
|
+
File.read(wrapper_script_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def wrapper_script_path
|
46
|
+
File.expand_path("wrapper.js", __dir__)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module HamlCoffeeTemplate
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :namespace, :compiler_options, :hamlcoffee_path
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.namespace = "window.JST"
|
7
|
+
self.compiler_options = {}
|
8
|
+
self.hamlcoffee_path = File.expand_path("hamlcoffee.js", __dir__)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,2276 @@
|
|
1
|
+
var require = function (file, cwd) {
|
2
|
+
var resolved = require.resolve(file, cwd || '/');
|
3
|
+
var mod = require.modules[resolved];
|
4
|
+
if (!mod) throw new Error(
|
5
|
+
'Failed to resolve module ' + file + ', tried ' + resolved
|
6
|
+
);
|
7
|
+
var cached = require.cache[resolved];
|
8
|
+
var res = cached? cached.exports : mod();
|
9
|
+
return res;
|
10
|
+
};
|
11
|
+
|
12
|
+
require.paths = [];
|
13
|
+
require.modules = {};
|
14
|
+
require.cache = {};
|
15
|
+
require.extensions = [".js",".coffee",".json"];
|
16
|
+
|
17
|
+
require._core = {
|
18
|
+
'assert': true,
|
19
|
+
'events': true,
|
20
|
+
'fs': true,
|
21
|
+
'path': true,
|
22
|
+
'vm': true
|
23
|
+
};
|
24
|
+
|
25
|
+
require.resolve = (function () {
|
26
|
+
return function (x, cwd) {
|
27
|
+
if (!cwd) cwd = '/';
|
28
|
+
|
29
|
+
if (require._core[x]) return x;
|
30
|
+
var path = require.modules.path();
|
31
|
+
cwd = path.resolve('/', cwd);
|
32
|
+
var y = cwd || '/';
|
33
|
+
|
34
|
+
if (x.match(/^(?:\.\.?\/|\/)/)) {
|
35
|
+
var m = loadAsFileSync(path.resolve(y, x))
|
36
|
+
|| loadAsDirectorySync(path.resolve(y, x));
|
37
|
+
if (m) return m;
|
38
|
+
}
|
39
|
+
|
40
|
+
var n = loadNodeModulesSync(x, y);
|
41
|
+
if (n) return n;
|
42
|
+
|
43
|
+
throw new Error("Cannot find module '" + x + "'");
|
44
|
+
|
45
|
+
function loadAsFileSync (x) {
|
46
|
+
x = path.normalize(x);
|
47
|
+
if (require.modules[x]) {
|
48
|
+
return x;
|
49
|
+
}
|
50
|
+
|
51
|
+
for (var i = 0; i < require.extensions.length; i++) {
|
52
|
+
var ext = require.extensions[i];
|
53
|
+
if (require.modules[x + ext]) return x + ext;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
function loadAsDirectorySync (x) {
|
58
|
+
x = x.replace(/\/+$/, '');
|
59
|
+
var pkgfile = path.normalize(x + '/package.json');
|
60
|
+
if (require.modules[pkgfile]) {
|
61
|
+
var pkg = require.modules[pkgfile]();
|
62
|
+
var b = pkg.browserify;
|
63
|
+
if (typeof b === 'object' && b.main) {
|
64
|
+
var m = loadAsFileSync(path.resolve(x, b.main));
|
65
|
+
if (m) return m;
|
66
|
+
}
|
67
|
+
else if (typeof b === 'string') {
|
68
|
+
var m = loadAsFileSync(path.resolve(x, b));
|
69
|
+
if (m) return m;
|
70
|
+
}
|
71
|
+
else if (pkg.main) {
|
72
|
+
var m = loadAsFileSync(path.resolve(x, pkg.main));
|
73
|
+
if (m) return m;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
return loadAsFileSync(x + '/index');
|
78
|
+
}
|
79
|
+
|
80
|
+
function loadNodeModulesSync (x, start) {
|
81
|
+
var dirs = nodeModulesPathsSync(start);
|
82
|
+
for (var i = 0; i < dirs.length; i++) {
|
83
|
+
var dir = dirs[i];
|
84
|
+
var m = loadAsFileSync(dir + '/' + x);
|
85
|
+
if (m) return m;
|
86
|
+
var n = loadAsDirectorySync(dir + '/' + x);
|
87
|
+
if (n) return n;
|
88
|
+
}
|
89
|
+
|
90
|
+
var m = loadAsFileSync(x);
|
91
|
+
if (m) return m;
|
92
|
+
}
|
93
|
+
|
94
|
+
function nodeModulesPathsSync (start) {
|
95
|
+
var parts;
|
96
|
+
if (start === '/') parts = [ '' ];
|
97
|
+
else parts = path.normalize(start).split('/');
|
98
|
+
|
99
|
+
var dirs = [];
|
100
|
+
for (var i = parts.length - 1; i >= 0; i--) {
|
101
|
+
if (parts[i] === 'node_modules') continue;
|
102
|
+
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
|
103
|
+
dirs.push(dir);
|
104
|
+
}
|
105
|
+
|
106
|
+
return dirs;
|
107
|
+
}
|
108
|
+
};
|
109
|
+
})();
|
110
|
+
|
111
|
+
require.alias = function (from, to) {
|
112
|
+
var path = require.modules.path();
|
113
|
+
var res = null;
|
114
|
+
try {
|
115
|
+
res = require.resolve(from + '/package.json', '/');
|
116
|
+
}
|
117
|
+
catch (err) {
|
118
|
+
res = require.resolve(from, '/');
|
119
|
+
}
|
120
|
+
var basedir = path.dirname(res);
|
121
|
+
|
122
|
+
var keys = (Object.keys || function (obj) {
|
123
|
+
var res = [];
|
124
|
+
for (var key in obj) res.push(key);
|
125
|
+
return res;
|
126
|
+
})(require.modules);
|
127
|
+
|
128
|
+
for (var i = 0; i < keys.length; i++) {
|
129
|
+
var key = keys[i];
|
130
|
+
if (key.slice(0, basedir.length + 1) === basedir + '/') {
|
131
|
+
var f = key.slice(basedir.length);
|
132
|
+
require.modules[to + f] = require.modules[basedir + f];
|
133
|
+
}
|
134
|
+
else if (key === basedir) {
|
135
|
+
require.modules[to] = require.modules[basedir];
|
136
|
+
}
|
137
|
+
}
|
138
|
+
};
|
139
|
+
|
140
|
+
(function () {
|
141
|
+
var process = {};
|
142
|
+
var global = typeof window !== 'undefined' ? window : {};
|
143
|
+
var definedProcess = false;
|
144
|
+
|
145
|
+
require.define = function (filename, fn) {
|
146
|
+
if (!definedProcess && require.modules.__browserify_process) {
|
147
|
+
process = require.modules.__browserify_process();
|
148
|
+
definedProcess = true;
|
149
|
+
}
|
150
|
+
|
151
|
+
var dirname = require._core[filename]
|
152
|
+
? ''
|
153
|
+
: require.modules.path().dirname(filename)
|
154
|
+
;
|
155
|
+
|
156
|
+
var require_ = function (file) {
|
157
|
+
var requiredModule = require(file, dirname);
|
158
|
+
var cached = require.cache[require.resolve(file, dirname)];
|
159
|
+
|
160
|
+
if (cached && cached.parent === null) {
|
161
|
+
cached.parent = module_;
|
162
|
+
}
|
163
|
+
|
164
|
+
return requiredModule;
|
165
|
+
};
|
166
|
+
require_.resolve = function (name) {
|
167
|
+
return require.resolve(name, dirname);
|
168
|
+
};
|
169
|
+
require_.modules = require.modules;
|
170
|
+
require_.define = require.define;
|
171
|
+
require_.cache = require.cache;
|
172
|
+
var module_ = {
|
173
|
+
id : filename,
|
174
|
+
filename: filename,
|
175
|
+
exports : {},
|
176
|
+
loaded : false,
|
177
|
+
parent: null
|
178
|
+
};
|
179
|
+
|
180
|
+
require.modules[filename] = function () {
|
181
|
+
require.cache[filename] = module_;
|
182
|
+
fn.call(
|
183
|
+
module_.exports,
|
184
|
+
require_,
|
185
|
+
module_,
|
186
|
+
module_.exports,
|
187
|
+
dirname,
|
188
|
+
filename,
|
189
|
+
process,
|
190
|
+
global
|
191
|
+
);
|
192
|
+
module_.loaded = true;
|
193
|
+
return module_.exports;
|
194
|
+
};
|
195
|
+
};
|
196
|
+
})();
|
197
|
+
|
198
|
+
|
199
|
+
require.define("path",function(require,module,exports,__dirname,__filename,process,global){function filter (xs, fn) {
|
200
|
+
var res = [];
|
201
|
+
for (var i = 0; i < xs.length; i++) {
|
202
|
+
if (fn(xs[i], i, xs)) res.push(xs[i]);
|
203
|
+
}
|
204
|
+
return res;
|
205
|
+
}
|
206
|
+
|
207
|
+
// resolves . and .. elements in a path array with directory names there
|
208
|
+
// must be no slashes, empty elements, or device names (c:\) in the array
|
209
|
+
// (so also no leading and trailing slashes - it does not distinguish
|
210
|
+
// relative and absolute paths)
|
211
|
+
function normalizeArray(parts, allowAboveRoot) {
|
212
|
+
// if the path tries to go above the root, `up` ends up > 0
|
213
|
+
var up = 0;
|
214
|
+
for (var i = parts.length; i >= 0; i--) {
|
215
|
+
var last = parts[i];
|
216
|
+
if (last == '.') {
|
217
|
+
parts.splice(i, 1);
|
218
|
+
} else if (last === '..') {
|
219
|
+
parts.splice(i, 1);
|
220
|
+
up++;
|
221
|
+
} else if (up) {
|
222
|
+
parts.splice(i, 1);
|
223
|
+
up--;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
// if the path is allowed to go above the root, restore leading ..s
|
228
|
+
if (allowAboveRoot) {
|
229
|
+
for (; up--; up) {
|
230
|
+
parts.unshift('..');
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
return parts;
|
235
|
+
}
|
236
|
+
|
237
|
+
// Regex to split a filename into [*, dir, basename, ext]
|
238
|
+
// posix version
|
239
|
+
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
|
240
|
+
|
241
|
+
// path.resolve([from ...], to)
|
242
|
+
// posix version
|
243
|
+
exports.resolve = function() {
|
244
|
+
var resolvedPath = '',
|
245
|
+
resolvedAbsolute = false;
|
246
|
+
|
247
|
+
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
|
248
|
+
var path = (i >= 0)
|
249
|
+
? arguments[i]
|
250
|
+
: process.cwd();
|
251
|
+
|
252
|
+
// Skip empty and invalid entries
|
253
|
+
if (typeof path !== 'string' || !path) {
|
254
|
+
continue;
|
255
|
+
}
|
256
|
+
|
257
|
+
resolvedPath = path + '/' + resolvedPath;
|
258
|
+
resolvedAbsolute = path.charAt(0) === '/';
|
259
|
+
}
|
260
|
+
|
261
|
+
// At this point the path should be resolved to a full absolute path, but
|
262
|
+
// handle relative paths to be safe (might happen when process.cwd() fails)
|
263
|
+
|
264
|
+
// Normalize the path
|
265
|
+
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
266
|
+
return !!p;
|
267
|
+
}), !resolvedAbsolute).join('/');
|
268
|
+
|
269
|
+
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
270
|
+
};
|
271
|
+
|
272
|
+
// path.normalize(path)
|
273
|
+
// posix version
|
274
|
+
exports.normalize = function(path) {
|
275
|
+
var isAbsolute = path.charAt(0) === '/',
|
276
|
+
trailingSlash = path.slice(-1) === '/';
|
277
|
+
|
278
|
+
// Normalize the path
|
279
|
+
path = normalizeArray(filter(path.split('/'), function(p) {
|
280
|
+
return !!p;
|
281
|
+
}), !isAbsolute).join('/');
|
282
|
+
|
283
|
+
if (!path && !isAbsolute) {
|
284
|
+
path = '.';
|
285
|
+
}
|
286
|
+
if (path && trailingSlash) {
|
287
|
+
path += '/';
|
288
|
+
}
|
289
|
+
|
290
|
+
return (isAbsolute ? '/' : '') + path;
|
291
|
+
};
|
292
|
+
|
293
|
+
|
294
|
+
// posix version
|
295
|
+
exports.join = function() {
|
296
|
+
var paths = Array.prototype.slice.call(arguments, 0);
|
297
|
+
return exports.normalize(filter(paths, function(p, index) {
|
298
|
+
return p && typeof p === 'string';
|
299
|
+
}).join('/'));
|
300
|
+
};
|
301
|
+
|
302
|
+
|
303
|
+
exports.dirname = function(path) {
|
304
|
+
var dir = splitPathRe.exec(path)[1] || '';
|
305
|
+
var isWindows = false;
|
306
|
+
if (!dir) {
|
307
|
+
// No dirname
|
308
|
+
return '.';
|
309
|
+
} else if (dir.length === 1 ||
|
310
|
+
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
|
311
|
+
// It is just a slash or a drive letter with a slash
|
312
|
+
return dir;
|
313
|
+
} else {
|
314
|
+
// It is a full dirname, strip trailing slash
|
315
|
+
return dir.substring(0, dir.length - 1);
|
316
|
+
}
|
317
|
+
};
|
318
|
+
|
319
|
+
|
320
|
+
exports.basename = function(path, ext) {
|
321
|
+
var f = splitPathRe.exec(path)[2] || '';
|
322
|
+
// TODO: make this comparison case-insensitive on windows?
|
323
|
+
if (ext && f.substr(-1 * ext.length) === ext) {
|
324
|
+
f = f.substr(0, f.length - ext.length);
|
325
|
+
}
|
326
|
+
return f;
|
327
|
+
};
|
328
|
+
|
329
|
+
|
330
|
+
exports.extname = function(path) {
|
331
|
+
return splitPathRe.exec(path)[3] || '';
|
332
|
+
};
|
333
|
+
|
334
|
+
exports.relative = function(from, to) {
|
335
|
+
from = exports.resolve(from).substr(1);
|
336
|
+
to = exports.resolve(to).substr(1);
|
337
|
+
|
338
|
+
function trim(arr) {
|
339
|
+
var start = 0;
|
340
|
+
for (; start < arr.length; start++) {
|
341
|
+
if (arr[start] !== '') break;
|
342
|
+
}
|
343
|
+
|
344
|
+
var end = arr.length - 1;
|
345
|
+
for (; end >= 0; end--) {
|
346
|
+
if (arr[end] !== '') break;
|
347
|
+
}
|
348
|
+
|
349
|
+
if (start > end) return [];
|
350
|
+
return arr.slice(start, end - start + 1);
|
351
|
+
}
|
352
|
+
|
353
|
+
var fromParts = trim(from.split('/'));
|
354
|
+
var toParts = trim(to.split('/'));
|
355
|
+
|
356
|
+
var length = Math.min(fromParts.length, toParts.length);
|
357
|
+
var samePartsLength = length;
|
358
|
+
for (var i = 0; i < length; i++) {
|
359
|
+
if (fromParts[i] !== toParts[i]) {
|
360
|
+
samePartsLength = i;
|
361
|
+
break;
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
var outputParts = [];
|
366
|
+
for (var i = samePartsLength; i < fromParts.length; i++) {
|
367
|
+
outputParts.push('..');
|
368
|
+
}
|
369
|
+
|
370
|
+
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
371
|
+
|
372
|
+
return outputParts.join('/');
|
373
|
+
};
|
374
|
+
|
375
|
+
});
|
376
|
+
|
377
|
+
require.define("__browserify_process",function(require,module,exports,__dirname,__filename,process,global){var process = module.exports = {};
|
378
|
+
|
379
|
+
process.nextTick = (function () {
|
380
|
+
var canSetImmediate = typeof window !== 'undefined'
|
381
|
+
&& window.setImmediate;
|
382
|
+
var canPost = typeof window !== 'undefined'
|
383
|
+
&& window.postMessage && window.addEventListener
|
384
|
+
;
|
385
|
+
|
386
|
+
if (canSetImmediate) {
|
387
|
+
return function (f) { return window.setImmediate(f) };
|
388
|
+
}
|
389
|
+
|
390
|
+
if (canPost) {
|
391
|
+
var queue = [];
|
392
|
+
window.addEventListener('message', function (ev) {
|
393
|
+
if (ev.source === window && ev.data === 'browserify-tick') {
|
394
|
+
ev.stopPropagation();
|
395
|
+
if (queue.length > 0) {
|
396
|
+
var fn = queue.shift();
|
397
|
+
fn();
|
398
|
+
}
|
399
|
+
}
|
400
|
+
}, true);
|
401
|
+
|
402
|
+
return function nextTick(fn) {
|
403
|
+
queue.push(fn);
|
404
|
+
window.postMessage('browserify-tick', '*');
|
405
|
+
};
|
406
|
+
}
|
407
|
+
|
408
|
+
return function nextTick(fn) {
|
409
|
+
setTimeout(fn, 0);
|
410
|
+
};
|
411
|
+
})();
|
412
|
+
|
413
|
+
process.title = 'browser';
|
414
|
+
process.browser = true;
|
415
|
+
process.env = {};
|
416
|
+
process.argv = [];
|
417
|
+
|
418
|
+
process.binding = function (name) {
|
419
|
+
if (name === 'evals') return (require)('vm')
|
420
|
+
else throw new Error('No such module. (Possibly not yet loaded)')
|
421
|
+
};
|
422
|
+
|
423
|
+
(function () {
|
424
|
+
var cwd = '/';
|
425
|
+
var path;
|
426
|
+
process.cwd = function () { return cwd };
|
427
|
+
process.chdir = function (dir) {
|
428
|
+
if (!path) path = require('path');
|
429
|
+
cwd = path.resolve(dir, cwd);
|
430
|
+
};
|
431
|
+
})();
|
432
|
+
|
433
|
+
});
|
434
|
+
|
435
|
+
require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
436
|
+
var Code, Comment, Directive, Filter, Haml, HamlCoffee, Node, Text, indent, whitespace;
|
437
|
+
|
438
|
+
Node = require('./nodes/node');
|
439
|
+
|
440
|
+
Text = require('./nodes/text');
|
441
|
+
|
442
|
+
Haml = require('./nodes/haml');
|
443
|
+
|
444
|
+
Code = require('./nodes/code');
|
445
|
+
|
446
|
+
Comment = require('./nodes/comment');
|
447
|
+
|
448
|
+
Filter = require('./nodes/filter');
|
449
|
+
|
450
|
+
Directive = require('./nodes/directive');
|
451
|
+
|
452
|
+
whitespace = require('./util/text').whitespace;
|
453
|
+
|
454
|
+
indent = require('./util/text').indent;
|
455
|
+
|
456
|
+
module.exports = HamlCoffee = (function() {
|
457
|
+
HamlCoffee.VERSION = '1.14.1';
|
458
|
+
|
459
|
+
function HamlCoffee(options) {
|
460
|
+
var segment, segments, _base, _base1, _base10, _base11, _base12, _base13, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _i, _len;
|
461
|
+
this.options = options != null ? options : {};
|
462
|
+
if ((_base = this.options).placement == null) {
|
463
|
+
_base.placement = 'global';
|
464
|
+
}
|
465
|
+
if ((_base1 = this.options).dependencies == null) {
|
466
|
+
_base1.dependencies = {
|
467
|
+
hc: 'hamlcoffee'
|
468
|
+
};
|
469
|
+
}
|
470
|
+
if ((_base2 = this.options).escapeHtml == null) {
|
471
|
+
_base2.escapeHtml = true;
|
472
|
+
}
|
473
|
+
if ((_base3 = this.options).escapeAttributes == null) {
|
474
|
+
_base3.escapeAttributes = true;
|
475
|
+
}
|
476
|
+
if ((_base4 = this.options).cleanValue == null) {
|
477
|
+
_base4.cleanValue = true;
|
478
|
+
}
|
479
|
+
if ((_base5 = this.options).uglify == null) {
|
480
|
+
_base5.uglify = false;
|
481
|
+
}
|
482
|
+
if ((_base6 = this.options).basename == null) {
|
483
|
+
_base6.basename = false;
|
484
|
+
}
|
485
|
+
if ((_base7 = this.options).extendScope == null) {
|
486
|
+
_base7.extendScope = false;
|
487
|
+
}
|
488
|
+
if ((_base8 = this.options).format == null) {
|
489
|
+
_base8.format = 'html5';
|
490
|
+
}
|
491
|
+
if ((_base9 = this.options).hyphenateDataAttrs == null) {
|
492
|
+
_base9.hyphenateDataAttrs = true;
|
493
|
+
}
|
494
|
+
if ((_base10 = this.options).preserveTags == null) {
|
495
|
+
_base10.preserveTags = 'pre,textarea';
|
496
|
+
}
|
497
|
+
if ((_base11 = this.options).selfCloseTags == null) {
|
498
|
+
_base11.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
|
499
|
+
}
|
500
|
+
if (this.options.placement === 'global') {
|
501
|
+
if ((_base12 = this.options).name == null) {
|
502
|
+
_base12.name = 'test';
|
503
|
+
}
|
504
|
+
if ((_base13 = this.options).namespace == null) {
|
505
|
+
_base13.namespace = 'window.HAML';
|
506
|
+
}
|
507
|
+
segments = ("" + this.options.namespace + "." + this.options.name).replace(/(\s|-)+/g, '_').split(/\./);
|
508
|
+
this.options.name = this.options.basename ? segments.pop().split(/\/|\\/).pop() : segments.pop();
|
509
|
+
this.options.namespace = segments.shift();
|
510
|
+
this.intro = '';
|
511
|
+
if (segments.length !== 0) {
|
512
|
+
for (_i = 0, _len = segments.length; _i < _len; _i++) {
|
513
|
+
segment = segments[_i];
|
514
|
+
this.options.namespace += "." + segment;
|
515
|
+
this.intro += "" + this.options.namespace + " ?= {}\n";
|
516
|
+
}
|
517
|
+
} else {
|
518
|
+
this.intro += "" + this.options.namespace + " ?= {}\n";
|
519
|
+
}
|
520
|
+
}
|
521
|
+
}
|
522
|
+
|
523
|
+
HamlCoffee.prototype.indentChanged = function() {
|
524
|
+
return this.currentIndent !== this.previousIndent;
|
525
|
+
};
|
526
|
+
|
527
|
+
HamlCoffee.prototype.isIndent = function() {
|
528
|
+
return this.currentIndent > this.previousIndent;
|
529
|
+
};
|
530
|
+
|
531
|
+
HamlCoffee.prototype.updateTabSize = function() {
|
532
|
+
if (this.tabSize === 0) {
|
533
|
+
return this.tabSize = this.currentIndent - this.previousIndent;
|
534
|
+
}
|
535
|
+
};
|
536
|
+
|
537
|
+
HamlCoffee.prototype.updateBlockLevel = function() {
|
538
|
+
this.currentBlockLevel = this.currentIndent / this.tabSize;
|
539
|
+
if (!this.node.isCommented()) {
|
540
|
+
if (this.currentBlockLevel - Math.floor(this.currentBlockLevel) > 0) {
|
541
|
+
throw "Indentation error in line " + this.lineNumber;
|
542
|
+
}
|
543
|
+
if ((this.currentIndent - this.previousIndent) / this.tabSize > 1) {
|
544
|
+
throw "Block level too deep in line " + this.lineNumber;
|
545
|
+
}
|
546
|
+
}
|
547
|
+
return this.delta = this.previousBlockLevel - this.currentBlockLevel;
|
548
|
+
};
|
549
|
+
|
550
|
+
HamlCoffee.prototype.updateCodeBlockLevel = function(node) {
|
551
|
+
if (node instanceof Code) {
|
552
|
+
return this.currentCodeBlockLevel = node.codeBlockLevel + 1;
|
553
|
+
} else {
|
554
|
+
return this.currentCodeBlockLevel = node.codeBlockLevel;
|
555
|
+
}
|
556
|
+
};
|
557
|
+
|
558
|
+
HamlCoffee.prototype.updateParent = function() {
|
559
|
+
if (this.isIndent()) {
|
560
|
+
return this.pushParent();
|
561
|
+
} else {
|
562
|
+
return this.popParent();
|
563
|
+
}
|
564
|
+
};
|
565
|
+
|
566
|
+
HamlCoffee.prototype.pushParent = function() {
|
567
|
+
this.stack.push(this.parentNode);
|
568
|
+
return this.parentNode = this.node;
|
569
|
+
};
|
570
|
+
|
571
|
+
HamlCoffee.prototype.popParent = function() {
|
572
|
+
var i, _i, _ref, _results;
|
573
|
+
_results = [];
|
574
|
+
for (i = _i = 0, _ref = this.delta - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
|
575
|
+
_results.push(this.parentNode = this.stack.pop());
|
576
|
+
}
|
577
|
+
return _results;
|
578
|
+
};
|
579
|
+
|
580
|
+
HamlCoffee.prototype.getNodeOptions = function(override) {
|
581
|
+
if (override == null) {
|
582
|
+
override = {};
|
583
|
+
}
|
584
|
+
return {
|
585
|
+
parentNode: override.parentNode || this.parentNode,
|
586
|
+
blockLevel: override.blockLevel || this.currentBlockLevel,
|
587
|
+
codeBlockLevel: override.codeBlockLevel || this.currentCodeBlockLevel,
|
588
|
+
escapeHtml: override.escapeHtml || this.options.escapeHtml,
|
589
|
+
escapeAttributes: override.escapeAttributes || this.options.escapeAttributes,
|
590
|
+
cleanValue: override.cleanValue || this.options.cleanValue,
|
591
|
+
format: override.format || this.options.format,
|
592
|
+
hyphenateDataAttrs: override.hyphenateDataAttrs || this.options.format,
|
593
|
+
preserveTags: override.preserveTags || this.options.preserveTags,
|
594
|
+
selfCloseTags: override.selfCloseTags || this.options.selfCloseTags,
|
595
|
+
uglify: override.uglify || this.options.uglify,
|
596
|
+
placement: override.placement || this.options.placement,
|
597
|
+
namespace: override.namespace || this.options.namespace,
|
598
|
+
name: override.name || this.options.name
|
599
|
+
};
|
600
|
+
};
|
601
|
+
|
602
|
+
HamlCoffee.prototype.nodeFactory = function(expression) {
|
603
|
+
var node, options, _ref;
|
604
|
+
if (expression == null) {
|
605
|
+
expression = '';
|
606
|
+
}
|
607
|
+
options = this.getNodeOptions();
|
608
|
+
if (expression.match(/^:(escaped|preserve|css|javascript|plain|cdata|coffeescript)/)) {
|
609
|
+
node = new Filter(expression, options);
|
610
|
+
} else if (expression.match(/^(\/|-#)(.*)/)) {
|
611
|
+
node = new Comment(expression, options);
|
612
|
+
} else if (expression.match(/^(-#|-|=|!=|\&=|~)\s*(.*)/)) {
|
613
|
+
node = new Code(expression, options);
|
614
|
+
} else if (expression.match(/^(%|#[^{]|\.|\!)(.*)/)) {
|
615
|
+
node = new Haml(expression, options);
|
616
|
+
} else if (expression.match(/^\+(.*)/)) {
|
617
|
+
node = new Directive(expression, options);
|
618
|
+
} else {
|
619
|
+
node = new Text(expression, options);
|
620
|
+
}
|
621
|
+
if ((_ref = options.parentNode) != null) {
|
622
|
+
_ref.addChild(node);
|
623
|
+
}
|
624
|
+
return node;
|
625
|
+
};
|
626
|
+
|
627
|
+
HamlCoffee.prototype.parse = function(source) {
|
628
|
+
var attributes, expression, line, lines, range, result, tabsize, text, ws, _i, _j, _len, _ref, _ref1, _results;
|
629
|
+
if (source == null) {
|
630
|
+
source = '';
|
631
|
+
}
|
632
|
+
this.lineNumber = this.previousIndent = this.tabSize = this.currentBlockLevel = this.previousBlockLevel = 0;
|
633
|
+
this.currentCodeBlockLevel = this.previousCodeBlockLevel = 0;
|
634
|
+
this.node = null;
|
635
|
+
this.stack = [];
|
636
|
+
this.root = this.parentNode = new Node('', this.getNodeOptions());
|
637
|
+
lines = source.replace(/\r/g, '').split("\n");
|
638
|
+
while ((line = lines.shift()) !== void 0) {
|
639
|
+
if ((this.node instanceof Filter) && !this.exitFilter) {
|
640
|
+
if (/^(\s)*$/.test(line)) {
|
641
|
+
this.node.addChild(new Text('', this.getNodeOptions({
|
642
|
+
parentNode: this.node
|
643
|
+
})));
|
644
|
+
} else {
|
645
|
+
result = line.match(/^(\s*)(.*)/);
|
646
|
+
ws = result[1];
|
647
|
+
expression = result[2];
|
648
|
+
if (this.node.blockLevel >= (ws.length / 2)) {
|
649
|
+
this.exitFilter = true;
|
650
|
+
lines.unshift(line);
|
651
|
+
continue;
|
652
|
+
}
|
653
|
+
range = this.tabSize > 2 ? (function() {
|
654
|
+
_results = [];
|
655
|
+
for (var _i = _ref = this.tabSize; _ref <= 1 ? _i <= 1 : _i >= 1; _ref <= 1 ? _i++ : _i--){ _results.push(_i); }
|
656
|
+
return _results;
|
657
|
+
}).apply(this) : [2, 1];
|
658
|
+
for (_j = 0, _len = range.length; _j < _len; _j++) {
|
659
|
+
tabsize = range[_j];
|
660
|
+
text = line.match(RegExp("^\\s{" + ((this.node.blockLevel * tabsize) + tabsize) + "}(.*)"));
|
661
|
+
if (text) {
|
662
|
+
this.node.addChild(new Text(text[1], this.getNodeOptions({
|
663
|
+
parentNode: this.node
|
664
|
+
})));
|
665
|
+
break;
|
666
|
+
}
|
667
|
+
}
|
668
|
+
}
|
669
|
+
} else {
|
670
|
+
this.exitFilter = false;
|
671
|
+
result = line.match(/^(\s*)(.*)/);
|
672
|
+
ws = result[1];
|
673
|
+
expression = result[2];
|
674
|
+
this.currentIndent = ws.length;
|
675
|
+
if (/^\s*$/.test(line)) {
|
676
|
+
continue;
|
677
|
+
}
|
678
|
+
while (/^[%.#].*[{(]/.test(expression) && RegExp("^\\s{" + (this.previousIndent + (this.tabSize || 2)) + "}").test(lines[0]) && !/^(\s*)[-=&!~.%#</]/.test(lines[0]) && /([-\w]+[\w:-]*\w?)\s*=|('\w+[\w:-]*\w?')\s*=|("\w+[\w:-]*\w?")\s*=|(\w+[\w:-]*\w?):|('[-\w]+[\w:-]*\w?'):|("[-\w]+[\w:-]*\w?"):|:(\w+[\w:-]*\w?)\s*=>|:?'([-\w]+[\w:-]*\w?)'\s*=>|:?"([-\w]+[\w:-]*\w?)"\s*=>/.test(lines[0]) && !/;\s*$/.test(lines[0])) {
|
679
|
+
attributes = lines.shift();
|
680
|
+
expression = expression.replace(/(\s)+\|\s*$/, '');
|
681
|
+
expression += ' ' + attributes.match(/^\s*(.*?)(\s+\|\s*)?$/)[1];
|
682
|
+
this.lineNumber++;
|
683
|
+
}
|
684
|
+
while (/^-#/.test(expression) && RegExp("^\\s{" + (this.currentIndent + (this.tabSize || 2)) + "}").test(lines[0]) && lines.length > 0) {
|
685
|
+
lines.shift();
|
686
|
+
this.lineNumber++;
|
687
|
+
}
|
688
|
+
if (expression.match(/(\s)+\|\s*$/)) {
|
689
|
+
expression = expression.replace(/(\s)+\|\s*$/, ' ');
|
690
|
+
while ((_ref1 = lines[0]) != null ? _ref1.match(/(\s)+\|$/) : void 0) {
|
691
|
+
expression += lines.shift().match(/^(\s*)(.*)/)[2].replace(/(\s)+\|\s*$/, '');
|
692
|
+
this.lineNumber++;
|
693
|
+
}
|
694
|
+
}
|
695
|
+
if (this.indentChanged()) {
|
696
|
+
this.updateTabSize();
|
697
|
+
this.updateBlockLevel();
|
698
|
+
this.updateParent();
|
699
|
+
this.updateCodeBlockLevel(this.parentNode);
|
700
|
+
}
|
701
|
+
this.node = this.nodeFactory(expression);
|
702
|
+
this.previousBlockLevel = this.currentBlockLevel;
|
703
|
+
this.previousIndent = this.currentIndent;
|
704
|
+
}
|
705
|
+
this.lineNumber++;
|
706
|
+
}
|
707
|
+
return this.evaluate(this.root);
|
708
|
+
};
|
709
|
+
|
710
|
+
HamlCoffee.prototype.evaluate = function(node) {
|
711
|
+
var child, _i, _len, _ref;
|
712
|
+
_ref = node.children;
|
713
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
714
|
+
child = _ref[_i];
|
715
|
+
this.evaluate(child);
|
716
|
+
}
|
717
|
+
return node.evaluate();
|
718
|
+
};
|
719
|
+
|
720
|
+
HamlCoffee.prototype.render = function() {
|
721
|
+
switch (this.options.placement) {
|
722
|
+
case 'amd':
|
723
|
+
return this.renderAmd();
|
724
|
+
case 'standalone':
|
725
|
+
return this.renderStandalone();
|
726
|
+
default:
|
727
|
+
return this.renderGlobal();
|
728
|
+
}
|
729
|
+
};
|
730
|
+
|
731
|
+
HamlCoffee.prototype.renderStandalone = function() {
|
732
|
+
var template;
|
733
|
+
return template = "return (context) ->\n (->\n" + (indent(this.precompile(), 2)) + "\n ).call(context)";
|
734
|
+
};
|
735
|
+
|
736
|
+
HamlCoffee.prototype.renderAmd = function() {
|
737
|
+
var m, module, modules, param, params, template, _ref, _ref1;
|
738
|
+
if (/^hamlcoffee/.test(this.options.dependencies['hc'])) {
|
739
|
+
this.options.customHtmlEscape = 'hc.escape';
|
740
|
+
this.options.customCleanValue = 'hc.cleanValue';
|
741
|
+
this.options.customPreserve = 'hc.preserve';
|
742
|
+
this.options.customFindAndPreserve = 'hc.findAndPreserve';
|
743
|
+
this.options.customSurround = 'hc.surround';
|
744
|
+
this.options.customSucceed = 'hc.succeed';
|
745
|
+
this.options.customPrecede = 'hc.precede';
|
746
|
+
this.options.customReference = 'hc.reference';
|
747
|
+
}
|
748
|
+
modules = [];
|
749
|
+
params = [];
|
750
|
+
_ref = this.options.dependencies;
|
751
|
+
for (param in _ref) {
|
752
|
+
module = _ref[param];
|
753
|
+
modules.push(module);
|
754
|
+
params.push(param);
|
755
|
+
}
|
756
|
+
if (this.options.extendScope) {
|
757
|
+
template = " `with (context || {}) {`\n" + (indent(this.precompile(), 1)) + "\n`}`";
|
758
|
+
} else {
|
759
|
+
template = this.precompile();
|
760
|
+
}
|
761
|
+
_ref1 = this.findDependencies(template);
|
762
|
+
for (param in _ref1) {
|
763
|
+
module = _ref1[param];
|
764
|
+
modules.push(module);
|
765
|
+
params.push(param);
|
766
|
+
}
|
767
|
+
if (modules.length !== 0) {
|
768
|
+
modules = (function() {
|
769
|
+
var _i, _len, _results;
|
770
|
+
_results = [];
|
771
|
+
for (_i = 0, _len = modules.length; _i < _len; _i++) {
|
772
|
+
m = modules[_i];
|
773
|
+
_results.push("'" + m + "'");
|
774
|
+
}
|
775
|
+
return _results;
|
776
|
+
})();
|
777
|
+
modules = "[" + modules + "], (" + (params.join(', ')) + ")";
|
778
|
+
} else {
|
779
|
+
modules = '';
|
780
|
+
}
|
781
|
+
return "define " + modules + " ->\n (context) ->\n render = ->\n \n" + (indent(template, 4)) + "\n render.call(context)";
|
782
|
+
};
|
783
|
+
|
784
|
+
HamlCoffee.prototype.renderGlobal = function() {
|
785
|
+
var template;
|
786
|
+
template = this.intro;
|
787
|
+
if (this.options.extendScope) {
|
788
|
+
template += "" + this.options.namespace + "['" + this.options.name + "'] = (context) -> ( ->\n";
|
789
|
+
template += " `with (context || {}) {`\n";
|
790
|
+
template += "" + (indent(this.precompile(), 1));
|
791
|
+
template += "`}`\n";
|
792
|
+
template += ").call(context)";
|
793
|
+
} else {
|
794
|
+
template += "" + this.options.namespace + "['" + this.options.name + "'] = (context) -> ( ->\n";
|
795
|
+
template += "" + (indent(this.precompile(), 1));
|
796
|
+
template += ").call(context)";
|
797
|
+
}
|
798
|
+
return template;
|
799
|
+
};
|
800
|
+
|
801
|
+
HamlCoffee.prototype.precompile = function() {
|
802
|
+
var code, fn;
|
803
|
+
fn = '';
|
804
|
+
code = this.createCode();
|
805
|
+
if (code.indexOf('$e') !== -1) {
|
806
|
+
if (this.options.customHtmlEscape) {
|
807
|
+
fn += "$e = " + this.options.customHtmlEscape + "\n";
|
808
|
+
} else {
|
809
|
+
fn += "$e = (text, escape) ->\n \"\#{ text }\"\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\'/g, ''')\n .replace(/\\//g, '/')\n .replace(/\"/g, '"')\n";
|
810
|
+
}
|
811
|
+
}
|
812
|
+
if (code.indexOf('$c') !== -1) {
|
813
|
+
if (this.options.customCleanValue) {
|
814
|
+
fn += "$c = " + this.options.customCleanValue + "\n";
|
815
|
+
} else {
|
816
|
+
fn += "$c = (text) ->\n";
|
817
|
+
fn += " switch text\n";
|
818
|
+
fn += " when null, undefined then ''\n";
|
819
|
+
fn += " when true, false then '\u0093' + text\n";
|
820
|
+
fn += " else text\n";
|
821
|
+
}
|
822
|
+
}
|
823
|
+
if (code.indexOf('$p') !== -1 || code.indexOf('$fp') !== -1) {
|
824
|
+
if (this.options.customPreserve) {
|
825
|
+
fn += "$p = " + this.options.customPreserve + "\n";
|
826
|
+
} else {
|
827
|
+
fn += "$p = (text) -> text.replace /\\n/g, '
'\n";
|
828
|
+
}
|
829
|
+
}
|
830
|
+
if (code.indexOf('$fp') !== -1) {
|
831
|
+
if (this.options.customFindAndPreserve) {
|
832
|
+
fn += "$fp = " + this.options.customFindAndPreserve + "\n";
|
833
|
+
} else {
|
834
|
+
fn += "$fp = (text) ->\n text.replace /<(" + (this.options.preserveTags.split(',').join('|')) + ")>([^]*?)<\\/\\1>/g, (str, tag, content) ->\n \"<\#{ tag }>\#{ $p content }</\#{ tag }>\"\n";
|
835
|
+
}
|
836
|
+
}
|
837
|
+
if (code.indexOf('surround') !== -1) {
|
838
|
+
if (this.options.customSurround) {
|
839
|
+
fn += "surround = (start, end, fn) => " + this.options.customSurround + ".call(@, start, end, fn)\n";
|
840
|
+
} else {
|
841
|
+
fn += "surround = (start, end, fn) => start + fn.call(@)?.replace(/^\\s+|\\s+$/g, '') + end\n";
|
842
|
+
}
|
843
|
+
}
|
844
|
+
if (code.indexOf('succeed') !== -1) {
|
845
|
+
if (this.options.customSucceed) {
|
846
|
+
fn += "succeed = (start, end, fn) => " + this.options.customSucceed + ".call(@, start, end, fn)\n";
|
847
|
+
} else {
|
848
|
+
fn += "succeed = (end, fn) => fn.call(@)?.replace(/\s+$/g, '') + end\n";
|
849
|
+
}
|
850
|
+
}
|
851
|
+
if (code.indexOf('precede') !== -1) {
|
852
|
+
if (this.options.customPrecede) {
|
853
|
+
fn += "precede = (start, end, fn) => " + this.options.customPrecede + ".call(@, start, end, fn)\n";
|
854
|
+
} else {
|
855
|
+
fn += "precede = (start, fn) => start + fn.call(@)?.replace(/^\s+/g, '')\n";
|
856
|
+
}
|
857
|
+
}
|
858
|
+
if (code.indexOf('$r') !== -1) {
|
859
|
+
if (this.options.customReference) {
|
860
|
+
fn += "$r = " + this.options.customReference + "\n";
|
861
|
+
} else {
|
862
|
+
fn += "$r = (object, prefix) ->\n name = if prefix then prefix + '_' else ''\n\n if typeof(object.hamlObjectRef) is 'function'\n name += object.hamlObjectRef()\n else\n name += (object.constructor?.name || 'object').replace(/\W+/g, '_').replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase()\n\n id = if typeof(object.to_key) is 'function'\n object.to_key()\n else if typeof(object.id) is 'function'\n object.id()\n else if object.id\n object.id\n else\n object\n\n result = \"class='\#{ name }'\"\n result += \" id='\#{ name }_\#{ id }'\" if id\n";
|
863
|
+
}
|
864
|
+
}
|
865
|
+
fn += "$o = []\n";
|
866
|
+
fn += "" + code + "\n";
|
867
|
+
return fn += "return $o.join(\"\\n\")" + (this.convertBooleans(code)) + (this.removeEmptyIDAndClass(code)) + (this.cleanupWhitespace(code)) + "\n";
|
868
|
+
};
|
869
|
+
|
870
|
+
HamlCoffee.prototype.createCode = function() {
|
871
|
+
var child, code, line, processors, _i, _j, _len, _len1, _ref, _ref1;
|
872
|
+
code = [];
|
873
|
+
this.lines = [];
|
874
|
+
_ref = this.root.children;
|
875
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
876
|
+
child = _ref[_i];
|
877
|
+
this.lines = this.lines.concat(child.render());
|
878
|
+
}
|
879
|
+
this.lines = this.combineText(this.lines);
|
880
|
+
this.blockLevel = 0;
|
881
|
+
_ref1 = this.lines;
|
882
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
883
|
+
line = _ref1[_j];
|
884
|
+
if (line !== null) {
|
885
|
+
switch (line.type) {
|
886
|
+
case 'text':
|
887
|
+
code.push("" + (whitespace(line.cw)) + (this.getBuffer(this.blockLevel)) + ".push \"" + (whitespace(line.hw)) + line.text + "\"");
|
888
|
+
break;
|
889
|
+
case 'run':
|
890
|
+
if (line.block !== 'end') {
|
891
|
+
code.push("" + (whitespace(line.cw)) + line.code);
|
892
|
+
} else {
|
893
|
+
code.push("" + (whitespace(line.cw)) + (line.code.replace('$buffer', this.getBuffer(this.blockLevel))));
|
894
|
+
this.blockLevel -= 1;
|
895
|
+
}
|
896
|
+
break;
|
897
|
+
case 'insert':
|
898
|
+
processors = '';
|
899
|
+
if (line.findAndPreserve) {
|
900
|
+
processors += '$fp ';
|
901
|
+
}
|
902
|
+
if (line.preserve) {
|
903
|
+
processors += '$p ';
|
904
|
+
}
|
905
|
+
if (line.escape) {
|
906
|
+
processors += '$e ';
|
907
|
+
}
|
908
|
+
if (this.options.cleanValue) {
|
909
|
+
processors += '$c ';
|
910
|
+
}
|
911
|
+
code.push("" + (whitespace(line.cw)) + (this.getBuffer(this.blockLevel)) + ".push \"" + (whitespace(line.hw)) + "\" + " + processors + line.code);
|
912
|
+
if (line.block === 'start') {
|
913
|
+
this.blockLevel += 1;
|
914
|
+
code.push("" + (whitespace(line.cw + 1)) + (this.getBuffer(this.blockLevel)) + " = []");
|
915
|
+
}
|
916
|
+
}
|
917
|
+
}
|
918
|
+
}
|
919
|
+
return code.join('\n');
|
920
|
+
};
|
921
|
+
|
922
|
+
HamlCoffee.prototype.getBuffer = function(level) {
|
923
|
+
if (level > 0) {
|
924
|
+
return "$o" + level;
|
925
|
+
} else {
|
926
|
+
return '$o';
|
927
|
+
}
|
928
|
+
};
|
929
|
+
|
930
|
+
HamlCoffee.prototype.combineText = function(lines) {
|
931
|
+
var combined, line, nextLine;
|
932
|
+
combined = [];
|
933
|
+
while ((line = lines.shift()) !== void 0) {
|
934
|
+
if (line.type === 'text') {
|
935
|
+
while (lines[0] && lines[0].type === 'text' && line.cw === lines[0].cw) {
|
936
|
+
nextLine = lines.shift();
|
937
|
+
line.text += "\\n" + (whitespace(nextLine.hw)) + nextLine.text;
|
938
|
+
}
|
939
|
+
}
|
940
|
+
combined.push(line);
|
941
|
+
}
|
942
|
+
return combined;
|
943
|
+
};
|
944
|
+
|
945
|
+
HamlCoffee.prototype.convertBooleans = function(code) {
|
946
|
+
if (code.indexOf('$c') !== -1) {
|
947
|
+
if (this.options.format === 'xhtml') {
|
948
|
+
return '.replace(/\\s([\\w-]+)=\'\u0093true\'/mg, " $1=\'$1\'").replace(/\\s([\\w-]+)=\'\u0093false\'/mg, \'\')';
|
949
|
+
} else {
|
950
|
+
return '.replace(/\\s([\\w-]+)=\'\u0093true\'/mg, \' $1\').replace(/\\s([\\w-]+)=\'\u0093false\'/mg, \'\')';
|
951
|
+
}
|
952
|
+
} else {
|
953
|
+
return '';
|
954
|
+
}
|
955
|
+
};
|
956
|
+
|
957
|
+
HamlCoffee.prototype.removeEmptyIDAndClass = function(code) {
|
958
|
+
if (code.indexOf('id=') !== -1 || code.indexOf('class=') !== -1) {
|
959
|
+
return '.replace(/\\s(?:id|class)=([\'"])(\\1)/mg, "")';
|
960
|
+
} else {
|
961
|
+
return '';
|
962
|
+
}
|
963
|
+
};
|
964
|
+
|
965
|
+
HamlCoffee.prototype.cleanupWhitespace = function(code) {
|
966
|
+
if (/\u0091|\u0092/.test(code)) {
|
967
|
+
return ".replace(/[\\s\\n]*\\u0091/mg, '').replace(/\\u0092[\\s\\n]*/mg, '')";
|
968
|
+
} else {
|
969
|
+
return '';
|
970
|
+
}
|
971
|
+
};
|
972
|
+
|
973
|
+
HamlCoffee.prototype.findDependencies = function(code) {
|
974
|
+
var dependencies, match, module, name, requireRegexp;
|
975
|
+
requireRegexp = /require(?:\s+|\()(['"])(.+?)(\1)\)?/gm;
|
976
|
+
dependencies = {};
|
977
|
+
while (match = requireRegexp.exec(code)) {
|
978
|
+
module = match[2];
|
979
|
+
name = module.split('/').pop();
|
980
|
+
dependencies[name] = module;
|
981
|
+
}
|
982
|
+
return dependencies;
|
983
|
+
};
|
984
|
+
|
985
|
+
return HamlCoffee;
|
986
|
+
|
987
|
+
})();
|
988
|
+
|
989
|
+
}).call(this);
|
990
|
+
|
991
|
+
});
|
992
|
+
|
993
|
+
require.define("/nodes/node.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
994
|
+
var Node, escapeHTML;
|
995
|
+
|
996
|
+
escapeHTML = require('../util/text').escapeHTML;
|
997
|
+
|
998
|
+
module.exports = Node = (function() {
|
999
|
+
Node.CLEAR_WHITESPACE_LEFT = '\u0091';
|
1000
|
+
|
1001
|
+
Node.CLEAR_WHITESPACE_RIGHT = '\u0092';
|
1002
|
+
|
1003
|
+
function Node(expression, options) {
|
1004
|
+
this.expression = expression != null ? expression : '';
|
1005
|
+
if (options == null) {
|
1006
|
+
options = {};
|
1007
|
+
}
|
1008
|
+
this.parentNode = options.parentNode;
|
1009
|
+
this.children = [];
|
1010
|
+
this.opener = this.closer = null;
|
1011
|
+
this.silent = false;
|
1012
|
+
this.preserveTags = options.preserveTags.split(',');
|
1013
|
+
this.preserve = false;
|
1014
|
+
this.wsRemoval = {
|
1015
|
+
around: false,
|
1016
|
+
inside: false
|
1017
|
+
};
|
1018
|
+
this.escapeHtml = options.escapeHtml;
|
1019
|
+
this.escapeAttributes = options.escapeAttributes;
|
1020
|
+
this.cleanValue = options.cleanValue;
|
1021
|
+
this.format = options.format;
|
1022
|
+
this.hyphenateDataAttrs = options.hyphenateDataAttrs;
|
1023
|
+
this.selfCloseTags = options.selfCloseTags.split(',');
|
1024
|
+
this.uglify = options.uglify;
|
1025
|
+
this.codeBlockLevel = options.codeBlockLevel;
|
1026
|
+
this.blockLevel = options.blockLevel;
|
1027
|
+
this.placement = options.placement;
|
1028
|
+
this.namespace = options.namespace;
|
1029
|
+
this.name = options.name;
|
1030
|
+
}
|
1031
|
+
|
1032
|
+
Node.prototype.addChild = function(child) {
|
1033
|
+
this.children.push(child);
|
1034
|
+
return this;
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
Node.prototype.getOpener = function() {
|
1038
|
+
if (this.wsRemoval.around && this.opener.text) {
|
1039
|
+
this.opener.text = Node.CLEAR_WHITESPACE_LEFT + this.opener.text;
|
1040
|
+
}
|
1041
|
+
if (this.wsRemoval.inside && this.opener.text) {
|
1042
|
+
this.opener.text += Node.CLEAR_WHITESPACE_RIGHT;
|
1043
|
+
}
|
1044
|
+
return this.opener;
|
1045
|
+
};
|
1046
|
+
|
1047
|
+
Node.prototype.getCloser = function() {
|
1048
|
+
if (this.wsRemoval.inside && this.closer.text) {
|
1049
|
+
this.closer.text = Node.CLEAR_WHITESPACE_LEFT + this.closer.text;
|
1050
|
+
}
|
1051
|
+
if (this.wsRemoval.around && this.closer.text) {
|
1052
|
+
this.closer.text += Node.CLEAR_WHITESPACE_RIGHT;
|
1053
|
+
}
|
1054
|
+
return this.closer;
|
1055
|
+
};
|
1056
|
+
|
1057
|
+
Node.prototype.isPreserved = function() {
|
1058
|
+
if (this.preserve) {
|
1059
|
+
return true;
|
1060
|
+
}
|
1061
|
+
if (this.parentNode) {
|
1062
|
+
return this.parentNode.isPreserved();
|
1063
|
+
} else {
|
1064
|
+
return false;
|
1065
|
+
}
|
1066
|
+
};
|
1067
|
+
|
1068
|
+
Node.prototype.isCommented = function() {
|
1069
|
+
if (this.constructor.name === 'Comment') {
|
1070
|
+
return true;
|
1071
|
+
}
|
1072
|
+
if (this.parentNode) {
|
1073
|
+
return this.parentNode.isCommented();
|
1074
|
+
} else {
|
1075
|
+
return false;
|
1076
|
+
}
|
1077
|
+
};
|
1078
|
+
|
1079
|
+
Node.prototype.markText = function(text, escape) {
|
1080
|
+
if (escape == null) {
|
1081
|
+
escape = false;
|
1082
|
+
}
|
1083
|
+
return {
|
1084
|
+
type: 'text',
|
1085
|
+
cw: this.codeBlockLevel,
|
1086
|
+
hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel,
|
1087
|
+
text: escape ? escapeHTML(text) : text
|
1088
|
+
};
|
1089
|
+
};
|
1090
|
+
|
1091
|
+
Node.prototype.markRunningCode = function(code) {
|
1092
|
+
return {
|
1093
|
+
type: 'run',
|
1094
|
+
cw: this.codeBlockLevel,
|
1095
|
+
code: code
|
1096
|
+
};
|
1097
|
+
};
|
1098
|
+
|
1099
|
+
Node.prototype.markInsertingCode = function(code, escape, preserve, findAndPreserve) {
|
1100
|
+
if (escape == null) {
|
1101
|
+
escape = false;
|
1102
|
+
}
|
1103
|
+
if (preserve == null) {
|
1104
|
+
preserve = false;
|
1105
|
+
}
|
1106
|
+
if (findAndPreserve == null) {
|
1107
|
+
findAndPreserve = false;
|
1108
|
+
}
|
1109
|
+
return {
|
1110
|
+
type: 'insert',
|
1111
|
+
cw: this.codeBlockLevel,
|
1112
|
+
hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel,
|
1113
|
+
escape: escape,
|
1114
|
+
preserve: preserve,
|
1115
|
+
findAndPreserve: findAndPreserve,
|
1116
|
+
code: code
|
1117
|
+
};
|
1118
|
+
};
|
1119
|
+
|
1120
|
+
Node.prototype.evaluate = function() {};
|
1121
|
+
|
1122
|
+
Node.prototype.render = function() {
|
1123
|
+
var child, output, rendered, tag, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4;
|
1124
|
+
output = [];
|
1125
|
+
if (this.silent) {
|
1126
|
+
return output;
|
1127
|
+
}
|
1128
|
+
if (this.children.length === 0) {
|
1129
|
+
if (this.opener && this.closer) {
|
1130
|
+
tag = this.getOpener();
|
1131
|
+
tag.text += this.getCloser().text;
|
1132
|
+
output.push(tag);
|
1133
|
+
} else {
|
1134
|
+
if (!this.preserve && this.isPreserved()) {
|
1135
|
+
output.push(this.getOpener());
|
1136
|
+
} else {
|
1137
|
+
output.push(this.getOpener());
|
1138
|
+
}
|
1139
|
+
}
|
1140
|
+
} else {
|
1141
|
+
if (this.opener && this.closer) {
|
1142
|
+
if (this.preserve) {
|
1143
|
+
this.wsRemoval.inside = true;
|
1144
|
+
output.push(this.getOpener());
|
1145
|
+
_ref = this.children;
|
1146
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1147
|
+
child = _ref[_i];
|
1148
|
+
_ref1 = child.render();
|
1149
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
1150
|
+
rendered = _ref1[_j];
|
1151
|
+
rendered.hw = this.blockLevel;
|
1152
|
+
output.push(rendered);
|
1153
|
+
}
|
1154
|
+
}
|
1155
|
+
output.push(this.getCloser());
|
1156
|
+
} else {
|
1157
|
+
output.push(this.getOpener());
|
1158
|
+
_ref2 = this.children;
|
1159
|
+
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
1160
|
+
child = _ref2[_k];
|
1161
|
+
output = output.concat(child.render());
|
1162
|
+
}
|
1163
|
+
output.push(this.getCloser());
|
1164
|
+
}
|
1165
|
+
} else if (this.opener) {
|
1166
|
+
output.push(this.getOpener());
|
1167
|
+
_ref3 = this.children;
|
1168
|
+
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
|
1169
|
+
child = _ref3[_l];
|
1170
|
+
output = output.concat(child.render());
|
1171
|
+
}
|
1172
|
+
} else {
|
1173
|
+
_ref4 = this.children;
|
1174
|
+
for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {
|
1175
|
+
child = _ref4[_m];
|
1176
|
+
output.push(this.markText(child.render().text));
|
1177
|
+
}
|
1178
|
+
}
|
1179
|
+
}
|
1180
|
+
return output;
|
1181
|
+
};
|
1182
|
+
|
1183
|
+
return Node;
|
1184
|
+
|
1185
|
+
})();
|
1186
|
+
|
1187
|
+
}).call(this);
|
1188
|
+
|
1189
|
+
});
|
1190
|
+
|
1191
|
+
require.define("/util/text.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
1192
|
+
module.exports = {
|
1193
|
+
whitespace: function(n) {
|
1194
|
+
var a;
|
1195
|
+
n = n * 2;
|
1196
|
+
a = [];
|
1197
|
+
while (a.length < n) {
|
1198
|
+
a.push(' ');
|
1199
|
+
}
|
1200
|
+
return a.join('');
|
1201
|
+
},
|
1202
|
+
escapeQuotes: function(text) {
|
1203
|
+
if (!text) {
|
1204
|
+
return '';
|
1205
|
+
}
|
1206
|
+
return text.replace(/"/g, '\\"').replace(/\\\\\"/g, '\\"');
|
1207
|
+
},
|
1208
|
+
unescapeQuotes: function(text) {
|
1209
|
+
if (!text) {
|
1210
|
+
return '';
|
1211
|
+
}
|
1212
|
+
return text.replace(/\\"/g, '"');
|
1213
|
+
},
|
1214
|
+
escapeHTML: function(text) {
|
1215
|
+
if (!text) {
|
1216
|
+
return '';
|
1217
|
+
}
|
1218
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"');
|
1219
|
+
},
|
1220
|
+
preserve: function(code) {
|
1221
|
+
if (code) {
|
1222
|
+
code.replace(/\r/g, '');
|
1223
|
+
return code.replace(/<(pre|textarea)>(.*?)<\/\1>/g, function(text) {
|
1224
|
+
return text.replace('\\n', '\&\#x000A;');
|
1225
|
+
});
|
1226
|
+
}
|
1227
|
+
},
|
1228
|
+
indent: function(text, spaces) {
|
1229
|
+
return text.replace(/^(.*)$/mg, module.exports.whitespace(spaces) + '$1');
|
1230
|
+
}
|
1231
|
+
};
|
1232
|
+
|
1233
|
+
}).call(this);
|
1234
|
+
|
1235
|
+
});
|
1236
|
+
|
1237
|
+
require.define("/nodes/text.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
1238
|
+
var Node, Text, escapeQuotes, _ref,
|
1239
|
+
__hasProp = {}.hasOwnProperty,
|
1240
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
1241
|
+
|
1242
|
+
Node = require('./node');
|
1243
|
+
|
1244
|
+
escapeQuotes = require('../util/text').escapeQuotes;
|
1245
|
+
|
1246
|
+
module.exports = Text = (function(_super) {
|
1247
|
+
__extends(Text, _super);
|
1248
|
+
|
1249
|
+
function Text() {
|
1250
|
+
_ref = Text.__super__.constructor.apply(this, arguments);
|
1251
|
+
return _ref;
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
Text.prototype.evaluate = function() {
|
1255
|
+
return this.opener = this.markText(escapeQuotes(this.expression));
|
1256
|
+
};
|
1257
|
+
|
1258
|
+
return Text;
|
1259
|
+
|
1260
|
+
})(Node);
|
1261
|
+
|
1262
|
+
}).call(this);
|
1263
|
+
|
1264
|
+
});
|
1265
|
+
|
1266
|
+
require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
1267
|
+
var Haml, Node, escapeQuotes, _ref,
|
1268
|
+
__hasProp = {}.hasOwnProperty,
|
1269
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
1270
|
+
|
1271
|
+
Node = require('./node');
|
1272
|
+
|
1273
|
+
escapeQuotes = require('../util/text').escapeQuotes;
|
1274
|
+
|
1275
|
+
module.exports = Haml = (function(_super) {
|
1276
|
+
__extends(Haml, _super);
|
1277
|
+
|
1278
|
+
function Haml() {
|
1279
|
+
_ref = Haml.__super__.constructor.apply(this, arguments);
|
1280
|
+
return _ref;
|
1281
|
+
}
|
1282
|
+
|
1283
|
+
Haml.prototype.evaluate = function() {
|
1284
|
+
var assignment, code, identifier, match, prefix, tokens;
|
1285
|
+
tokens = this.parseExpression(this.expression);
|
1286
|
+
if (tokens.doctype) {
|
1287
|
+
return this.opener = this.markText("" + (escapeQuotes(this.buildDocType(tokens.doctype))));
|
1288
|
+
} else {
|
1289
|
+
if (this.isNotSelfClosing(tokens.tag)) {
|
1290
|
+
prefix = this.buildHtmlTagPrefix(tokens);
|
1291
|
+
if (tokens.assignment) {
|
1292
|
+
match = tokens.assignment.match(/^(=|!=|&=|~)\s*(.*)$/);
|
1293
|
+
identifier = match[1];
|
1294
|
+
assignment = match[2];
|
1295
|
+
if (identifier === '~') {
|
1296
|
+
code = "\#{$fp " + assignment + " }";
|
1297
|
+
} else if (identifier === '&=' || (identifier === '=' && this.escapeHtml)) {
|
1298
|
+
if (this.preserve) {
|
1299
|
+
if (this.cleanValue) {
|
1300
|
+
code = "\#{ $p($e($c(" + assignment + "))) }";
|
1301
|
+
} else {
|
1302
|
+
code = "\#{ $p($e(" + assignment + ")) }";
|
1303
|
+
}
|
1304
|
+
} else {
|
1305
|
+
if (this.cleanValue) {
|
1306
|
+
code = "\#{ $e($c(" + assignment + ")) }";
|
1307
|
+
} else {
|
1308
|
+
code = "\#{ $e(" + assignment + ") }";
|
1309
|
+
}
|
1310
|
+
}
|
1311
|
+
} else if (identifier === '!=' || (identifier === '=' && !this.escapeHtml)) {
|
1312
|
+
if (this.preserve) {
|
1313
|
+
if (this.cleanValue) {
|
1314
|
+
code = "\#{ $p($c(" + assignment + ")) }";
|
1315
|
+
} else {
|
1316
|
+
code = "\#{ $p(" + assignment + ") }";
|
1317
|
+
}
|
1318
|
+
} else {
|
1319
|
+
if (this.cleanValue) {
|
1320
|
+
code = "\#{ $c(" + assignment + ") }";
|
1321
|
+
} else {
|
1322
|
+
code = "\#{ " + assignment + " }";
|
1323
|
+
}
|
1324
|
+
}
|
1325
|
+
}
|
1326
|
+
this.opener = this.markText("" + prefix + ">" + code);
|
1327
|
+
return this.closer = this.markText("</" + tokens.tag + ">");
|
1328
|
+
} else if (tokens.text) {
|
1329
|
+
this.opener = this.markText("" + prefix + ">" + tokens.text);
|
1330
|
+
return this.closer = this.markText("</" + tokens.tag + ">");
|
1331
|
+
} else {
|
1332
|
+
this.opener = this.markText(prefix + '>');
|
1333
|
+
return this.closer = this.markText("</" + tokens.tag + ">");
|
1334
|
+
}
|
1335
|
+
} else {
|
1336
|
+
tokens.tag = tokens.tag.replace(/\/$/, '');
|
1337
|
+
prefix = this.buildHtmlTagPrefix(tokens);
|
1338
|
+
if (tokens.text) {
|
1339
|
+
this.opener = this.markText("" + prefix + ">" + tokens.text);
|
1340
|
+
return this.closer = this.markText("</" + tokens.tag + ">");
|
1341
|
+
} else {
|
1342
|
+
return this.opener = this.markText("" + prefix + (this.format === 'xhtml' ? ' /' : '') + ">" + tokens.text);
|
1343
|
+
}
|
1344
|
+
}
|
1345
|
+
}
|
1346
|
+
};
|
1347
|
+
|
1348
|
+
Haml.prototype.parseExpression = function(exp) {
|
1349
|
+
var attributes, classes, id, key, tag, value, _ref1, _ref2;
|
1350
|
+
tag = this.parseTag(exp);
|
1351
|
+
if (this.preserveTags.indexOf(tag.tag) !== -1) {
|
1352
|
+
this.preserve = true;
|
1353
|
+
}
|
1354
|
+
id = this.interpolateCodeAttribute((_ref1 = tag.ids) != null ? _ref1.pop() : void 0, true);
|
1355
|
+
classes = tag.classes;
|
1356
|
+
attributes = {};
|
1357
|
+
if (tag.attributes) {
|
1358
|
+
_ref2 = tag.attributes;
|
1359
|
+
for (key in _ref2) {
|
1360
|
+
value = _ref2[key];
|
1361
|
+
if (key === 'id') {
|
1362
|
+
if (id) {
|
1363
|
+
id += '_' + this.interpolateCodeAttribute(value, true);
|
1364
|
+
} else {
|
1365
|
+
id = this.interpolateCodeAttribute(value, true);
|
1366
|
+
}
|
1367
|
+
} else if (key === 'class') {
|
1368
|
+
classes || (classes = []);
|
1369
|
+
classes.push(value);
|
1370
|
+
} else {
|
1371
|
+
attributes[key] = value;
|
1372
|
+
}
|
1373
|
+
}
|
1374
|
+
}
|
1375
|
+
return {
|
1376
|
+
doctype: tag.doctype,
|
1377
|
+
tag: tag.tag,
|
1378
|
+
id: id,
|
1379
|
+
classes: classes,
|
1380
|
+
text: escapeQuotes(tag.text),
|
1381
|
+
attributes: attributes,
|
1382
|
+
assignment: tag.assignment,
|
1383
|
+
reference: tag.reference
|
1384
|
+
};
|
1385
|
+
};
|
1386
|
+
|
1387
|
+
Haml.prototype.parseTag = function(exp) {
|
1388
|
+
var assignment, attr, attributes, ch, classes, doctype, end, error, haml, htmlAttributes, id, ids, key, klass, level, pos, reference, rest, rubyAttributes, start, tag, text, val, whitespace, _i, _j, _k, _len, _len1, _ref1, _ref2, _ref3, _ref4, _ref5;
|
1389
|
+
try {
|
1390
|
+
doctype = (_ref1 = exp.match(/^(\!{3}.*)/)) != null ? _ref1[1] : void 0;
|
1391
|
+
if (doctype) {
|
1392
|
+
return {
|
1393
|
+
doctype: doctype
|
1394
|
+
};
|
1395
|
+
}
|
1396
|
+
haml = exp.match(/^((?:[#%\.][a-z0-9_:\-]*[\/]?)+)/i)[0];
|
1397
|
+
rest = exp.substring(haml.length);
|
1398
|
+
if (rest.match(/^[{([]/)) {
|
1399
|
+
reference = '';
|
1400
|
+
htmlAttributes = '';
|
1401
|
+
rubyAttributes = '';
|
1402
|
+
_ref2 = ['[', '{', '(', '[', '{', '('];
|
1403
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1404
|
+
start = _ref2[_i];
|
1405
|
+
if (start === rest[0]) {
|
1406
|
+
end = (function() {
|
1407
|
+
switch (start) {
|
1408
|
+
case '{':
|
1409
|
+
return '}';
|
1410
|
+
case '(':
|
1411
|
+
return ')';
|
1412
|
+
case '[':
|
1413
|
+
return ']';
|
1414
|
+
}
|
1415
|
+
})();
|
1416
|
+
level = 0;
|
1417
|
+
for (pos = _j = 0, _ref3 = rest.length; 0 <= _ref3 ? _j <= _ref3 : _j >= _ref3; pos = 0 <= _ref3 ? ++_j : --_j) {
|
1418
|
+
ch = rest[pos];
|
1419
|
+
if (ch === start) {
|
1420
|
+
level += 1;
|
1421
|
+
}
|
1422
|
+
if (ch === end) {
|
1423
|
+
if (level === 1) {
|
1424
|
+
break;
|
1425
|
+
} else {
|
1426
|
+
level -= 1;
|
1427
|
+
}
|
1428
|
+
}
|
1429
|
+
}
|
1430
|
+
switch (start) {
|
1431
|
+
case '{':
|
1432
|
+
rubyAttributes += rest.substring(0, pos + 1);
|
1433
|
+
rest = rest.substring(pos + 1);
|
1434
|
+
break;
|
1435
|
+
case '(':
|
1436
|
+
htmlAttributes += rest.substring(0, pos + 1);
|
1437
|
+
rest = rest.substring(pos + 1);
|
1438
|
+
break;
|
1439
|
+
case '[':
|
1440
|
+
reference = rest.substring(1, pos);
|
1441
|
+
rest = rest.substring(pos + 1);
|
1442
|
+
}
|
1443
|
+
}
|
1444
|
+
}
|
1445
|
+
assignment = rest || '';
|
1446
|
+
} else {
|
1447
|
+
reference = '';
|
1448
|
+
htmlAttributes = '';
|
1449
|
+
rubyAttributes = '';
|
1450
|
+
assignment = rest;
|
1451
|
+
}
|
1452
|
+
attributes = {};
|
1453
|
+
_ref4 = [this.parseAttributes(htmlAttributes), this.parseAttributes(rubyAttributes)];
|
1454
|
+
for (_k = 0, _len1 = _ref4.length; _k < _len1; _k++) {
|
1455
|
+
attr = _ref4[_k];
|
1456
|
+
for (key in attr) {
|
1457
|
+
val = attr[key];
|
1458
|
+
attributes[key] = val;
|
1459
|
+
}
|
1460
|
+
}
|
1461
|
+
if (whitespace = (_ref5 = assignment.match(/^[<>]{0,2}/)) != null ? _ref5[0] : void 0) {
|
1462
|
+
assignment = assignment.substring(whitespace.length);
|
1463
|
+
}
|
1464
|
+
if (assignment[0] === ' ') {
|
1465
|
+
assignment = assignment.substring(1);
|
1466
|
+
}
|
1467
|
+
if (assignment && !assignment.match(/^(=|!=|&=|~)/)) {
|
1468
|
+
text = assignment.replace(/^ /, '');
|
1469
|
+
assignment = void 0;
|
1470
|
+
}
|
1471
|
+
if (whitespace) {
|
1472
|
+
if (whitespace.indexOf('>') !== -1) {
|
1473
|
+
this.wsRemoval.around = true;
|
1474
|
+
}
|
1475
|
+
if (whitespace.indexOf('<') !== -1) {
|
1476
|
+
this.wsRemoval.inside = true;
|
1477
|
+
this.preserve = true;
|
1478
|
+
}
|
1479
|
+
}
|
1480
|
+
tag = haml.match(/\%([a-z_\-][a-z0-9_:\-]*[\/]?)/i);
|
1481
|
+
ids = haml.match(/\#([a-z_\-][a-z0-9_\-]*)/gi);
|
1482
|
+
classes = haml.match(/\.([a-z0-9_\-]*)/gi);
|
1483
|
+
return {
|
1484
|
+
tag: tag ? tag[1] : 'div',
|
1485
|
+
ids: ids ? (function() {
|
1486
|
+
var _l, _len2, _results;
|
1487
|
+
_results = [];
|
1488
|
+
for (_l = 0, _len2 = ids.length; _l < _len2; _l++) {
|
1489
|
+
id = ids[_l];
|
1490
|
+
_results.push("'" + (id.substr(1)) + "'");
|
1491
|
+
}
|
1492
|
+
return _results;
|
1493
|
+
})() : void 0,
|
1494
|
+
classes: classes ? (function() {
|
1495
|
+
var _l, _len2, _results;
|
1496
|
+
_results = [];
|
1497
|
+
for (_l = 0, _len2 = classes.length; _l < _len2; _l++) {
|
1498
|
+
klass = classes[_l];
|
1499
|
+
_results.push("'" + (klass.substr(1)) + "'");
|
1500
|
+
}
|
1501
|
+
return _results;
|
1502
|
+
})() : void 0,
|
1503
|
+
attributes: attributes,
|
1504
|
+
assignment: assignment,
|
1505
|
+
reference: reference,
|
1506
|
+
text: text
|
1507
|
+
};
|
1508
|
+
} catch (_error) {
|
1509
|
+
error = _error;
|
1510
|
+
throw new Error("Unable to parse tag from " + exp + ": " + error);
|
1511
|
+
}
|
1512
|
+
};
|
1513
|
+
|
1514
|
+
Haml.prototype.parseAttributes = function(exp) {
|
1515
|
+
var attr, attributes, ch, endPos, hasDataAttribute, inDataAttribute, key, keyValue, keys, level, marker, markers, pairs, pos, quote, quoted, start, startPos, type, value, _i, _j, _k, _len, _len1, _ref1, _ref2, _ref3, _ref4, _ref5;
|
1516
|
+
attributes = {};
|
1517
|
+
if (exp === void 0) {
|
1518
|
+
return attributes;
|
1519
|
+
}
|
1520
|
+
type = exp.substring(0, 1);
|
1521
|
+
exp = exp.replace(/(=|:|=>)\s*('([^\\']|\\\\|\\')*'|"([^\\"]|\\\\|\\")*")/g, function(match, type, value) {
|
1522
|
+
return type + (value != null ? value.replace(/(:|=|=>)/g, '\u0090$1') : void 0);
|
1523
|
+
});
|
1524
|
+
level = 0;
|
1525
|
+
start = 0;
|
1526
|
+
markers = [];
|
1527
|
+
if (type === '(') {
|
1528
|
+
startPos = 1;
|
1529
|
+
endPos = exp.length - 1;
|
1530
|
+
} else {
|
1531
|
+
startPos = 0;
|
1532
|
+
endPos = exp.length;
|
1533
|
+
}
|
1534
|
+
for (pos = _i = startPos; startPos <= endPos ? _i < endPos : _i > endPos; pos = startPos <= endPos ? ++_i : --_i) {
|
1535
|
+
ch = exp[pos];
|
1536
|
+
if (ch === '(') {
|
1537
|
+
level += 1;
|
1538
|
+
if (level === 1) {
|
1539
|
+
start = pos;
|
1540
|
+
}
|
1541
|
+
}
|
1542
|
+
if (ch === ')') {
|
1543
|
+
if (level === 1) {
|
1544
|
+
if (start !== 0 && pos - start !== 1) {
|
1545
|
+
markers.push({
|
1546
|
+
start: start,
|
1547
|
+
end: pos
|
1548
|
+
});
|
1549
|
+
}
|
1550
|
+
} else {
|
1551
|
+
level -= 1;
|
1552
|
+
}
|
1553
|
+
}
|
1554
|
+
}
|
1555
|
+
_ref1 = markers.reverse();
|
1556
|
+
for (_j = 0, _len = _ref1.length; _j < _len; _j++) {
|
1557
|
+
marker = _ref1[_j];
|
1558
|
+
exp = exp.substring(0, marker.start) + exp.substring(marker.start, marker.end).replace(/(:|=|=>)/g, '\u0090$1') + exp.substring(marker.end);
|
1559
|
+
}
|
1560
|
+
switch (type) {
|
1561
|
+
case '(':
|
1562
|
+
keys = /\(\s*([-\w]+[\w:-]*\w?)\s*=|\s+([-\w]+[\w:-]*\w?)\s*=|\(\s*('\w+[\w:-]*\w?')\s*=|\s+('\w+[\w:-]*\w?')\s*=|\(\s*("\w+[\w:-]*\w?")\s*=|\s+("\w+[\w:-]*\w?")\s*=/g;
|
1563
|
+
break;
|
1564
|
+
case '{':
|
1565
|
+
keys = /[{,]\s*(\w+[\w:-]*\w?)\s*:|[{,]\s*('[-\w]+[\w:-]*\w?')\s*:|[{,]\s*("[-\w]+[\w:-]*\w?")\s*:|[{,]\s*:(\w+[\w:-]*\w?)\s*=>|[{,]\s*:?'([-\w]+[\w:-]*\w?)'\s*=>|[{,]\s*:?"([-\w]+[\w:-]*\w?)"\s*=>/g;
|
1566
|
+
}
|
1567
|
+
pairs = exp.split(keys).filter(Boolean);
|
1568
|
+
inDataAttribute = false;
|
1569
|
+
hasDataAttribute = false;
|
1570
|
+
while (pairs.length) {
|
1571
|
+
keyValue = pairs.splice(0, 2);
|
1572
|
+
if (keyValue.length === 1) {
|
1573
|
+
attr = keyValue[0].replace(/^[\s({]+|[\s)}]+$/g, '');
|
1574
|
+
attributes[attr] = 'true';
|
1575
|
+
} else {
|
1576
|
+
key = (_ref2 = keyValue[0]) != null ? _ref2.replace(/^\s+|\s+$/g, '').replace(/^:/, '') : void 0;
|
1577
|
+
if (quoted = key.match(/^("|')(.*)\1$/)) {
|
1578
|
+
key = quoted[2];
|
1579
|
+
}
|
1580
|
+
value = (_ref3 = keyValue[1]) != null ? _ref3.replace(/^\s+|[\s,]+$/g, '').replace(/\u0090/g, '') : void 0;
|
1581
|
+
if (key === 'data' && !value) {
|
1582
|
+
inDataAttribute = true;
|
1583
|
+
hasDataAttribute = true;
|
1584
|
+
} else if (key && value) {
|
1585
|
+
if (inDataAttribute) {
|
1586
|
+
key = this.hyphenateDataAttrs ? "data-" + (key.replace('_', '-')) : "data-" + key;
|
1587
|
+
if (/}\s*$/.test(value)) {
|
1588
|
+
inDataAttribute = false;
|
1589
|
+
}
|
1590
|
+
}
|
1591
|
+
}
|
1592
|
+
switch (type) {
|
1593
|
+
case '(':
|
1594
|
+
value = value.replace(/^\s+|[\s)]+$/g, '');
|
1595
|
+
quote = (_ref4 = /^(['"])/.exec(value)) != null ? _ref4[1] : void 0;
|
1596
|
+
pos = value.lastIndexOf(quote);
|
1597
|
+
if (pos > 1) {
|
1598
|
+
_ref5 = value.substring(pos + 1).split(' ');
|
1599
|
+
for (_k = 0, _len1 = _ref5.length; _k < _len1; _k++) {
|
1600
|
+
attr = _ref5[_k];
|
1601
|
+
if (attr) {
|
1602
|
+
attributes[attr] = 'true';
|
1603
|
+
}
|
1604
|
+
}
|
1605
|
+
value = value.substring(0, pos + 1);
|
1606
|
+
}
|
1607
|
+
attributes[key] = value;
|
1608
|
+
break;
|
1609
|
+
case '{':
|
1610
|
+
attributes[key] = value.replace(/^\s+|[\s}]+$/g, '');
|
1611
|
+
}
|
1612
|
+
}
|
1613
|
+
}
|
1614
|
+
if (hasDataAttribute) {
|
1615
|
+
delete attributes['data'];
|
1616
|
+
}
|
1617
|
+
return attributes;
|
1618
|
+
};
|
1619
|
+
|
1620
|
+
Haml.prototype.buildHtmlTagPrefix = function(tokens) {
|
1621
|
+
var classList, classes, hasDynamicClass, key, klass, name, tagParts, value, _i, _len, _ref1;
|
1622
|
+
tagParts = ["<" + tokens.tag];
|
1623
|
+
if (tokens.classes) {
|
1624
|
+
hasDynamicClass = false;
|
1625
|
+
classList = (function() {
|
1626
|
+
var _i, _len, _ref1, _results;
|
1627
|
+
_ref1 = tokens.classes;
|
1628
|
+
_results = [];
|
1629
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
1630
|
+
name = _ref1[_i];
|
1631
|
+
name = this.interpolateCodeAttribute(name, true);
|
1632
|
+
if (name.indexOf('#{') !== -1) {
|
1633
|
+
hasDynamicClass = true;
|
1634
|
+
}
|
1635
|
+
_results.push(name);
|
1636
|
+
}
|
1637
|
+
return _results;
|
1638
|
+
}).call(this);
|
1639
|
+
if (hasDynamicClass && classList.length > 1) {
|
1640
|
+
classes = '#{ [';
|
1641
|
+
for (_i = 0, _len = classList.length; _i < _len; _i++) {
|
1642
|
+
klass = classList[_i];
|
1643
|
+
classes += "" + (this.quoteAndEscapeAttributeValue(klass, true)) + ",";
|
1644
|
+
}
|
1645
|
+
classes = classes.substring(0, classes.length - 1) + '].sort().join(\' \').replace(/^\\s+|\\s+$/g, \'\') }';
|
1646
|
+
} else {
|
1647
|
+
classes = classList.sort().join(' ');
|
1648
|
+
}
|
1649
|
+
tagParts.push("class='" + classes + "'");
|
1650
|
+
}
|
1651
|
+
if (tokens.id) {
|
1652
|
+
tagParts.push("id='" + tokens.id + "'");
|
1653
|
+
}
|
1654
|
+
if (tokens.reference) {
|
1655
|
+
if (tokens.attributes) {
|
1656
|
+
delete tokens.attributes['class'];
|
1657
|
+
delete tokens.attributes['id'];
|
1658
|
+
}
|
1659
|
+
tagParts.push("\#{$r(" + tokens.reference + ")}");
|
1660
|
+
}
|
1661
|
+
if (tokens.attributes) {
|
1662
|
+
_ref1 = tokens.attributes;
|
1663
|
+
for (key in _ref1) {
|
1664
|
+
value = _ref1[key];
|
1665
|
+
if (value === 'true' || value === 'false') {
|
1666
|
+
if (value === 'true') {
|
1667
|
+
if (this.format === 'html5') {
|
1668
|
+
tagParts.push("" + key);
|
1669
|
+
} else {
|
1670
|
+
tagParts.push("" + key + "=" + (this.quoteAndEscapeAttributeValue(key)));
|
1671
|
+
}
|
1672
|
+
}
|
1673
|
+
} else {
|
1674
|
+
tagParts.push("" + key + "=" + (this.quoteAndEscapeAttributeValue(this.interpolateCodeAttribute(value))));
|
1675
|
+
}
|
1676
|
+
}
|
1677
|
+
}
|
1678
|
+
return tagParts.join(' ');
|
1679
|
+
};
|
1680
|
+
|
1681
|
+
Haml.prototype.interpolateCodeAttribute = function(text, unwrap) {
|
1682
|
+
var quoted;
|
1683
|
+
if (unwrap == null) {
|
1684
|
+
unwrap = false;
|
1685
|
+
}
|
1686
|
+
if (!text) {
|
1687
|
+
return;
|
1688
|
+
}
|
1689
|
+
if (!text.match(/^("|').*\1$/)) {
|
1690
|
+
if (this.escapeAttributes) {
|
1691
|
+
if (this.cleanValue) {
|
1692
|
+
text = '#{ $e($c(' + text + ')) }';
|
1693
|
+
} else {
|
1694
|
+
text = '#{ $e(' + text + ') }';
|
1695
|
+
}
|
1696
|
+
} else {
|
1697
|
+
if (this.cleanValue) {
|
1698
|
+
text = '#{ $c(' + text + ') }';
|
1699
|
+
} else {
|
1700
|
+
text = '#{ (' + text + ') }';
|
1701
|
+
}
|
1702
|
+
}
|
1703
|
+
}
|
1704
|
+
if (unwrap) {
|
1705
|
+
if (quoted = text.match(/^("|')(.*)\1$/)) {
|
1706
|
+
text = quoted[2];
|
1707
|
+
}
|
1708
|
+
}
|
1709
|
+
return text;
|
1710
|
+
};
|
1711
|
+
|
1712
|
+
Haml.prototype.quoteAndEscapeAttributeValue = function(value, code) {
|
1713
|
+
var escaped, hasDoubleQuotes, hasInterpolation, hasSingleQuotes, quoted, result, token, tokens;
|
1714
|
+
if (code == null) {
|
1715
|
+
code = false;
|
1716
|
+
}
|
1717
|
+
if (!value) {
|
1718
|
+
return;
|
1719
|
+
}
|
1720
|
+
if (quoted = value.match(/^("|')(.*)\1$/)) {
|
1721
|
+
value = quoted[2];
|
1722
|
+
}
|
1723
|
+
tokens = this.splitInterpolations(value);
|
1724
|
+
hasSingleQuotes = false;
|
1725
|
+
hasDoubleQuotes = false;
|
1726
|
+
hasInterpolation = false;
|
1727
|
+
tokens = (function() {
|
1728
|
+
var _i, _len, _results;
|
1729
|
+
_results = [];
|
1730
|
+
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
1731
|
+
token = tokens[_i];
|
1732
|
+
if (token.slice(0, 2) === '#{') {
|
1733
|
+
if (token.indexOf('$e') === -1 && token.indexOf('$c') === -1) {
|
1734
|
+
if (this.escapeAttributes) {
|
1735
|
+
if (this.cleanValue) {
|
1736
|
+
token = '#{ $e($c(' + token.slice(2, -1) + ')) }';
|
1737
|
+
} else {
|
1738
|
+
token = '#{ $e(' + token.slice(2, -1) + ') }';
|
1739
|
+
}
|
1740
|
+
} else {
|
1741
|
+
if (this.cleanValue) {
|
1742
|
+
token = '#{ $c(' + token.slice(2, -1) + ') }';
|
1743
|
+
}
|
1744
|
+
}
|
1745
|
+
}
|
1746
|
+
hasInterpolation = true;
|
1747
|
+
} else {
|
1748
|
+
if (!hasSingleQuotes) {
|
1749
|
+
hasSingleQuotes = token.indexOf("'") !== -1;
|
1750
|
+
}
|
1751
|
+
if (!hasDoubleQuotes) {
|
1752
|
+
hasDoubleQuotes = token.indexOf('"') !== -1;
|
1753
|
+
}
|
1754
|
+
}
|
1755
|
+
_results.push(token);
|
1756
|
+
}
|
1757
|
+
return _results;
|
1758
|
+
}).call(this);
|
1759
|
+
if (code) {
|
1760
|
+
if (hasInterpolation) {
|
1761
|
+
result = "\"" + (tokens.join('')) + "\"";
|
1762
|
+
} else {
|
1763
|
+
result = "'" + (tokens.join('')) + "'";
|
1764
|
+
}
|
1765
|
+
} else {
|
1766
|
+
if (!hasDoubleQuotes && !hasSingleQuotes) {
|
1767
|
+
result = "'" + (tokens.join('')) + "'";
|
1768
|
+
}
|
1769
|
+
if (hasSingleQuotes && !hasDoubleQuotes) {
|
1770
|
+
result = "\\\"" + (tokens.join('')) + "\\\"";
|
1771
|
+
}
|
1772
|
+
if (hasDoubleQuotes && !hasSingleQuotes) {
|
1773
|
+
escaped = (function() {
|
1774
|
+
var _i, _len, _results;
|
1775
|
+
_results = [];
|
1776
|
+
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
1777
|
+
token = tokens[_i];
|
1778
|
+
_results.push(escapeQuotes(token));
|
1779
|
+
}
|
1780
|
+
return _results;
|
1781
|
+
})();
|
1782
|
+
result = "'" + (escaped.join('')) + "'";
|
1783
|
+
}
|
1784
|
+
if (hasSingleQuotes && hasDoubleQuotes) {
|
1785
|
+
escaped = (function() {
|
1786
|
+
var _i, _len, _results;
|
1787
|
+
_results = [];
|
1788
|
+
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
1789
|
+
token = tokens[_i];
|
1790
|
+
_results.push(escapeQuotes(token).replace(/'/g, '''));
|
1791
|
+
}
|
1792
|
+
return _results;
|
1793
|
+
})();
|
1794
|
+
result = "'" + (escaped.join('')) + "'";
|
1795
|
+
}
|
1796
|
+
}
|
1797
|
+
return result;
|
1798
|
+
};
|
1799
|
+
|
1800
|
+
Haml.prototype.splitInterpolations = function(value) {
|
1801
|
+
var ch, ch2, level, pos, start, tokens, _i, _ref1;
|
1802
|
+
level = 0;
|
1803
|
+
start = 0;
|
1804
|
+
tokens = [];
|
1805
|
+
for (pos = _i = 0, _ref1 = value.length; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; pos = 0 <= _ref1 ? ++_i : --_i) {
|
1806
|
+
ch = value[pos];
|
1807
|
+
ch2 = value.slice(pos, +(pos + 1) + 1 || 9e9);
|
1808
|
+
if (ch === '{') {
|
1809
|
+
level += 1;
|
1810
|
+
}
|
1811
|
+
if (ch2 === '#{' && level === 0) {
|
1812
|
+
tokens.push(value.slice(start, pos));
|
1813
|
+
start = pos;
|
1814
|
+
}
|
1815
|
+
if (ch === '}') {
|
1816
|
+
level -= 1;
|
1817
|
+
if (level === 0) {
|
1818
|
+
tokens.push(value.slice(start, +pos + 1 || 9e9));
|
1819
|
+
start = pos + 1;
|
1820
|
+
}
|
1821
|
+
}
|
1822
|
+
}
|
1823
|
+
tokens.push(value.slice(start, value.length));
|
1824
|
+
return tokens.filter(Boolean);
|
1825
|
+
};
|
1826
|
+
|
1827
|
+
Haml.prototype.buildDocType = function(doctype) {
|
1828
|
+
switch ("" + this.format + " " + doctype) {
|
1829
|
+
case 'xhtml !!! XML':
|
1830
|
+
return '<?xml version=\'1.0\' encoding=\'utf-8\' ?>';
|
1831
|
+
case 'xhtml !!!':
|
1832
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
1833
|
+
case 'xhtml !!! 1.1':
|
1834
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
|
1835
|
+
case 'xhtml !!! mobile':
|
1836
|
+
return '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">';
|
1837
|
+
case 'xhtml !!! basic':
|
1838
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">';
|
1839
|
+
case 'xhtml !!! frameset':
|
1840
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
|
1841
|
+
case 'xhtml !!! 5':
|
1842
|
+
case 'html5 !!!':
|
1843
|
+
return '<!DOCTYPE html>';
|
1844
|
+
case 'html5 !!! XML':
|
1845
|
+
case 'html4 !!! XML':
|
1846
|
+
return '';
|
1847
|
+
case 'html4 !!!':
|
1848
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
|
1849
|
+
case 'html4 !!! frameset':
|
1850
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">';
|
1851
|
+
case 'html4 !!! strict':
|
1852
|
+
return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
|
1853
|
+
}
|
1854
|
+
};
|
1855
|
+
|
1856
|
+
Haml.prototype.isNotSelfClosing = function(tag) {
|
1857
|
+
return this.selfCloseTags.indexOf(tag) === -1 && !tag.match(/\/$/);
|
1858
|
+
};
|
1859
|
+
|
1860
|
+
return Haml;
|
1861
|
+
|
1862
|
+
})(Node);
|
1863
|
+
|
1864
|
+
}).call(this);
|
1865
|
+
|
1866
|
+
});
|
1867
|
+
|
1868
|
+
require.define("/nodes/code.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
1869
|
+
var Code, Node, _ref,
|
1870
|
+
__hasProp = {}.hasOwnProperty,
|
1871
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
1872
|
+
|
1873
|
+
Node = require('./node');
|
1874
|
+
|
1875
|
+
module.exports = Code = (function(_super) {
|
1876
|
+
__extends(Code, _super);
|
1877
|
+
|
1878
|
+
function Code() {
|
1879
|
+
_ref = Code.__super__.constructor.apply(this, arguments);
|
1880
|
+
return _ref;
|
1881
|
+
}
|
1882
|
+
|
1883
|
+
Code.prototype.evaluate = function() {
|
1884
|
+
var code, codeBlock, escape, identifier;
|
1885
|
+
codeBlock = this.expression.match(/(-|!=|\&=|=|~)\s?(.*)?/);
|
1886
|
+
identifier = codeBlock[1];
|
1887
|
+
code = codeBlock[2];
|
1888
|
+
if (identifier === '-') {
|
1889
|
+
this.opener = this.markRunningCode(code);
|
1890
|
+
if (this.children.length !== 0 && this.opener.code.match(/(->|=>)/)) {
|
1891
|
+
return this.closer = this.markRunningCode(" ''");
|
1892
|
+
}
|
1893
|
+
} else if (identifier === '~') {
|
1894
|
+
if (this.escapeHtml) {
|
1895
|
+
return this.opener = this.markInsertingCode(code, true, false, true);
|
1896
|
+
} else {
|
1897
|
+
return this.opener = this.markInsertingCode(code, false, false, true);
|
1898
|
+
}
|
1899
|
+
} else {
|
1900
|
+
escape = identifier === '&=' || (identifier === '=' && this.escapeHtml);
|
1901
|
+
if (this.children.length !== 0 && code.match(/(->|=>)$/)) {
|
1902
|
+
this.opener = this.markInsertingCode(code, escape, false, false);
|
1903
|
+
this.opener.block = 'start';
|
1904
|
+
this.closer = this.markRunningCode(" $buffer.join \"\\n\"");
|
1905
|
+
return this.closer.block = 'end';
|
1906
|
+
} else {
|
1907
|
+
return this.opener = this.markInsertingCode(code, escape);
|
1908
|
+
}
|
1909
|
+
}
|
1910
|
+
};
|
1911
|
+
|
1912
|
+
return Code;
|
1913
|
+
|
1914
|
+
})(Node);
|
1915
|
+
|
1916
|
+
}).call(this);
|
1917
|
+
|
1918
|
+
});
|
1919
|
+
|
1920
|
+
require.define("/nodes/comment.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
1921
|
+
var Comment, Node, escapeQuotes, _ref,
|
1922
|
+
__hasProp = {}.hasOwnProperty,
|
1923
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
1924
|
+
|
1925
|
+
Node = require('./node');
|
1926
|
+
|
1927
|
+
escapeQuotes = require('../util/text').escapeQuotes;
|
1928
|
+
|
1929
|
+
module.exports = Comment = (function(_super) {
|
1930
|
+
__extends(Comment, _super);
|
1931
|
+
|
1932
|
+
function Comment() {
|
1933
|
+
_ref = Comment.__super__.constructor.apply(this, arguments);
|
1934
|
+
return _ref;
|
1935
|
+
}
|
1936
|
+
|
1937
|
+
Comment.prototype.evaluate = function() {
|
1938
|
+
var comment, expression, identifier, _ref1;
|
1939
|
+
_ref1 = this.expression.match(/(-#|\/\[|\/)\s?(.*)?/), expression = _ref1[0], identifier = _ref1[1], comment = _ref1[2];
|
1940
|
+
switch (identifier) {
|
1941
|
+
case '-#':
|
1942
|
+
this.silent = true;
|
1943
|
+
return this.opener = this.markText('');
|
1944
|
+
case '\/[':
|
1945
|
+
this.opener = this.markText("<!--[" + comment + ">");
|
1946
|
+
return this.closer = this.markText('<![endif]-->');
|
1947
|
+
case '\/':
|
1948
|
+
if (comment) {
|
1949
|
+
this.opener = this.markText("<!-- " + (escapeQuotes(comment)));
|
1950
|
+
return this.closer = this.markText(' -->');
|
1951
|
+
} else {
|
1952
|
+
this.opener = this.markText("<!--");
|
1953
|
+
return this.closer = this.markText('-->');
|
1954
|
+
}
|
1955
|
+
}
|
1956
|
+
};
|
1957
|
+
|
1958
|
+
return Comment;
|
1959
|
+
|
1960
|
+
})(Node);
|
1961
|
+
|
1962
|
+
}).call(this);
|
1963
|
+
|
1964
|
+
});
|
1965
|
+
|
1966
|
+
require.define("/nodes/filter.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
1967
|
+
var Filter, Node, unescapeQuotes, whitespace, _ref,
|
1968
|
+
__hasProp = {}.hasOwnProperty,
|
1969
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
1970
|
+
|
1971
|
+
Node = require('./node');
|
1972
|
+
|
1973
|
+
whitespace = require('../util/text').whitespace;
|
1974
|
+
|
1975
|
+
unescapeQuotes = require('../util/text').unescapeQuotes;
|
1976
|
+
|
1977
|
+
module.exports = Filter = (function(_super) {
|
1978
|
+
__extends(Filter, _super);
|
1979
|
+
|
1980
|
+
function Filter() {
|
1981
|
+
_ref = Filter.__super__.constructor.apply(this, arguments);
|
1982
|
+
return _ref;
|
1983
|
+
}
|
1984
|
+
|
1985
|
+
Filter.prototype.evaluate = function() {
|
1986
|
+
var _ref1;
|
1987
|
+
return this.filter = (_ref1 = this.expression.match(/:(escaped|preserve|css|javascript|coffeescript|plain|cdata|coffeescript)(.*)?/)) != null ? _ref1[1] : void 0;
|
1988
|
+
};
|
1989
|
+
|
1990
|
+
Filter.prototype.render = function() {
|
1991
|
+
var child, indent, output, preserve, _i, _j, _len, _len1, _ref1, _ref2;
|
1992
|
+
output = [];
|
1993
|
+
switch (this.filter) {
|
1994
|
+
case 'escaped':
|
1995
|
+
_ref1 = this.children;
|
1996
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
1997
|
+
child = _ref1[_i];
|
1998
|
+
output.push(this.markText(child.render()[0].text, true));
|
1999
|
+
}
|
2000
|
+
break;
|
2001
|
+
case 'preserve':
|
2002
|
+
preserve = '';
|
2003
|
+
_ref2 = this.children;
|
2004
|
+
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
2005
|
+
child = _ref2[_j];
|
2006
|
+
preserve += "" + (child.render()[0].text) + "
";
|
2007
|
+
}
|
2008
|
+
preserve = preserve.replace(/\&\#x000A;$/, '');
|
2009
|
+
output.push(this.markText(preserve));
|
2010
|
+
break;
|
2011
|
+
case 'plain':
|
2012
|
+
this.renderFilterContent(0, output);
|
2013
|
+
break;
|
2014
|
+
case 'css':
|
2015
|
+
if (this.format === 'html5') {
|
2016
|
+
output.push(this.markText('<style>'));
|
2017
|
+
} else {
|
2018
|
+
output.push(this.markText('<style type=\'text/css\'>'));
|
2019
|
+
}
|
2020
|
+
if (this.format === 'xhtml') {
|
2021
|
+
output.push(this.markText(' /*<![CDATA[*/'));
|
2022
|
+
}
|
2023
|
+
indent = this.format === 'xhtml' ? 2 : 1;
|
2024
|
+
this.renderFilterContent(indent, output);
|
2025
|
+
if (this.format === 'xhtml') {
|
2026
|
+
output.push(this.markText(' /*]]>*/'));
|
2027
|
+
}
|
2028
|
+
output.push(this.markText('</style>'));
|
2029
|
+
break;
|
2030
|
+
case 'javascript':
|
2031
|
+
if (this.format === 'html5') {
|
2032
|
+
output.push(this.markText('<script>'));
|
2033
|
+
} else {
|
2034
|
+
output.push(this.markText('<script type=\'text/javascript\'>'));
|
2035
|
+
}
|
2036
|
+
if (this.format === 'xhtml') {
|
2037
|
+
output.push(this.markText(' //<![CDATA['));
|
2038
|
+
}
|
2039
|
+
indent = this.format === 'xhtml' ? 2 : 1;
|
2040
|
+
this.renderFilterContent(indent, output);
|
2041
|
+
if (this.format === 'xhtml') {
|
2042
|
+
output.push(this.markText(' //]]>'));
|
2043
|
+
}
|
2044
|
+
output.push(this.markText('</script>'));
|
2045
|
+
break;
|
2046
|
+
case 'cdata':
|
2047
|
+
output.push(this.markText('<![CDATA['));
|
2048
|
+
this.renderFilterContent(2, output);
|
2049
|
+
output.push(this.markText(']]>'));
|
2050
|
+
break;
|
2051
|
+
case 'coffeescript':
|
2052
|
+
this.renderFilterContent(0, output, 'run');
|
2053
|
+
}
|
2054
|
+
return output;
|
2055
|
+
};
|
2056
|
+
|
2057
|
+
Filter.prototype.renderFilterContent = function(indent, output, type) {
|
2058
|
+
var child, content, e, empty, line, _i, _j, _k, _len, _len1, _ref1, _results;
|
2059
|
+
if (type == null) {
|
2060
|
+
type = 'text';
|
2061
|
+
}
|
2062
|
+
content = [];
|
2063
|
+
empty = 0;
|
2064
|
+
_ref1 = this.children;
|
2065
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
2066
|
+
child = _ref1[_i];
|
2067
|
+
content.push(child.render()[0].text);
|
2068
|
+
}
|
2069
|
+
_results = [];
|
2070
|
+
for (_j = 0, _len1 = content.length; _j < _len1; _j++) {
|
2071
|
+
line = content[_j];
|
2072
|
+
if (line === '') {
|
2073
|
+
_results.push(empty += 1);
|
2074
|
+
} else {
|
2075
|
+
switch (type) {
|
2076
|
+
case 'text':
|
2077
|
+
for (e = _k = 0; 0 <= empty ? _k < empty : _k > empty; e = 0 <= empty ? ++_k : --_k) {
|
2078
|
+
output.push(this.markText(""));
|
2079
|
+
}
|
2080
|
+
output.push(this.markText("" + (whitespace(indent)) + line));
|
2081
|
+
break;
|
2082
|
+
case 'run':
|
2083
|
+
output.push(this.markRunningCode("" + (unescapeQuotes(line))));
|
2084
|
+
}
|
2085
|
+
_results.push(empty = 0);
|
2086
|
+
}
|
2087
|
+
}
|
2088
|
+
return _results;
|
2089
|
+
};
|
2090
|
+
|
2091
|
+
return Filter;
|
2092
|
+
|
2093
|
+
})(Node);
|
2094
|
+
|
2095
|
+
}).call(this);
|
2096
|
+
|
2097
|
+
});
|
2098
|
+
|
2099
|
+
require.define("/nodes/directive.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
2100
|
+
var CoffeeScript, Directive, Node, fs, path, _ref,
|
2101
|
+
__hasProp = {}.hasOwnProperty,
|
2102
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
2103
|
+
|
2104
|
+
path = require('path');
|
2105
|
+
|
2106
|
+
Node = require('./node');
|
2107
|
+
|
2108
|
+
if (!process.browser) {
|
2109
|
+
fs = require('fs');
|
2110
|
+
CoffeeScript = require('coffee-script');
|
2111
|
+
}
|
2112
|
+
|
2113
|
+
module.exports = Directive = (function(_super) {
|
2114
|
+
__extends(Directive, _super);
|
2115
|
+
|
2116
|
+
function Directive() {
|
2117
|
+
_ref = Directive.__super__.constructor.apply(this, arguments);
|
2118
|
+
return _ref;
|
2119
|
+
}
|
2120
|
+
|
2121
|
+
Directive.prototype.directives = {
|
2122
|
+
include: function(expression) {
|
2123
|
+
var Compiler, code, compiler, context, e, error, name, source, statement, _ref1;
|
2124
|
+
try {
|
2125
|
+
_ref1 = expression.match(/\s*['"](.*?)['"](?:,\s*(.*))?\s*/), _ref1[0], name = _ref1[1], context = _ref1[2];
|
2126
|
+
} catch (_error) {
|
2127
|
+
e = _error;
|
2128
|
+
throw new Error("Failed to parse the include directive from " + expression);
|
2129
|
+
}
|
2130
|
+
if (!context) {
|
2131
|
+
context = 'this';
|
2132
|
+
}
|
2133
|
+
statement = (function() {
|
2134
|
+
switch (this.placement) {
|
2135
|
+
case 'global':
|
2136
|
+
return "" + this.namespace + "['" + name + "'](" + context + ")";
|
2137
|
+
case 'amd':
|
2138
|
+
return "require('" + name + "')(" + context + ")";
|
2139
|
+
case 'standalone':
|
2140
|
+
if (typeof browser !== "undefined" && browser !== null ? browser.process : void 0) {
|
2141
|
+
throw new Error("Include directive not available in the Browser when placement is standalone.");
|
2142
|
+
} else {
|
2143
|
+
try {
|
2144
|
+
source = fs.readFileSync(name).toString();
|
2145
|
+
} catch (_error) {
|
2146
|
+
error = _error;
|
2147
|
+
console.error(" Error opening file: %s", error);
|
2148
|
+
console.error(error);
|
2149
|
+
}
|
2150
|
+
Compiler = require('../haml-coffee');
|
2151
|
+
compiler = new Compiler(this.options);
|
2152
|
+
compiler.parse(source);
|
2153
|
+
code = CoffeeScript.compile(compiler.precompile(), {
|
2154
|
+
bare: true
|
2155
|
+
});
|
2156
|
+
return statement = "`(function(){" + code + "}).apply(" + context + ")`";
|
2157
|
+
}
|
2158
|
+
break;
|
2159
|
+
default:
|
2160
|
+
throw new Error("Include directive not available when placement is " + this.placement);
|
2161
|
+
}
|
2162
|
+
}).call(this);
|
2163
|
+
return this.opener = this.markInsertingCode(statement, false);
|
2164
|
+
}
|
2165
|
+
};
|
2166
|
+
|
2167
|
+
Directive.prototype.evaluate = function() {
|
2168
|
+
var directives, e, name, rest, _ref1;
|
2169
|
+
directives = Object.keys(this.directives).join('|');
|
2170
|
+
try {
|
2171
|
+
_ref1 = this.expression.match(RegExp("\\+(" + directives + ")(.*)")), _ref1[0], name = _ref1[1], rest = _ref1[2];
|
2172
|
+
} catch (_error) {
|
2173
|
+
e = _error;
|
2174
|
+
throw new Error("Unable to recognize directive from " + this.expression);
|
2175
|
+
}
|
2176
|
+
return this.directives[name].call(this, rest);
|
2177
|
+
};
|
2178
|
+
|
2179
|
+
return Directive;
|
2180
|
+
|
2181
|
+
})(Node);
|
2182
|
+
|
2183
|
+
}).call(this);
|
2184
|
+
|
2185
|
+
});
|
2186
|
+
|
2187
|
+
require.define("fs",function(require,module,exports,__dirname,__filename,process,global){// nothing to see here... no file methods for the browser
|
2188
|
+
|
2189
|
+
});
|
2190
|
+
|
2191
|
+
require.define("/hamlc.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
|
2192
|
+
var CoffeeScript, Compiler, fs, __expressCache;
|
2193
|
+
|
2194
|
+
fs = require('fs');
|
2195
|
+
|
2196
|
+
Compiler = require('./haml-coffee');
|
2197
|
+
|
2198
|
+
if (process.browser) {
|
2199
|
+
CoffeeScript = window.CoffeeScript;
|
2200
|
+
} else {
|
2201
|
+
CoffeeScript = require('coffee-script');
|
2202
|
+
}
|
2203
|
+
|
2204
|
+
__expressCache = {};
|
2205
|
+
|
2206
|
+
module.exports = {
|
2207
|
+
render: function(source, context, options) {
|
2208
|
+
var compiler, template;
|
2209
|
+
if (context == null) {
|
2210
|
+
context = {};
|
2211
|
+
}
|
2212
|
+
if (options == null) {
|
2213
|
+
options = {};
|
2214
|
+
}
|
2215
|
+
options.placement = 'standalone';
|
2216
|
+
compiler = new Compiler(options);
|
2217
|
+
compiler.parse(source);
|
2218
|
+
template = new Function(CoffeeScript.compile(compiler.precompile(), {
|
2219
|
+
bare: true
|
2220
|
+
}));
|
2221
|
+
return template.call(context);
|
2222
|
+
},
|
2223
|
+
compile: function(source, options) {
|
2224
|
+
var compiler, template;
|
2225
|
+
if (options == null) {
|
2226
|
+
options = {};
|
2227
|
+
}
|
2228
|
+
compiler = new Compiler(options);
|
2229
|
+
compiler.parse(source);
|
2230
|
+
template = new Function(CoffeeScript.compile(compiler.precompile(), {
|
2231
|
+
bare: true
|
2232
|
+
}));
|
2233
|
+
return function(params) {
|
2234
|
+
return template.call(params);
|
2235
|
+
};
|
2236
|
+
},
|
2237
|
+
template: function(source, name, namespace, options) {
|
2238
|
+
var compiler;
|
2239
|
+
if (options == null) {
|
2240
|
+
options = {};
|
2241
|
+
}
|
2242
|
+
options.namespace = namespace;
|
2243
|
+
options.name = name;
|
2244
|
+
compiler = new Compiler(options);
|
2245
|
+
compiler.parse(source);
|
2246
|
+
return CoffeeScript.compile(compiler.render());
|
2247
|
+
},
|
2248
|
+
__express: function(filename, options, callback) {
|
2249
|
+
var err, source;
|
2250
|
+
if (!!(options && options.constructor && options.call && options.apply)) {
|
2251
|
+
callback = options;
|
2252
|
+
options = {};
|
2253
|
+
}
|
2254
|
+
try {
|
2255
|
+
if (options.cache && __expressCache[filename]) {
|
2256
|
+
return callback(null, __expressCache[filename](options));
|
2257
|
+
} else {
|
2258
|
+
options.filename = filename;
|
2259
|
+
source = fs.readFileSync(filename, 'utf8');
|
2260
|
+
if (options.cache) {
|
2261
|
+
__expressCache[filename] = module.exports.compile(source, options);
|
2262
|
+
return callback(null, __expressCache[filename](options));
|
2263
|
+
} else {
|
2264
|
+
return callback(null, module.exports.compile(source, options)(options));
|
2265
|
+
}
|
2266
|
+
}
|
2267
|
+
} catch (_error) {
|
2268
|
+
err = _error;
|
2269
|
+
return callback(err);
|
2270
|
+
}
|
2271
|
+
}
|
2272
|
+
};
|
2273
|
+
|
2274
|
+
}).call(this);
|
2275
|
+
|
2276
|
+
});
|