guard-haml-coffee 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-haml-coffee.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Michael Witrant
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Guard::Haml::Coffee
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'guard-haml-coffee'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install guard-haml-coffee
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/guard/haml-coffee/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ouvrages"]
6
+ gem.email = ["contact@ouvrages-web.fr"]
7
+ gem.description = %q{Compiles a HamlCoffee .js.hamlc file to a .js javascript template}
8
+ gem.summary = %q{Guard gem for HamlCoffee}
9
+ gem.homepage = "https://github.com/ouvrages/guard-haml-coffee"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "guard-haml-coffee"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Guard::Haml::Coffee::VERSION
17
+
18
+ gem.add_dependency('guard')
19
+ gem.add_dependency('execjs')
20
+ gem.add_dependency('coffee-script')
21
+ end
@@ -0,0 +1,2 @@
1
+ require 'guard/haml-coffee/version'
2
+ require 'guard/haml-coffee'
@@ -0,0 +1,63 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'guard'
3
+ require 'guard/guard'
4
+ require 'guard/watcher'
5
+ require 'execjs'
6
+ require 'coffee-script'
7
+
8
+ module Guard
9
+ class HamlCoffee < Guard
10
+
11
+ def initialize(watchers=[], options={})
12
+ super
13
+ end
14
+
15
+ def start
16
+ ::Guard::UI.info("Guard::HamlCoffee has started watching your files",{})
17
+ source = File.read(::CoffeeScript::Source.path) + ";"
18
+ source += File.read(File.expand_path('../haml-coffee/hamlcoffee.js', __FILE__)) + ";"
19
+ source += File.read(File.expand_path('../haml-coffee/hamlcoffee_compiler.js', __FILE__))
20
+ @runtime = ExecJS.compile(source)
21
+ end
22
+
23
+ def run_all
24
+ run_on_changes(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
25
+ end
26
+
27
+ def run_on_changes(paths)
28
+ paths.each do |path|
29
+ basename = File.basename(path, '.js.hamlc')
30
+ output_file = File.join(File.dirname(path), basename + ".js")
31
+ options = [
32
+ basename,
33
+ File.read(path),
34
+ jst = true,
35
+ namespace = nil,
36
+ format = nil,
37
+ uglify = false,
38
+ basename,
39
+ escapeHtml = nil,
40
+ escapeAttributes = nil,
41
+ cleanValue = nil,
42
+ customHtmlEscape = nil,
43
+ customCleanValue = nil,
44
+ customPreserve = nil,
45
+ customFindAndPreserve = nil,
46
+ customSurround = nil,
47
+ customSucceed = nil,
48
+ customPrecede = nil,
49
+ preserveTags = nil,
50
+ selfCloseTags = nil,
51
+ context = false,
52
+ extendScope = nil,
53
+ ]
54
+ output = @runtime.call('HamlCoffeeCompiler.compile', *options)
55
+ File.open(output_file, "w") { |f| f.write output }
56
+ ::Guard::UI.info "# compiled haml coffee in '#{path}' to js in '#{output_file}'"
57
+ end
58
+ rescue StandardError => error
59
+ ::Guard::UI.error "Guard Haml Coffee Error: " + error.message
60
+ throw :task_has_failed
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,1763 @@
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 res = mod._cached ? mod._cached : mod();
8
+ return res;
9
+ }
10
+
11
+ require.paths = [];
12
+ require.modules = {};
13
+ require.extensions = [".js",".coffee"];
14
+
15
+ require._core = {
16
+ 'assert': true,
17
+ 'events': true,
18
+ 'fs': true,
19
+ 'path': true,
20
+ 'vm': true
21
+ };
22
+
23
+ require.resolve = (function () {
24
+ return function (x, cwd) {
25
+ if (!cwd) cwd = '/';
26
+
27
+ if (require._core[x]) return x;
28
+ var path = require.modules.path();
29
+ cwd = path.resolve('/', cwd);
30
+ var y = cwd || '/';
31
+
32
+ if (x.match(/^(?:\.\.?\/|\/)/)) {
33
+ var m = loadAsFileSync(path.resolve(y, x))
34
+ || loadAsDirectorySync(path.resolve(y, x));
35
+ if (m) return m;
36
+ }
37
+
38
+ var n = loadNodeModulesSync(x, y);
39
+ if (n) return n;
40
+
41
+ throw new Error("Cannot find module '" + x + "'");
42
+
43
+ function loadAsFileSync (x) {
44
+ if (require.modules[x]) {
45
+ return x;
46
+ }
47
+
48
+ for (var i = 0; i < require.extensions.length; i++) {
49
+ var ext = require.extensions[i];
50
+ if (require.modules[x + ext]) return x + ext;
51
+ }
52
+ }
53
+
54
+ function loadAsDirectorySync (x) {
55
+ x = x.replace(/\/+$/, '');
56
+ var pkgfile = x + '/package.json';
57
+ if (require.modules[pkgfile]) {
58
+ var pkg = require.modules[pkgfile]();
59
+ var b = pkg.browserify;
60
+ if (typeof b === 'object' && b.main) {
61
+ var m = loadAsFileSync(path.resolve(x, b.main));
62
+ if (m) return m;
63
+ }
64
+ else if (typeof b === 'string') {
65
+ var m = loadAsFileSync(path.resolve(x, b));
66
+ if (m) return m;
67
+ }
68
+ else if (pkg.main) {
69
+ var m = loadAsFileSync(path.resolve(x, pkg.main));
70
+ if (m) return m;
71
+ }
72
+ }
73
+
74
+ return loadAsFileSync(x + '/index');
75
+ }
76
+
77
+ function loadNodeModulesSync (x, start) {
78
+ var dirs = nodeModulesPathsSync(start);
79
+ for (var i = 0; i < dirs.length; i++) {
80
+ var dir = dirs[i];
81
+ var m = loadAsFileSync(dir + '/' + x);
82
+ if (m) return m;
83
+ var n = loadAsDirectorySync(dir + '/' + x);
84
+ if (n) return n;
85
+ }
86
+
87
+ var m = loadAsFileSync(x);
88
+ if (m) return m;
89
+ }
90
+
91
+ function nodeModulesPathsSync (start) {
92
+ var parts;
93
+ if (start === '/') parts = [ '' ];
94
+ else parts = path.normalize(start).split('/');
95
+
96
+ var dirs = [];
97
+ for (var i = parts.length - 1; i >= 0; i--) {
98
+ if (parts[i] === 'node_modules') continue;
99
+ var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
100
+ dirs.push(dir);
101
+ }
102
+
103
+ return dirs;
104
+ }
105
+ };
106
+ })();
107
+
108
+ require.alias = function (from, to) {
109
+ var path = require.modules.path();
110
+ var res = null;
111
+ try {
112
+ res = require.resolve(from + '/package.json', '/');
113
+ }
114
+ catch (err) {
115
+ res = require.resolve(from, '/');
116
+ }
117
+ var basedir = path.dirname(res);
118
+
119
+ var keys = (Object.keys || function (obj) {
120
+ var res = [];
121
+ for (var key in obj) res.push(key)
122
+ return res;
123
+ })(require.modules);
124
+
125
+ for (var i = 0; i < keys.length; i++) {
126
+ var key = keys[i];
127
+ if (key.slice(0, basedir.length + 1) === basedir + '/') {
128
+ var f = key.slice(basedir.length);
129
+ require.modules[to + f] = require.modules[basedir + f];
130
+ }
131
+ else if (key === basedir) {
132
+ require.modules[to] = require.modules[basedir];
133
+ }
134
+ }
135
+ };
136
+
137
+ require.define = function (filename, fn) {
138
+ var dirname = require._core[filename]
139
+ ? ''
140
+ : require.modules.path().dirname(filename)
141
+ ;
142
+
143
+ var require_ = function (file) {
144
+ return require(file, dirname)
145
+ };
146
+ require_.resolve = function (name) {
147
+ return require.resolve(name, dirname);
148
+ };
149
+ require_.modules = require.modules;
150
+ require_.define = require.define;
151
+ var module_ = { exports : {} };
152
+
153
+ require.modules[filename] = function () {
154
+ require.modules[filename]._cached = module_.exports;
155
+ fn.call(
156
+ module_.exports,
157
+ require_,
158
+ module_,
159
+ module_.exports,
160
+ dirname,
161
+ filename
162
+ );
163
+ require.modules[filename]._cached = module_.exports;
164
+ return module_.exports;
165
+ };
166
+ };
167
+
168
+ if (typeof process === 'undefined') process = {};
169
+
170
+ if (!process.nextTick) process.nextTick = (function () {
171
+ var queue = [];
172
+ var canPost = typeof window !== 'undefined'
173
+ && window.postMessage && window.addEventListener
174
+ ;
175
+
176
+ if (canPost) {
177
+ window.addEventListener('message', function (ev) {
178
+ if (ev.source === window && ev.data === 'browserify-tick') {
179
+ ev.stopPropagation();
180
+ if (queue.length > 0) {
181
+ var fn = queue.shift();
182
+ fn();
183
+ }
184
+ }
185
+ }, true);
186
+ }
187
+
188
+ return function (fn) {
189
+ if (canPost) {
190
+ queue.push(fn);
191
+ window.postMessage('browserify-tick', '*');
192
+ }
193
+ else setTimeout(fn, 0);
194
+ };
195
+ })();
196
+
197
+ if (!process.title) process.title = 'browser';
198
+
199
+ if (!process.binding) process.binding = function (name) {
200
+ if (name === 'evals') return require('vm')
201
+ else throw new Error('No such module')
202
+ };
203
+
204
+ if (!process.cwd) process.cwd = function () { return '.' };
205
+
206
+ require.define("path", function (require, module, exports, __dirname, __filename) {
207
+ function filter (xs, fn) {
208
+ var res = [];
209
+ for (var i = 0; i < xs.length; i++) {
210
+ if (fn(xs[i], i, xs)) res.push(xs[i]);
211
+ }
212
+ return res;
213
+ }
214
+
215
+ // resolves . and .. elements in a path array with directory names there
216
+ // must be no slashes, empty elements, or device names (c:\) in the array
217
+ // (so also no leading and trailing slashes - it does not distinguish
218
+ // relative and absolute paths)
219
+ function normalizeArray(parts, allowAboveRoot) {
220
+ // if the path tries to go above the root, `up` ends up > 0
221
+ var up = 0;
222
+ for (var i = parts.length; i >= 0; i--) {
223
+ var last = parts[i];
224
+ if (last == '.') {
225
+ parts.splice(i, 1);
226
+ } else if (last === '..') {
227
+ parts.splice(i, 1);
228
+ up++;
229
+ } else if (up) {
230
+ parts.splice(i, 1);
231
+ up--;
232
+ }
233
+ }
234
+
235
+ // if the path is allowed to go above the root, restore leading ..s
236
+ if (allowAboveRoot) {
237
+ for (; up--; up) {
238
+ parts.unshift('..');
239
+ }
240
+ }
241
+
242
+ return parts;
243
+ }
244
+
245
+ // Regex to split a filename into [*, dir, basename, ext]
246
+ // posix version
247
+ var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
248
+
249
+ // path.resolve([from ...], to)
250
+ // posix version
251
+ exports.resolve = function() {
252
+ var resolvedPath = '',
253
+ resolvedAbsolute = false;
254
+
255
+ for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
256
+ var path = (i >= 0)
257
+ ? arguments[i]
258
+ : process.cwd();
259
+
260
+ // Skip empty and invalid entries
261
+ if (typeof path !== 'string' || !path) {
262
+ continue;
263
+ }
264
+
265
+ resolvedPath = path + '/' + resolvedPath;
266
+ resolvedAbsolute = path.charAt(0) === '/';
267
+ }
268
+
269
+ // At this point the path should be resolved to a full absolute path, but
270
+ // handle relative paths to be safe (might happen when process.cwd() fails)
271
+
272
+ // Normalize the path
273
+ resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
274
+ return !!p;
275
+ }), !resolvedAbsolute).join('/');
276
+
277
+ return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
278
+ };
279
+
280
+ // path.normalize(path)
281
+ // posix version
282
+ exports.normalize = function(path) {
283
+ var isAbsolute = path.charAt(0) === '/',
284
+ trailingSlash = path.slice(-1) === '/';
285
+
286
+ // Normalize the path
287
+ path = normalizeArray(filter(path.split('/'), function(p) {
288
+ return !!p;
289
+ }), !isAbsolute).join('/');
290
+
291
+ if (!path && !isAbsolute) {
292
+ path = '.';
293
+ }
294
+ if (path && trailingSlash) {
295
+ path += '/';
296
+ }
297
+
298
+ return (isAbsolute ? '/' : '') + path;
299
+ };
300
+
301
+
302
+ // posix version
303
+ exports.join = function() {
304
+ var paths = Array.prototype.slice.call(arguments, 0);
305
+ return exports.normalize(filter(paths, function(p, index) {
306
+ return p && typeof p === 'string';
307
+ }).join('/'));
308
+ };
309
+
310
+
311
+ exports.dirname = function(path) {
312
+ var dir = splitPathRe.exec(path)[1] || '';
313
+ var isWindows = false;
314
+ if (!dir) {
315
+ // No dirname
316
+ return '.';
317
+ } else if (dir.length === 1 ||
318
+ (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
319
+ // It is just a slash or a drive letter with a slash
320
+ return dir;
321
+ } else {
322
+ // It is a full dirname, strip trailing slash
323
+ return dir.substring(0, dir.length - 1);
324
+ }
325
+ };
326
+
327
+
328
+ exports.basename = function(path, ext) {
329
+ var f = splitPathRe.exec(path)[2] || '';
330
+ // TODO: make this comparison case-insensitive on windows?
331
+ if (ext && f.substr(-1 * ext.length) === ext) {
332
+ f = f.substr(0, f.length - ext.length);
333
+ }
334
+ return f;
335
+ };
336
+
337
+
338
+ exports.extname = function(path) {
339
+ return splitPathRe.exec(path)[3] || '';
340
+ };
341
+
342
+ });
343
+
344
+ require.define("/haml-coffee.coffee", function (require, module, exports, __dirname, __filename) {
345
+ (function() {
346
+ var Code, Comment, Filter, Haml, HamlCoffee, Node, Text, indent, whitespace;
347
+
348
+ Node = require('./nodes/node');
349
+
350
+ Text = require('./nodes/text');
351
+
352
+ Haml = require('./nodes/haml');
353
+
354
+ Code = require('./nodes/code');
355
+
356
+ Comment = require('./nodes/comment');
357
+
358
+ Filter = require('./nodes/filter');
359
+
360
+ whitespace = require('./util/text').whitespace;
361
+
362
+ indent = require('./util/text').indent;
363
+
364
+ module.exports = HamlCoffee = (function() {
365
+
366
+ HamlCoffee.VERSION = '1.4.2';
367
+
368
+ function HamlCoffee(options) {
369
+ var _base, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
370
+ this.options = options != null ? options : {};
371
+ if ((_ref = (_base = this.options).escapeHtml) == null) {
372
+ _base.escapeHtml = true;
373
+ }
374
+ if ((_ref2 = (_base2 = this.options).escapeAttributes) == null) {
375
+ _base2.escapeAttributes = true;
376
+ }
377
+ if ((_ref3 = (_base3 = this.options).cleanValue) == null) {
378
+ _base3.cleanValue = true;
379
+ }
380
+ if ((_ref4 = (_base4 = this.options).uglify) == null) _base4.uglify = false;
381
+ if ((_ref5 = (_base5 = this.options).basename) == null) {
382
+ _base5.basename = false;
383
+ }
384
+ if ((_ref6 = (_base6 = this.options).extendScope) == null) {
385
+ _base6.extendScope = false;
386
+ }
387
+ if ((_ref7 = (_base7 = this.options).format) == null) {
388
+ _base7.format = 'html5';
389
+ }
390
+ if ((_ref8 = (_base8 = this.options).preserveTags) == null) {
391
+ _base8.preserveTags = 'pre,textarea';
392
+ }
393
+ if ((_ref9 = (_base9 = this.options).selfCloseTags) == null) {
394
+ _base9.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base';
395
+ }
396
+ }
397
+
398
+ HamlCoffee.prototype.indentChanged = function() {
399
+ return this.currentIndent !== this.previousIndent;
400
+ };
401
+
402
+ HamlCoffee.prototype.isIndent = function() {
403
+ return this.currentIndent > this.previousIndent;
404
+ };
405
+
406
+ HamlCoffee.prototype.updateTabSize = function() {
407
+ if (this.tabSize === 0) {
408
+ return this.tabSize = this.currentIndent - this.previousIndent;
409
+ }
410
+ };
411
+
412
+ HamlCoffee.prototype.updateBlockLevel = function() {
413
+ this.currentBlockLevel = this.currentIndent / this.tabSize;
414
+ if (this.currentBlockLevel - Math.floor(this.currentBlockLevel) > 0) {
415
+ throw "Indentation error in line " + this.lineNumber;
416
+ }
417
+ if ((this.currentIndent - this.previousIndent) / this.tabSize > 1) {
418
+ if (!this.node.isCommented()) {
419
+ throw "Block level too deep in line " + this.lineNumber;
420
+ }
421
+ }
422
+ return this.delta = this.previousBlockLevel - this.currentBlockLevel;
423
+ };
424
+
425
+ HamlCoffee.prototype.updateCodeBlockLevel = function(node) {
426
+ if (node instanceof Code) {
427
+ return this.currentCodeBlockLevel = node.codeBlockLevel + 1;
428
+ } else {
429
+ return this.currentCodeBlockLevel = node.codeBlockLevel;
430
+ }
431
+ };
432
+
433
+ HamlCoffee.prototype.updateParent = function() {
434
+ if (this.isIndent()) {
435
+ return this.pushParent();
436
+ } else {
437
+ return this.popParent();
438
+ }
439
+ };
440
+
441
+ HamlCoffee.prototype.pushParent = function() {
442
+ this.stack.push(this.parentNode);
443
+ return this.parentNode = this.node;
444
+ };
445
+
446
+ HamlCoffee.prototype.popParent = function() {
447
+ var i, _ref, _results;
448
+ _results = [];
449
+ for (i = 0, _ref = this.delta - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) {
450
+ _results.push(this.parentNode = this.stack.pop());
451
+ }
452
+ return _results;
453
+ };
454
+
455
+ HamlCoffee.prototype.getNodeOptions = function(override) {
456
+ if (override == null) override = {};
457
+ return {
458
+ parentNode: override.parentNode || this.parentNode,
459
+ blockLevel: override.blockLevel || this.currentBlockLevel,
460
+ codeBlockLevel: override.codeBlockLevel || this.currentCodeBlockLevel,
461
+ escapeHtml: override.escapeHtml || this.options.escapeHtml,
462
+ escapeAttributes: override.escapeAttributes || this.options.escapeAttributes,
463
+ cleanValue: override.cleanValue || this.options.cleanValue,
464
+ format: override.format || this.options.format,
465
+ preserveTags: override.preserveTags || this.options.preserveTags,
466
+ selfCloseTags: override.selfCloseTags || this.options.selfCloseTags,
467
+ uglify: override.uglify || this.options.uglify
468
+ };
469
+ };
470
+
471
+ HamlCoffee.prototype.nodeFactory = function(expression) {
472
+ var node, options, _ref;
473
+ if (expression == null) expression = '';
474
+ options = this.getNodeOptions();
475
+ if (expression.match(/^:(escaped|preserve|css|javascript|plain|cdata|coffeescript)/)) {
476
+ node = new Filter(expression, options);
477
+ } else if (expression.match(/^(\/|-#)(.*)/)) {
478
+ node = new Comment(expression, options);
479
+ } else if (expression.match(/^(-#|-|=|!=|\&=|~)\s*(.*)/)) {
480
+ node = new Code(expression, options);
481
+ } else if (expression.match(/^(%|#[^{]|\.|\!)(.*)/)) {
482
+ node = new Haml(expression, options);
483
+ } else {
484
+ node = new Text(expression, options);
485
+ }
486
+ if ((_ref = options.parentNode) != null) _ref.addChild(node);
487
+ return node;
488
+ };
489
+
490
+ HamlCoffee.prototype.parse = function(source) {
491
+ var attributes, expression, line, lines, result, text, ws, _ref;
492
+ if (source == null) source = '';
493
+ this.lineNumber = this.previousIndent = this.tabSize = this.currentBlockLevel = this.previousBlockLevel = 0;
494
+ this.currentCodeBlockLevel = this.previousCodeBlockLevel = 0;
495
+ this.node = null;
496
+ this.stack = [];
497
+ this.root = this.parentNode = new Node('', this.getNodeOptions());
498
+ lines = source.split("\n");
499
+ while ((line = lines.shift()) !== void 0) {
500
+ if ((this.node instanceof Filter) && !this.exitFilter) {
501
+ if (/^(\s)*$/.test(line)) {
502
+ this.node.addChild(new Text('', this.getNodeOptions({
503
+ parentNode: this.node
504
+ })));
505
+ } else {
506
+ result = line.match(/^(\s*)(.*)/);
507
+ ws = result[1];
508
+ expression = result[2];
509
+ if (this.node.blockLevel >= (ws.length / 2)) {
510
+ this.exitFilter = true;
511
+ lines.unshift(line);
512
+ continue;
513
+ }
514
+ text = line.match(RegExp("^\\s{" + ((this.node.blockLevel * 2) + 2) + "}(.*)"));
515
+ if (text) {
516
+ this.node.addChild(new Text(text[1], this.getNodeOptions({
517
+ parentNode: this.node
518
+ })));
519
+ }
520
+ }
521
+ } else {
522
+ this.exitFilter = false;
523
+ result = line.match(/^(\s*)(.*)/);
524
+ ws = result[1];
525
+ expression = result[2];
526
+ if (/^\s*$/.test(line)) continue;
527
+ while (/^[%.#].*[{(]/.test(expression) && !/^(\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])) {
528
+ attributes = lines.shift();
529
+ expression = expression.replace(/(\s)+\|\s*$/, '');
530
+ expression += ' ' + attributes.match(/^\s*(.*?)(\s+\|\s*)?$/)[1];
531
+ this.lineNumber++;
532
+ }
533
+ if (expression.match(/(\s)+\|\s*$/)) {
534
+ expression = expression.replace(/(\s)+\|\s*$/, ' ');
535
+ while ((_ref = lines[0]) != null ? _ref.match(/(\s)+\|$/) : void 0) {
536
+ expression += lines.shift().match(/^(\s*)(.*)/)[2].replace(/(\s)+\|\s*$/, '');
537
+ this.lineNumber++;
538
+ }
539
+ }
540
+ this.currentIndent = ws.length;
541
+ if (this.indentChanged()) {
542
+ this.updateTabSize();
543
+ this.updateBlockLevel();
544
+ this.updateParent();
545
+ this.updateCodeBlockLevel(this.parentNode);
546
+ }
547
+ this.node = this.nodeFactory(expression);
548
+ this.previousBlockLevel = this.currentBlockLevel;
549
+ this.previousIndent = this.currentIndent;
550
+ }
551
+ this.lineNumber++;
552
+ }
553
+ return this.evaluate(this.root);
554
+ };
555
+
556
+ HamlCoffee.prototype.evaluate = function(node) {
557
+ var child, _i, _len, _ref;
558
+ _ref = node.children;
559
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
560
+ child = _ref[_i];
561
+ this.evaluate(child);
562
+ }
563
+ return node.evaluate();
564
+ };
565
+
566
+ HamlCoffee.prototype.render = function(templateName, namespace) {
567
+ var segment, segments, template, _i, _len;
568
+ if (namespace == null) namespace = 'window.HAML';
569
+ template = '';
570
+ segments = ("" + namespace + "." + templateName).replace(/(\s|-)+/g, '_').split(/\./);
571
+ templateName = this.options.basename ? segments.pop().split(/\/|\\/).pop() : segments.pop();
572
+ namespace = segments.shift();
573
+ if (segments.length !== 0) {
574
+ for (_i = 0, _len = segments.length; _i < _len; _i++) {
575
+ segment = segments[_i];
576
+ namespace += "." + segment;
577
+ template += "" + namespace + " ?= {}\n";
578
+ }
579
+ } else {
580
+ template += "" + namespace + " ?= {}\n";
581
+ }
582
+ if (this.options.extendScope) {
583
+ template += "" + namespace + "['" + templateName + "'] = (context) -> ( ->\n";
584
+ template += " `with (context || {}) {`\n";
585
+ template += "" + (indent(this.precompile(), 1));
586
+ template += "`}`\n";
587
+ template += ").call(context)";
588
+ } else {
589
+ template += "" + namespace + "['" + templateName + "'] = (context) -> ( ->\n";
590
+ template += "" + (indent(this.precompile(), 1));
591
+ template += ").call(context)";
592
+ }
593
+ return template;
594
+ };
595
+
596
+ HamlCoffee.prototype.precompile = function() {
597
+ var code, fn;
598
+ fn = '';
599
+ code = this.createCode();
600
+ if (code.indexOf('$e') !== -1) {
601
+ if (this.options.customHtmlEscape) {
602
+ fn += "$e = " + this.options.customHtmlEscape + "\n";
603
+ } else {
604
+ fn += "$e = (text, escape) ->\n \"\#{ text }\"\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\'/g, '&#39;')\n .replace(/\"/g, '&quot;')\n";
605
+ }
606
+ }
607
+ if (code.indexOf('$c') !== -1) {
608
+ if (this.options.customCleanValue) {
609
+ fn += "$c = " + this.options.customCleanValue + "\n";
610
+ } else {
611
+ fn += "$c = (text) ->\n";
612
+ fn += " switch text\n";
613
+ fn += " when null, undefined then ''\n";
614
+ fn += " when true, false then '\u0093' + text\n";
615
+ fn += " else text\n";
616
+ }
617
+ }
618
+ if (code.indexOf('$p') !== -1 || code.indexOf('$fp') !== -1) {
619
+ if (this.options.customPreserve) {
620
+ fn += "$p = " + this.options.customPreserve + "\n";
621
+ } else {
622
+ fn += "$p = (text) -> text.replace /\\n/g, '&#x000A;'\n";
623
+ }
624
+ }
625
+ if (code.indexOf('$fp') !== -1) {
626
+ if (this.options.customFindAndPreserve) {
627
+ fn += "$fp = " + this.options.customFindAndPreserve + "\n";
628
+ } else {
629
+ fn += "$fp = (text) ->\n text.replace /<(" + (this.options.preserveTags.split(',').join('|')) + ")>([^]*?)<\\/\\1>/g, (str, tag, content) ->\n \"<\#{ tag }>\#{ $p content }</\#{ tag }>\"\n";
630
+ }
631
+ }
632
+ if (code.indexOf('surround') !== -1) {
633
+ if (this.options.customSurround) {
634
+ fn += "surround = " + this.options.customSurround + "\n";
635
+ } else {
636
+ fn += "surround = (start, end, fn) -> start + fn() + end\n";
637
+ }
638
+ }
639
+ if (code.indexOf('succeed') !== -1) {
640
+ if (this.options.customSucceed) {
641
+ fn += "succeed = " + this.options.customSucceed + "\n";
642
+ } else {
643
+ fn += "succeed = (end, fn) -> fn() + end\n";
644
+ }
645
+ }
646
+ if (code.indexOf('precede') !== -1) {
647
+ if (this.options.customPrecede) {
648
+ fn += "precede = " + this.options.customPrecede + "\n";
649
+ } else {
650
+ fn += "precede = (start, fn) -> start + fn()\n";
651
+ }
652
+ }
653
+ fn += "$o = []\n";
654
+ fn += "" + code + "\n";
655
+ return fn += "return $o.join(\"\\n\")" + (this.convertBooleans(code)) + (this.cleanupWhitespace(code)) + "\n";
656
+ };
657
+
658
+ HamlCoffee.prototype.createCode = function() {
659
+ var child, code, line, processors, _i, _j, _len, _len2, _ref, _ref2;
660
+ code = [];
661
+ this.lines = [];
662
+ _ref = this.root.children;
663
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
664
+ child = _ref[_i];
665
+ this.lines = this.lines.concat(child.render());
666
+ }
667
+ this.lines = this.combineText(this.lines);
668
+ this.blockLevel = 0;
669
+ _ref2 = this.lines;
670
+ for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
671
+ line = _ref2[_j];
672
+ if (line !== null) {
673
+ switch (line.type) {
674
+ case 'text':
675
+ code.push("" + (whitespace(line.cw)) + (this.getBuffer(this.blockLevel)) + ".push \"" + (whitespace(line.hw)) + line.text + "\"");
676
+ break;
677
+ case 'run':
678
+ if (line.block !== 'end') {
679
+ code.push("" + (whitespace(line.cw)) + line.code);
680
+ } else {
681
+ code.push("" + (whitespace(line.cw)) + (line.code.replace('$buffer', this.getBuffer(this.blockLevel))));
682
+ this.blockLevel -= 1;
683
+ }
684
+ break;
685
+ case 'insert':
686
+ processors = '';
687
+ if (line.findAndPreserve) processors += '$fp ';
688
+ if (line.preserve) processors += '$p ';
689
+ if (line.escape) processors += '$e ';
690
+ if (this.options.cleanValue) processors += '$c ';
691
+ code.push("" + (whitespace(line.cw)) + (this.getBuffer(this.blockLevel)) + ".push \"" + (whitespace(line.hw)) + "\" + " + processors + line.code);
692
+ if (line.block === 'start') {
693
+ this.blockLevel += 1;
694
+ code.push("" + (whitespace(line.cw + 1)) + (this.getBuffer(this.blockLevel)) + " = []");
695
+ }
696
+ }
697
+ }
698
+ }
699
+ return code.join('\n');
700
+ };
701
+
702
+ HamlCoffee.prototype.getBuffer = function(level) {
703
+ if (level > 0) {
704
+ return "$o" + level;
705
+ } else {
706
+ return '$o';
707
+ }
708
+ };
709
+
710
+ HamlCoffee.prototype.combineText = function(lines) {
711
+ var combined, line, nextLine;
712
+ combined = [];
713
+ while ((line = lines.shift()) !== void 0) {
714
+ if (line.type === 'text') {
715
+ while (lines[0] && lines[0].type === 'text' && line.cw === lines[0].cw) {
716
+ nextLine = lines.shift();
717
+ line.text += "\\n" + (whitespace(nextLine.hw)) + nextLine.text;
718
+ }
719
+ }
720
+ combined.push(line);
721
+ }
722
+ return combined;
723
+ };
724
+
725
+ HamlCoffee.prototype.convertBooleans = function(code) {
726
+ if (this.options.format === 'xhtml') {
727
+ return '.replace(/\\s(\\w+)=\'\u0093true\'/mg, " $1=\'$1\'").replace(/\\s(\\w+)=\'\u0093false\'/mg, \'\')';
728
+ } else {
729
+ return '.replace(/\\s(\\w+)=\'\u0093true\'/mg, \' $1\').replace(/\\s(\\w+)=\'\u0093false\'/mg, \'\')';
730
+ }
731
+ };
732
+
733
+ HamlCoffee.prototype.cleanupWhitespace = function(code) {
734
+ if (/\u0091|\u0092/.test(code)) {
735
+ return ".replace(/[\\s\\n]*\\u0091/mg, '').replace(/\\u0092[\\s\\n]*/mg, '')";
736
+ } else {
737
+ return '';
738
+ }
739
+ };
740
+
741
+ return HamlCoffee;
742
+
743
+ })();
744
+
745
+ }).call(this);
746
+
747
+ });
748
+
749
+ require.define("/nodes/node.coffee", function (require, module, exports, __dirname, __filename) {
750
+ (function() {
751
+ var Node, escapeHTML;
752
+
753
+ escapeHTML = require('../util/text').escapeHTML;
754
+
755
+ module.exports = Node = (function() {
756
+
757
+ Node.CLEAR_WHITESPACE_LEFT = '\u0091';
758
+
759
+ Node.CLEAR_WHITESPACE_RIGHT = '\u0092';
760
+
761
+ function Node(expression, options) {
762
+ this.expression = expression != null ? expression : '';
763
+ if (options == null) options = {};
764
+ this.parentNode = options.parentNode;
765
+ this.children = [];
766
+ this.opener = this.closer = null;
767
+ this.silent = false;
768
+ this.preserveTags = options.preserveTags.split(',');
769
+ this.preserve = false;
770
+ this.wsRemoval = {
771
+ around: false,
772
+ inside: false
773
+ };
774
+ this.escapeHtml = options.escapeHtml;
775
+ this.escapeAttributes = options.escapeAttributes;
776
+ this.cleanValue = options.cleanValue;
777
+ this.format = options.format;
778
+ this.selfCloseTags = options.selfCloseTags.split(',');
779
+ this.uglify = options.uglify;
780
+ this.codeBlockLevel = options.codeBlockLevel;
781
+ this.blockLevel = options.blockLevel;
782
+ }
783
+
784
+ Node.prototype.addChild = function(child) {
785
+ this.children.push(child);
786
+ return this;
787
+ };
788
+
789
+ Node.prototype.getOpener = function() {
790
+ if (this.wsRemoval.around && this.opener.text) {
791
+ this.opener.text = Node.CLEAR_WHITESPACE_LEFT + this.opener.text;
792
+ }
793
+ if (this.wsRemoval.inside && this.opener.text) {
794
+ this.opener.text += Node.CLEAR_WHITESPACE_RIGHT;
795
+ }
796
+ return this.opener;
797
+ };
798
+
799
+ Node.prototype.getCloser = function() {
800
+ if (this.wsRemoval.inside && this.closer.text) {
801
+ this.closer.text = Node.CLEAR_WHITESPACE_LEFT + this.closer.text;
802
+ }
803
+ if (this.wsRemoval.around && this.closer.text) {
804
+ this.closer.text += Node.CLEAR_WHITESPACE_RIGHT;
805
+ }
806
+ return this.closer;
807
+ };
808
+
809
+ Node.prototype.isPreserved = function() {
810
+ if (this.preserve) return true;
811
+ if (this.parentNode) {
812
+ return this.parentNode.isPreserved();
813
+ } else {
814
+ return false;
815
+ }
816
+ };
817
+
818
+ Node.prototype.isCommented = function() {
819
+ if (this.constructor.name === 'Comment') return true;
820
+ if (this.parentNode) {
821
+ return this.parentNode.isCommented();
822
+ } else {
823
+ return false;
824
+ }
825
+ };
826
+
827
+ Node.prototype.markText = function(text, escape) {
828
+ if (escape == null) escape = false;
829
+ return {
830
+ type: 'text',
831
+ cw: this.codeBlockLevel,
832
+ hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel,
833
+ text: escape ? escapeHTML(text) : text
834
+ };
835
+ };
836
+
837
+ Node.prototype.markRunningCode = function(code) {
838
+ return {
839
+ type: 'run',
840
+ cw: this.codeBlockLevel,
841
+ code: code
842
+ };
843
+ };
844
+
845
+ Node.prototype.markInsertingCode = function(code, escape, preserve, findAndPreserve) {
846
+ if (escape == null) escape = false;
847
+ if (preserve == null) preserve = false;
848
+ if (findAndPreserve == null) findAndPreserve = false;
849
+ return {
850
+ type: 'insert',
851
+ cw: this.codeBlockLevel,
852
+ hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel,
853
+ escape: escape,
854
+ preserve: preserve,
855
+ findAndPreserve: findAndPreserve,
856
+ code: code
857
+ };
858
+ };
859
+
860
+ Node.prototype.evaluate = function() {};
861
+
862
+ Node.prototype.render = function() {
863
+ var child, output, rendered, tag, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _m, _ref, _ref2, _ref3, _ref4, _ref5;
864
+ output = [];
865
+ if (this.silent) return output;
866
+ if (this.children.length === 0) {
867
+ if (this.opener && this.closer) {
868
+ tag = this.getOpener();
869
+ tag.text += this.getCloser().text;
870
+ output.push(tag);
871
+ } else {
872
+ if (!this.preserve && this.isPreserved()) {
873
+ output.push(this.getOpener());
874
+ } else {
875
+ output.push(this.getOpener());
876
+ }
877
+ }
878
+ } else {
879
+ if (this.opener && this.closer) {
880
+ if (this.preserve) {
881
+ this.wsRemoval.inside = true;
882
+ output.push(this.getOpener());
883
+ _ref = this.children;
884
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
885
+ child = _ref[_i];
886
+ _ref2 = child.render();
887
+ for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
888
+ rendered = _ref2[_j];
889
+ rendered.hw = this.blockLevel;
890
+ output.push(rendered);
891
+ }
892
+ }
893
+ output.push(this.getCloser());
894
+ } else {
895
+ output.push(this.getOpener());
896
+ _ref3 = this.children;
897
+ for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
898
+ child = _ref3[_k];
899
+ output = output.concat(child.render());
900
+ }
901
+ output.push(this.getCloser());
902
+ }
903
+ } else if (this.opener) {
904
+ output.push(this.getOpener());
905
+ _ref4 = this.children;
906
+ for (_l = 0, _len4 = _ref4.length; _l < _len4; _l++) {
907
+ child = _ref4[_l];
908
+ output = output.concat(child.render());
909
+ }
910
+ } else {
911
+ _ref5 = this.children;
912
+ for (_m = 0, _len5 = _ref5.length; _m < _len5; _m++) {
913
+ child = _ref5[_m];
914
+ output.push(this.markText(child.render().text));
915
+ }
916
+ }
917
+ }
918
+ return output;
919
+ };
920
+
921
+ return Node;
922
+
923
+ })();
924
+
925
+ }).call(this);
926
+
927
+ });
928
+
929
+ require.define("/util/text.coffee", function (require, module, exports, __dirname, __filename) {
930
+
931
+ module.exports = {
932
+ whitespace: function(n) {
933
+ var a;
934
+ n = n * 2;
935
+ a = [];
936
+ while (a.length < n) {
937
+ a.push(' ');
938
+ }
939
+ return a.join('');
940
+ },
941
+ escapeQuotes: function(text) {
942
+ if (!text) return '';
943
+ return text.replace(/"/g, '\\"').replace(/\\\\\"/g, '\\"');
944
+ },
945
+ unescapeQuotes: function(text) {
946
+ if (!text) return '';
947
+ return text.replace(/\\"/g, '"');
948
+ },
949
+ escapeHTML: function(text) {
950
+ if (!text) return '';
951
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;');
952
+ },
953
+ preserve: function(code) {
954
+ if (code) {
955
+ return code.replace(/<(pre|textarea)>(.*?)<\/\1>/g, function(text) {
956
+ return text.replace('\\n', '\&\#x000A;');
957
+ });
958
+ }
959
+ },
960
+ indent: function(text, spaces) {
961
+ return text.replace(/^(.*)$/mg, module.exports.whitespace(spaces) + '$1');
962
+ }
963
+ };
964
+
965
+ });
966
+
967
+ require.define("/nodes/text.coffee", function (require, module, exports, __dirname, __filename) {
968
+ (function() {
969
+ var Node, Text, escapeQuotes;
970
+ var __hasProp = Object.prototype.hasOwnProperty, __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; };
971
+
972
+ Node = require('./node');
973
+
974
+ escapeQuotes = require('../util/text').escapeQuotes;
975
+
976
+ module.exports = Text = (function() {
977
+
978
+ __extends(Text, Node);
979
+
980
+ function Text() {
981
+ Text.__super__.constructor.apply(this, arguments);
982
+ }
983
+
984
+ Text.prototype.evaluate = function() {
985
+ return this.opener = this.markText(escapeQuotes(this.expression));
986
+ };
987
+
988
+ return Text;
989
+
990
+ })();
991
+
992
+ }).call(this);
993
+
994
+ });
995
+
996
+ require.define("/nodes/haml.coffee", function (require, module, exports, __dirname, __filename) {
997
+ (function() {
998
+ var Haml, Node, escapeQuotes;
999
+ var __hasProp = Object.prototype.hasOwnProperty, __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; };
1000
+
1001
+ Node = require('./node');
1002
+
1003
+ escapeQuotes = require('../util/text').escapeQuotes;
1004
+
1005
+ module.exports = Haml = (function() {
1006
+
1007
+ __extends(Haml, Node);
1008
+
1009
+ function Haml() {
1010
+ Haml.__super__.constructor.apply(this, arguments);
1011
+ }
1012
+
1013
+ Haml.prototype.evaluate = function() {
1014
+ var assignment, code, identifier, match, prefix, tokens;
1015
+ tokens = this.parseExpression(this.expression);
1016
+ if (tokens.doctype) {
1017
+ return this.opener = this.markText("" + (escapeQuotes(this.buildDocType(tokens.doctype))));
1018
+ } else {
1019
+ if (this.isNotSelfClosing(tokens.tag)) {
1020
+ prefix = this.buildHtmlTagPrefix(tokens);
1021
+ if (tokens.assignment) {
1022
+ match = tokens.assignment.match(/^(=|!=|&=|~)\s*(.*)$/);
1023
+ identifier = match[1];
1024
+ assignment = match[2];
1025
+ if (identifier === '~') {
1026
+ code = "\#{$fp " + assignment + " }";
1027
+ } else if (identifier === '&=' || (identifier === '=' && this.escapeHtml)) {
1028
+ if (this.preserve) {
1029
+ if (this.cleanValue) {
1030
+ code = "\#{ $p($e($c(" + assignment + "))) }";
1031
+ } else {
1032
+ code = "\#{ $p($e(" + assignment + ")) }";
1033
+ }
1034
+ } else {
1035
+ if (this.cleanValue) {
1036
+ code = "\#{ $e($c(" + assignment + ")) }";
1037
+ } else {
1038
+ code = "\#{ $e(" + assignment + ") }";
1039
+ }
1040
+ }
1041
+ } else if (identifier === '!=' || (identifier === '=' && !this.escapeHtml)) {
1042
+ if (this.preserve) {
1043
+ if (this.cleanValue) {
1044
+ code = "\#{ $p($c(" + assignment + ")) }";
1045
+ } else {
1046
+ code = "\#{ $p(" + assignment + ") }";
1047
+ }
1048
+ } else {
1049
+ if (this.cleanValue) {
1050
+ code = "\#{ $c(" + assignment + ") }";
1051
+ } else {
1052
+ code = "\#{ " + assignment + " }";
1053
+ }
1054
+ }
1055
+ }
1056
+ this.opener = this.markText("" + prefix + ">" + code);
1057
+ return this.closer = this.markText("</" + tokens.tag + ">");
1058
+ } else if (tokens.text) {
1059
+ this.opener = this.markText("" + prefix + ">" + tokens.text);
1060
+ return this.closer = this.markText("</" + tokens.tag + ">");
1061
+ } else {
1062
+ this.opener = this.markText(prefix + '>');
1063
+ return this.closer = this.markText("</" + tokens.tag + ">");
1064
+ }
1065
+ } else {
1066
+ tokens.tag = tokens.tag.replace(/\/$/, '');
1067
+ prefix = this.buildHtmlTagPrefix(tokens);
1068
+ return this.opener = this.markText("" + prefix + (this.format === 'xhtml' ? ' /' : '') + ">");
1069
+ }
1070
+ }
1071
+ };
1072
+
1073
+ Haml.prototype.parseExpression = function(exp) {
1074
+ var attributes, classes, id, key, tag, value, _ref, _ref2;
1075
+ tag = this.parseTag(exp);
1076
+ if (this.preserveTags.indexOf(tag.tag) !== -1) this.preserve = true;
1077
+ id = this.wrapCode((_ref = tag.ids) != null ? _ref.pop() : void 0, true);
1078
+ classes = tag.classes;
1079
+ attributes = {};
1080
+ if (tag.attributes) {
1081
+ _ref2 = tag.attributes;
1082
+ for (key in _ref2) {
1083
+ value = _ref2[key];
1084
+ if (key === 'id') {
1085
+ if (id) {
1086
+ id += '_' + this.wrapCode(value, true);
1087
+ } else {
1088
+ id = this.wrapCode(value, true);
1089
+ }
1090
+ } else if (key === 'class') {
1091
+ classes || (classes = []);
1092
+ classes.push(value);
1093
+ } else {
1094
+ attributes[key] = value;
1095
+ }
1096
+ }
1097
+ }
1098
+ return {
1099
+ doctype: tag.doctype,
1100
+ tag: tag.tag,
1101
+ id: id,
1102
+ classes: classes,
1103
+ text: escapeQuotes(tag.text),
1104
+ attributes: attributes,
1105
+ assignment: tag.assignment
1106
+ };
1107
+ };
1108
+
1109
+ Haml.prototype.parseTag = function(exp) {
1110
+ var assignment, attributes, ch, classes, doctype, end, haml, id, ids, klass, level, pos, rest, start, tag, text, whitespace, _ref, _ref2, _ref3;
1111
+ try {
1112
+ doctype = (_ref = exp.match(/^(\!{3}.*)/)) != null ? _ref[1] : void 0;
1113
+ if (doctype) {
1114
+ return {
1115
+ doctype: doctype
1116
+ };
1117
+ }
1118
+ haml = exp.match(/^((?:[#%\.][a-z0-9_:\-]*[\/]?)+)/i)[0];
1119
+ rest = exp.substring(haml.length);
1120
+ if (rest.match(/^[{(]/)) {
1121
+ start = rest[0];
1122
+ end = (function() {
1123
+ switch (start) {
1124
+ case '{':
1125
+ return '}';
1126
+ case '(':
1127
+ return ')';
1128
+ }
1129
+ })();
1130
+ level = 0;
1131
+ for (pos = 0, _ref2 = rest.length; 0 <= _ref2 ? pos <= _ref2 : pos >= _ref2; 0 <= _ref2 ? pos++ : pos--) {
1132
+ ch = rest[pos];
1133
+ if (ch === start) level += 1;
1134
+ if (ch === end) {
1135
+ if (level === 1) {
1136
+ break;
1137
+ } else {
1138
+ level -= 1;
1139
+ }
1140
+ }
1141
+ }
1142
+ attributes = rest.substring(0, pos + 1);
1143
+ assignment = rest.substring(pos + 1);
1144
+ } else {
1145
+ attributes = '';
1146
+ assignment = rest;
1147
+ }
1148
+ if (whitespace = (_ref3 = assignment.match(/^[<>]{0,2}/)) != null ? _ref3[0] : void 0) {
1149
+ assignment = assignment.substring(whitespace.length);
1150
+ }
1151
+ if (assignment[0] === ' ') assignment = assignment.substring(1);
1152
+ if (assignment && !assignment.match(/^(=|!=|&=|~)/)) {
1153
+ text = assignment.replace(/^ /, '');
1154
+ assignment = void 0;
1155
+ }
1156
+ if (whitespace) {
1157
+ if (whitespace.indexOf('>') !== -1) this.wsRemoval.around = true;
1158
+ if (whitespace.indexOf('<') !== -1) {
1159
+ this.wsRemoval.inside = true;
1160
+ this.preserve = true;
1161
+ }
1162
+ }
1163
+ tag = haml.match(/\%([a-z_\-][a-z0-9_:\-]*[\/]?)/i);
1164
+ ids = haml.match(/\#([a-z_\-][a-z0-9_\-]*)/gi);
1165
+ classes = haml.match(/\.([a-z0-9_\-]*)/gi);
1166
+ return {
1167
+ tag: tag ? tag[1] : 'div',
1168
+ ids: ids ? (function() {
1169
+ var _i, _len, _results;
1170
+ _results = [];
1171
+ for (_i = 0, _len = ids.length; _i < _len; _i++) {
1172
+ id = ids[_i];
1173
+ _results.push("'" + (id.substr(1)) + "'");
1174
+ }
1175
+ return _results;
1176
+ })() : void 0,
1177
+ classes: classes ? (function() {
1178
+ var _i, _len, _results;
1179
+ _results = [];
1180
+ for (_i = 0, _len = classes.length; _i < _len; _i++) {
1181
+ klass = classes[_i];
1182
+ _results.push("'" + (klass.substr(1)) + "'");
1183
+ }
1184
+ return _results;
1185
+ })() : void 0,
1186
+ attributes: this.parseAttributes(attributes),
1187
+ assignment: assignment,
1188
+ text: text
1189
+ };
1190
+ } catch (error) {
1191
+ throw "Unable to parse tag from " + exp + ": " + error;
1192
+ }
1193
+ };
1194
+
1195
+ Haml.prototype.parseAttributes = function(exp) {
1196
+ var attributes, ch, endPos, hasDataAttribute, inDataAttribute, key, keyValue, keys, level, marker, markers, pairs, pos, quoted, start, startPos, type, value, _i, _len, _ref, _ref2, _ref3;
1197
+ attributes = {};
1198
+ if (exp === void 0) return attributes;
1199
+ type = exp.substring(0, 1);
1200
+ exp = exp.replace(/(=|:|=>)\s*('([^\\']|\\\\|\\')*'|"([^\\"]|\\\\|\\")*")/g, function(match, type, value) {
1201
+ return type + (value != null ? value.replace(/(:|=|=>)/g, '\u0090$1') : void 0);
1202
+ });
1203
+ level = 0;
1204
+ start = 0;
1205
+ markers = [];
1206
+ if (type === '(') {
1207
+ startPos = 1;
1208
+ endPos = exp.length - 1;
1209
+ } else {
1210
+ startPos = 0;
1211
+ endPos = exp.length;
1212
+ }
1213
+ for (pos = startPos; startPos <= endPos ? pos < endPos : pos > endPos; startPos <= endPos ? pos++ : pos--) {
1214
+ ch = exp[pos];
1215
+ if (ch === '(') {
1216
+ level += 1;
1217
+ start = pos;
1218
+ }
1219
+ if (ch === ')') {
1220
+ if (level === 1) {
1221
+ if (start !== 0 && pos - start !== 1) {
1222
+ markers.push({
1223
+ start: start,
1224
+ end: pos
1225
+ });
1226
+ }
1227
+ } else {
1228
+ level -= 1;
1229
+ }
1230
+ }
1231
+ }
1232
+ _ref = markers.reverse();
1233
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1234
+ marker = _ref[_i];
1235
+ exp = exp.substring(0, marker.start) + exp.substring(marker.start, marker.end).replace(/(:|=|=>)/g, '\u0090$1') + exp.substring(marker.end);
1236
+ }
1237
+ switch (type) {
1238
+ case '(':
1239
+ 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;
1240
+ break;
1241
+ case '{':
1242
+ 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;
1243
+ }
1244
+ pairs = exp.split(keys).filter(Boolean);
1245
+ inDataAttribute = false;
1246
+ hasDataAttribute = false;
1247
+ while (pairs.length) {
1248
+ keyValue = pairs.splice(0, 2);
1249
+ key = (_ref2 = keyValue[0]) != null ? _ref2.replace(/^\s+|\s+$/g, '').replace(/^:/, '') : void 0;
1250
+ if (quoted = key.match(/^("|')(.*)\1$/)) key = quoted[2];
1251
+ value = (_ref3 = keyValue[1]) != null ? _ref3.replace(/^\s+|[\s,]+$/g, '').replace(/\u0090/g, '') : void 0;
1252
+ if (key === 'data') {
1253
+ inDataAttribute = true;
1254
+ hasDataAttribute = true;
1255
+ } else if (key && value) {
1256
+ if (inDataAttribute) {
1257
+ key = "data-" + key;
1258
+ if (/}\s*$/.test(value)) inDataAttribute = false;
1259
+ }
1260
+ }
1261
+ switch (type) {
1262
+ case '(':
1263
+ attributes[key] = value.replace(/^\s+|[\s)]+$/g, '');
1264
+ break;
1265
+ case '{':
1266
+ attributes[key] = value.replace(/^\s+|[\s}]+$/g, '');
1267
+ }
1268
+ }
1269
+ if (hasDataAttribute) delete attributes['data'];
1270
+ return attributes;
1271
+ };
1272
+
1273
+ Haml.prototype.buildHtmlTagPrefix = function(tokens) {
1274
+ var classList, classes, hasDynamicClass, key, klass, name, tagParts, value, _i, _len, _ref;
1275
+ tagParts = ["<" + tokens.tag];
1276
+ if (tokens.classes) {
1277
+ hasDynamicClass = false;
1278
+ classList = (function() {
1279
+ var _i, _len, _ref, _results;
1280
+ _ref = tokens.classes;
1281
+ _results = [];
1282
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1283
+ name = _ref[_i];
1284
+ name = this.wrapCode(name, true);
1285
+ if (name.indexOf('#{') !== -1) hasDynamicClass = true;
1286
+ _results.push(name);
1287
+ }
1288
+ return _results;
1289
+ }).call(this);
1290
+ if (hasDynamicClass && classList.length > 1) {
1291
+ classes = '#{ [';
1292
+ for (_i = 0, _len = classList.length; _i < _len; _i++) {
1293
+ klass = classList[_i];
1294
+ classes += "" + (this.quoteAndEscapeAttributeValue(klass, true)) + ",";
1295
+ }
1296
+ classes = classes.substring(0, classes.length - 1) + '].sort().join(\' \').trim() }';
1297
+ } else {
1298
+ classes = classList.sort().join(' ');
1299
+ }
1300
+ tagParts.push("class='" + classes + "'");
1301
+ }
1302
+ if (tokens.id) tagParts.push("id='" + tokens.id + "'");
1303
+ if (tokens.attributes) {
1304
+ _ref = tokens.attributes;
1305
+ for (key in _ref) {
1306
+ value = _ref[key];
1307
+ if (value === 'true' || value === 'false') {
1308
+ if (value === 'true') {
1309
+ if (this.format === 'html5') {
1310
+ tagParts.push("" + key);
1311
+ } else {
1312
+ tagParts.push("" + key + "=" + (this.quoteAndEscapeAttributeValue(key)));
1313
+ }
1314
+ }
1315
+ } else {
1316
+ tagParts.push("" + key + "=" + (this.quoteAndEscapeAttributeValue(this.wrapCode(value))));
1317
+ }
1318
+ }
1319
+ }
1320
+ return tagParts.join(' ');
1321
+ };
1322
+
1323
+ Haml.prototype.wrapCode = function(text, unwrap) {
1324
+ var quoted;
1325
+ if (unwrap == null) unwrap = false;
1326
+ if (!text) return;
1327
+ if (!text.match(/^("|').*\1$/)) {
1328
+ if (this.escapeAttributes) {
1329
+ if (this.cleanValue) {
1330
+ text = '#{ $e($c(' + text + ')) }';
1331
+ } else {
1332
+ text = '#{ $e(' + text + ') }';
1333
+ }
1334
+ } else {
1335
+ if (this.cleanValue) {
1336
+ text = '#{ $c(' + text + ') }';
1337
+ } else {
1338
+ text = '#{ (' + text + ') }';
1339
+ }
1340
+ }
1341
+ }
1342
+ if (unwrap) if (quoted = text.match(/^("|')(.*)\1$/)) text = quoted[2];
1343
+ return text;
1344
+ };
1345
+
1346
+ Haml.prototype.quoteAndEscapeAttributeValue = function(value, code) {
1347
+ var escaped, hasDoubleQuotes, hasInterpolation, hasSingleQuotes, quoted, result, token, tokens, _i, _len;
1348
+ if (code == null) code = false;
1349
+ if (!value) return;
1350
+ if (quoted = value.match(/^("|')(.*)\1$/)) value = quoted[2];
1351
+ tokens = this.splitInterpolations(value);
1352
+ hasSingleQuotes = false;
1353
+ hasDoubleQuotes = false;
1354
+ hasInterpolation = false;
1355
+ for (_i = 0, _len = tokens.length; _i < _len; _i++) {
1356
+ token = tokens[_i];
1357
+ if (token.slice(0, 2) === '#{') {
1358
+ hasInterpolation = true;
1359
+ } else {
1360
+ if (!hasSingleQuotes) hasSingleQuotes = token.indexOf("'") !== -1;
1361
+ if (!hasDoubleQuotes) hasDoubleQuotes = token.indexOf('"') !== -1;
1362
+ }
1363
+ }
1364
+ if (code) {
1365
+ if (hasInterpolation) {
1366
+ result = "\"" + (tokens.join('')) + "\"";
1367
+ } else {
1368
+ result = "'" + (tokens.join('')) + "'";
1369
+ }
1370
+ } else {
1371
+ if (!hasDoubleQuotes && !hasSingleQuotes) {
1372
+ result = "'" + (tokens.join('')) + "'";
1373
+ }
1374
+ if (hasSingleQuotes && !hasDoubleQuotes) {
1375
+ result = "\\\"" + (tokens.join('')) + "\\\"";
1376
+ }
1377
+ if (hasDoubleQuotes && !hasSingleQuotes) {
1378
+ escaped = (function() {
1379
+ var _j, _len2, _results;
1380
+ _results = [];
1381
+ for (_j = 0, _len2 = tokens.length; _j < _len2; _j++) {
1382
+ token = tokens[_j];
1383
+ _results.push(escapeQuotes(token));
1384
+ }
1385
+ return _results;
1386
+ })();
1387
+ result = "'" + (escaped.join('')) + "'";
1388
+ }
1389
+ if (hasSingleQuotes && hasDoubleQuotes) {
1390
+ escaped = (function() {
1391
+ var _j, _len2, _results;
1392
+ _results = [];
1393
+ for (_j = 0, _len2 = tokens.length; _j < _len2; _j++) {
1394
+ token = tokens[_j];
1395
+ _results.push(escapeQuotes(token).replace(/'/g, '&#39;'));
1396
+ }
1397
+ return _results;
1398
+ })();
1399
+ result = "'" + (escaped.join('')) + "'";
1400
+ }
1401
+ }
1402
+ return result;
1403
+ };
1404
+
1405
+ Haml.prototype.splitInterpolations = function(value) {
1406
+ var ch, ch2, level, pos, quoted, start, tokens, _ref;
1407
+ level = 0;
1408
+ start = 0;
1409
+ tokens = [];
1410
+ quoted = false;
1411
+ for (pos = 0, _ref = value.length; 0 <= _ref ? pos < _ref : pos > _ref; 0 <= _ref ? pos++ : pos--) {
1412
+ ch = value[pos];
1413
+ ch2 = value.slice(pos, (pos + 1) + 1 || 9e9);
1414
+ if (ch === '{') level += 1;
1415
+ if (ch2 === '#{' && level === 0) {
1416
+ tokens.push(value.slice(start, pos));
1417
+ start = pos;
1418
+ }
1419
+ if (ch === '}') {
1420
+ level -= 1;
1421
+ if (level === 0) {
1422
+ tokens.push(value.slice(start, pos + 1 || 9e9));
1423
+ start = pos + 1;
1424
+ }
1425
+ }
1426
+ }
1427
+ tokens.push(value.slice(start, value.length));
1428
+ return tokens.filter(Boolean);
1429
+ };
1430
+
1431
+ Haml.prototype.buildDocType = function(doctype) {
1432
+ switch ("" + this.format + " " + doctype) {
1433
+ case 'xhtml !!! XML':
1434
+ return '<?xml version=\'1.0\' encoding=\'utf-8\' ?>';
1435
+ case 'xhtml !!!':
1436
+ return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
1437
+ case 'xhtml !!! 1.1':
1438
+ return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
1439
+ case 'xhtml !!! mobile':
1440
+ return '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">';
1441
+ case 'xhtml !!! basic':
1442
+ return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">';
1443
+ case 'xhtml !!! frameset':
1444
+ return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
1445
+ case 'xhtml !!! 5':
1446
+ case 'html5 !!!':
1447
+ return '<!DOCTYPE html>';
1448
+ case 'html5 !!! XML':
1449
+ case 'html4 !!! XML':
1450
+ return '';
1451
+ case 'html4 !!!':
1452
+ return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
1453
+ case 'html4 !!! frameset':
1454
+ return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">';
1455
+ case 'html4 !!! strict':
1456
+ return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
1457
+ }
1458
+ };
1459
+
1460
+ Haml.prototype.isNotSelfClosing = function(tag) {
1461
+ return this.selfCloseTags.indexOf(tag) === -1 && !tag.match(/\/$/);
1462
+ };
1463
+
1464
+ return Haml;
1465
+
1466
+ })();
1467
+
1468
+ }).call(this);
1469
+
1470
+ });
1471
+
1472
+ require.define("/nodes/code.coffee", function (require, module, exports, __dirname, __filename) {
1473
+ (function() {
1474
+ var Code, Node;
1475
+ var __hasProp = Object.prototype.hasOwnProperty, __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; };
1476
+
1477
+ Node = require('./node');
1478
+
1479
+ module.exports = Code = (function() {
1480
+
1481
+ __extends(Code, Node);
1482
+
1483
+ function Code() {
1484
+ Code.__super__.constructor.apply(this, arguments);
1485
+ }
1486
+
1487
+ Code.prototype.evaluate = function() {
1488
+ var code, codeBlock, escape, identifier;
1489
+ codeBlock = this.expression.match(/(-|!=|\&=|=|~)\s?(.*)?/);
1490
+ identifier = codeBlock[1];
1491
+ code = codeBlock[2];
1492
+ if (identifier === '-') {
1493
+ this.opener = this.markRunningCode(code);
1494
+ if (this.children.length !== 0 && this.opener.code.match(/(->|=>)/)) {
1495
+ return this.closer = this.markRunningCode(" ''");
1496
+ }
1497
+ } else if (identifier === '~') {
1498
+ if (this.escapeHtml) {
1499
+ return this.opener = this.markInsertingCode(code, true, false, true);
1500
+ } else {
1501
+ return this.opener = this.markInsertingCode(code, false, false, true);
1502
+ }
1503
+ } else {
1504
+ escape = identifier === '&=' || (identifier === '=' && this.escapeHtml);
1505
+ if (this.children.length !== 0 && code.match(/(->|=>)$/)) {
1506
+ this.opener = this.markInsertingCode(code, escape, false, false);
1507
+ this.opener.block = 'start';
1508
+ this.closer = this.markRunningCode(" $buffer.join \"\\n\"");
1509
+ return this.closer.block = 'end';
1510
+ } else {
1511
+ return this.opener = this.markInsertingCode(code, escape);
1512
+ }
1513
+ }
1514
+ };
1515
+
1516
+ return Code;
1517
+
1518
+ })();
1519
+
1520
+ }).call(this);
1521
+
1522
+ });
1523
+
1524
+ require.define("/nodes/comment.coffee", function (require, module, exports, __dirname, __filename) {
1525
+ (function() {
1526
+ var Comment, Node, escapeQuotes;
1527
+ var __hasProp = Object.prototype.hasOwnProperty, __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; };
1528
+
1529
+ Node = require('./node');
1530
+
1531
+ escapeQuotes = require('../util/text').escapeQuotes;
1532
+
1533
+ module.exports = Comment = (function() {
1534
+
1535
+ __extends(Comment, Node);
1536
+
1537
+ function Comment() {
1538
+ Comment.__super__.constructor.apply(this, arguments);
1539
+ }
1540
+
1541
+ Comment.prototype.evaluate = function() {
1542
+ var comment, expression, identifier, _ref;
1543
+ _ref = this.expression.match(/(-#|\/\[|\/)\s?(.*)?/), expression = _ref[0], identifier = _ref[1], comment = _ref[2];
1544
+ switch (identifier) {
1545
+ case '-#':
1546
+ this.silent = true;
1547
+ return this.opener = this.markText('');
1548
+ case '\/[':
1549
+ this.opener = this.markText("<!--[" + comment + ">");
1550
+ return this.closer = this.markText('<![endif]-->');
1551
+ case '\/':
1552
+ if (comment) {
1553
+ this.opener = this.markText("<!-- " + (escapeQuotes(comment)));
1554
+ return this.closer = this.markText(' -->');
1555
+ } else {
1556
+ this.opener = this.markText("<!--");
1557
+ return this.closer = this.markText('-->');
1558
+ }
1559
+ }
1560
+ };
1561
+
1562
+ return Comment;
1563
+
1564
+ })();
1565
+
1566
+ }).call(this);
1567
+
1568
+ });
1569
+
1570
+ require.define("/nodes/filter.coffee", function (require, module, exports, __dirname, __filename) {
1571
+ (function() {
1572
+ var Filter, Node, unescapeQuotes, whitespace;
1573
+ var __hasProp = Object.prototype.hasOwnProperty, __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; };
1574
+
1575
+ Node = require('./node');
1576
+
1577
+ whitespace = require('../util/text').whitespace;
1578
+
1579
+ unescapeQuotes = require('../util/text').unescapeQuotes;
1580
+
1581
+ module.exports = Filter = (function() {
1582
+
1583
+ __extends(Filter, Node);
1584
+
1585
+ function Filter() {
1586
+ Filter.__super__.constructor.apply(this, arguments);
1587
+ }
1588
+
1589
+ Filter.prototype.evaluate = function() {
1590
+ var _ref;
1591
+ return this.filter = (_ref = this.expression.match(/:(escaped|preserve|css|javascript|coffeescript|plain|cdata|coffeescript)(.*)?/)) != null ? _ref[1] : void 0;
1592
+ };
1593
+
1594
+ Filter.prototype.render = function() {
1595
+ var child, indent, output, preserve, _i, _j, _len, _len2, _ref, _ref2;
1596
+ output = [];
1597
+ switch (this.filter) {
1598
+ case 'escaped':
1599
+ _ref = this.children;
1600
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1601
+ child = _ref[_i];
1602
+ output.push(this.markText(child.render()[0].text, true));
1603
+ }
1604
+ break;
1605
+ case 'preserve':
1606
+ preserve = '';
1607
+ _ref2 = this.children;
1608
+ for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
1609
+ child = _ref2[_j];
1610
+ preserve += "" + (child.render()[0].text) + "&#x000A;";
1611
+ }
1612
+ preserve = preserve.replace(/\&\#x000A;$/, '');
1613
+ output.push(this.markText(preserve));
1614
+ break;
1615
+ case 'plain':
1616
+ this.renderFilterContent(0, output);
1617
+ break;
1618
+ case 'css':
1619
+ if (this.format === 'html5') {
1620
+ output.push(this.markText('<style>'));
1621
+ } else {
1622
+ output.push(this.markText('<style type=\'text/css\'>'));
1623
+ }
1624
+ if (this.format === 'xhtml') {
1625
+ output.push(this.markText(' /*<![CDATA[*/'));
1626
+ }
1627
+ indent = this.format === 'xhtml' ? 2 : 1;
1628
+ this.renderFilterContent(indent, output);
1629
+ if (this.format === 'xhtml') output.push(this.markText(' /*]]>*/'));
1630
+ output.push(this.markText('</style>'));
1631
+ break;
1632
+ case 'javascript':
1633
+ if (this.format === 'html5') {
1634
+ output.push(this.markText('<script>'));
1635
+ } else {
1636
+ output.push(this.markText('<script type=\'text/javascript\'>'));
1637
+ }
1638
+ if (this.format === 'xhtml') output.push(this.markText(' //<![CDATA['));
1639
+ indent = this.format === 'xhtml' ? 2 : 1;
1640
+ this.renderFilterContent(indent, output);
1641
+ if (this.format === 'xhtml') output.push(this.markText(' //]]>'));
1642
+ output.push(this.markText('</script>'));
1643
+ break;
1644
+ case 'cdata':
1645
+ output.push(this.markText('<![CDATA['));
1646
+ this.renderFilterContent(2, output);
1647
+ output.push(this.markText(']]>'));
1648
+ break;
1649
+ case 'coffeescript':
1650
+ this.renderFilterContent(0, output, 'run');
1651
+ }
1652
+ return output;
1653
+ };
1654
+
1655
+ Filter.prototype.renderFilterContent = function(indent, output, type) {
1656
+ var child, content, e, empty, line, _i, _j, _len, _len2, _ref, _results;
1657
+ if (type == null) type = 'text';
1658
+ content = [];
1659
+ empty = 0;
1660
+ _ref = this.children;
1661
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1662
+ child = _ref[_i];
1663
+ content.push(child.render()[0].text);
1664
+ }
1665
+ _results = [];
1666
+ for (_j = 0, _len2 = content.length; _j < _len2; _j++) {
1667
+ line = content[_j];
1668
+ if (line === '') {
1669
+ _results.push(empty += 1);
1670
+ } else {
1671
+ switch (type) {
1672
+ case 'text':
1673
+ for (e = 0; 0 <= empty ? e < empty : e > empty; 0 <= empty ? e++ : e--) {
1674
+ output.push(this.markText(""));
1675
+ }
1676
+ output.push(this.markText("" + (whitespace(indent)) + line));
1677
+ break;
1678
+ case 'run':
1679
+ output.push(this.markRunningCode("" + (unescapeQuotes(line))));
1680
+ }
1681
+ _results.push(empty = 0);
1682
+ }
1683
+ }
1684
+ return _results;
1685
+ };
1686
+
1687
+ return Filter;
1688
+
1689
+ })();
1690
+
1691
+ }).call(this);
1692
+
1693
+ });
1694
+
1695
+ require.define("/hamlc.coffee", function (require, module, exports, __dirname, __filename) {
1696
+ (function() {
1697
+ var CoffeeScript, Compiler, fs, __expressCache;
1698
+
1699
+ fs = require('fs');
1700
+
1701
+ Compiler = require('./haml-coffee');
1702
+
1703
+ if (process.title === 'node') {
1704
+ CoffeeScript = require('coffee-script');
1705
+ } else {
1706
+ CoffeeScript = window.CoffeeScript;
1707
+ }
1708
+
1709
+ __expressCache = {};
1710
+
1711
+ module.exports = {
1712
+ compile: function(source, options) {
1713
+ var compiler, template;
1714
+ if (options == null) options = {};
1715
+ compiler = new Compiler(options);
1716
+ compiler.parse(source);
1717
+ template = new Function(CoffeeScript.compile(compiler.precompile(), {
1718
+ bare: true
1719
+ }));
1720
+ return function(params) {
1721
+ return template.call(params);
1722
+ };
1723
+ },
1724
+ template: function(source, name, namespace, options) {
1725
+ var compiler;
1726
+ if (options == null) options = {};
1727
+ compiler = new Compiler(options);
1728
+ compiler.parse(source);
1729
+ return CoffeeScript.compile(compiler.render(name, namespace));
1730
+ },
1731
+ __express: function(filename, options, callback) {
1732
+ var source;
1733
+ if (!!(options && options.constructor && options.call && options.apply)) {
1734
+ callback = options;
1735
+ options = {};
1736
+ }
1737
+ try {
1738
+ if (options.cache && __expressCache[filename]) {
1739
+ return callback(null, __expressCache[filename](options));
1740
+ } else {
1741
+ options.filename = filename;
1742
+ source = fs.readFileSync(filename, 'utf8');
1743
+ if (options.cache) {
1744
+ __expressCache[filename] = module.exports.compile(source, options);
1745
+ return callback(null, __expressCache[filename](options));
1746
+ } else {
1747
+ return callback(null, module.exports.compile(source, options)(options));
1748
+ }
1749
+ }
1750
+ } catch (err) {
1751
+ return callback(err);
1752
+ }
1753
+ }
1754
+ };
1755
+
1756
+ }).call(this);
1757
+
1758
+ });
1759
+
1760
+ require.define("fs", function (require, module, exports, __dirname, __filename) {
1761
+ // nothing to see here... no file methods for the browser
1762
+
1763
+ });