UNPKG

haml-coffee

Version:

Haml templates where you can write inline CoffeeScript.

1,489 lines (1,338 loc) 76.1 kB
var require = function (file, cwd) { var resolved = require.resolve(file, cwd || '/'); var mod = require.modules[resolved]; if (!mod) throw new Error( 'Failed to resolve module ' + file + ', tried ' + resolved ); var cached = require.cache[resolved]; var res = cached? cached.exports : mod(); return res; }; require.paths = []; require.modules = {}; require.cache = {}; require.extensions = [".js",".coffee",".json"]; require._core = { 'assert': true, 'events': true, 'fs': true, 'path': true, 'vm': true }; require.resolve = (function () { return function (x, cwd) { if (!cwd) cwd = '/'; if (require._core[x]) return x; var path = require.modules.path(); cwd = path.resolve('/', cwd); var y = cwd || '/'; if (x.match(/^(?:\.\.?\/|\/)/)) { var m = loadAsFileSync(path.resolve(y, x)) || loadAsDirectorySync(path.resolve(y, x)); if (m) return m; } var n = loadNodeModulesSync(x, y); if (n) return n; throw new Error("Cannot find module '" + x + "'"); function loadAsFileSync (x) { x = path.normalize(x); if (require.modules[x]) { return x; } for (var i = 0; i < require.extensions.length; i++) { var ext = require.extensions[i]; if (require.modules[x + ext]) return x + ext; } } function loadAsDirectorySync (x) { x = x.replace(/\/+$/, ''); var pkgfile = path.normalize(x + '/package.json'); if (require.modules[pkgfile]) { var pkg = require.modules[pkgfile](); var b = pkg.browserify; if (typeof b === 'object' && b.main) { var m = loadAsFileSync(path.resolve(x, b.main)); if (m) return m; } else if (typeof b === 'string') { var m = loadAsFileSync(path.resolve(x, b)); if (m) return m; } else if (pkg.main) { var m = loadAsFileSync(path.resolve(x, pkg.main)); if (m) return m; } } return loadAsFileSync(x + '/index'); } function loadNodeModulesSync (x, start) { var dirs = nodeModulesPathsSync(start); for (var i = 0; i < dirs.length; i++) { var dir = dirs[i]; var m = loadAsFileSync(dir + '/' + x); if (m) return m; var n = loadAsDirectorySync(dir + '/' + x); if (n) return n; } var m = loadAsFileSync(x); if (m) return m; } function nodeModulesPathsSync (start) { var parts; if (start === '/') parts = [ '' ]; else parts = path.normalize(start).split('/'); var dirs = []; for (var i = parts.length - 1; i >= 0; i--) { if (parts[i] === 'node_modules') continue; var dir = parts.slice(0, i + 1).join('/') + '/node_modules'; dirs.push(dir); } return dirs; } }; })(); require.alias = function (from, to) { var path = require.modules.path(); var res = null; try { res = require.resolve(from + '/package.json', '/'); } catch (err) { res = require.resolve(from, '/'); } var basedir = path.dirname(res); var keys = (Object.keys || function (obj) { var res = []; for (var key in obj) res.push(key); return res; })(require.modules); for (var i = 0; i < keys.length; i++) { var key = keys[i]; if (key.slice(0, basedir.length + 1) === basedir + '/') { var f = key.slice(basedir.length); require.modules[to + f] = require.modules[basedir + f]; } else if (key === basedir) { require.modules[to] = require.modules[basedir]; } } }; (function () { var process = {}; var global = typeof window !== 'undefined' ? window : {}; var definedProcess = false; require.define = function (filename, fn) { if (!definedProcess && require.modules.__browserify_process) { process = require.modules.__browserify_process(); definedProcess = true; } var dirname = require._core[filename] ? '' : require.modules.path().dirname(filename) ; var require_ = function (file) { var requiredModule = require(file, dirname); var cached = require.cache[require.resolve(file, dirname)]; if (cached && cached.parent === null) { cached.parent = module_; } return requiredModule; }; require_.resolve = function (name) { return require.resolve(name, dirname); }; require_.modules = require.modules; require_.define = require.define; require_.cache = require.cache; var module_ = { id : filename, filename: filename, exports : {}, loaded : false, parent: null }; require.modules[filename] = function () { require.cache[filename] = module_; fn.call( module_.exports, require_, module_, module_.exports, dirname, filename, process, global ); module_.loaded = true; return module_.exports; }; }; })(); require.define("path",function(require,module,exports,__dirname,__filename,process,global){function filter (xs, fn) { var res = []; for (var i = 0; i < xs.length; i++) { if (fn(xs[i], i, xs)) res.push(xs[i]); } return res; } // resolves . and .. elements in a path array with directory names there // must be no slashes, empty elements, or device names (c:\) in the array // (so also no leading and trailing slashes - it does not distinguish // relative and absolute paths) function normalizeArray(parts, allowAboveRoot) { // if the path tries to go above the root, `up` ends up > 0 var up = 0; for (var i = parts.length; i >= 0; i--) { var last = parts[i]; if (last == '.') { parts.splice(i, 1); } else if (last === '..') { parts.splice(i, 1); up++; } else if (up) { parts.splice(i, 1); up--; } } // if the path is allowed to go above the root, restore leading ..s if (allowAboveRoot) { for (; up--; up) { parts.unshift('..'); } } return parts; } // Regex to split a filename into [*, dir, basename, ext] // posix version var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/; // path.resolve([from ...], to) // posix version exports.resolve = function() { var resolvedPath = '', resolvedAbsolute = false; for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) { var path = (i >= 0) ? arguments[i] : process.cwd(); // Skip empty and invalid entries if (typeof path !== 'string' || !path) { continue; } resolvedPath = path + '/' + resolvedPath; resolvedAbsolute = path.charAt(0) === '/'; } // At this point the path should be resolved to a full absolute path, but // handle relative paths to be safe (might happen when process.cwd() fails) // Normalize the path resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { return !!p; }), !resolvedAbsolute).join('/'); return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; }; // path.normalize(path) // posix version exports.normalize = function(path) { var isAbsolute = path.charAt(0) === '/', trailingSlash = path.slice(-1) === '/'; // Normalize the path path = normalizeArray(filter(path.split('/'), function(p) { return !!p; }), !isAbsolute).join('/'); if (!path && !isAbsolute) { path = '.'; } if (path && trailingSlash) { path += '/'; } return (isAbsolute ? '/' : '') + path; }; // posix version exports.join = function() { var paths = Array.prototype.slice.call(arguments, 0); return exports.normalize(filter(paths, function(p, index) { return p && typeof p === 'string'; }).join('/')); }; exports.dirname = function(path) { var dir = splitPathRe.exec(path)[1] || ''; var isWindows = false; if (!dir) { // No dirname return '.'; } else if (dir.length === 1 || (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) { // It is just a slash or a drive letter with a slash return dir; } else { // It is a full dirname, strip trailing slash return dir.substring(0, dir.length - 1); } }; exports.basename = function(path, ext) { var f = splitPathRe.exec(path)[2] || ''; // TODO: make this comparison case-insensitive on windows? if (ext && f.substr(-1 * ext.length) === ext) { f = f.substr(0, f.length - ext.length); } return f; }; exports.extname = function(path) { return splitPathRe.exec(path)[3] || ''; }; exports.relative = function(from, to) { from = exports.resolve(from).substr(1); to = exports.resolve(to).substr(1); function trim(arr) { var start = 0; for (; start < arr.length; start++) { if (arr[start] !== '') break; } var end = arr.length - 1; for (; end >= 0; end--) { if (arr[end] !== '') break; } if (start > end) return []; return arr.slice(start, end - start + 1); } var fromParts = trim(from.split('/')); var toParts = trim(to.split('/')); var length = Math.min(fromParts.length, toParts.length); var samePartsLength = length; for (var i = 0; i < length; i++) { if (fromParts[i] !== toParts[i]) { samePartsLength = i; break; } } var outputParts = []; for (var i = samePartsLength; i < fromParts.length; i++) { outputParts.push('..'); } outputParts = outputParts.concat(toParts.slice(samePartsLength)); return outputParts.join('/'); }; }); require.define("__browserify_process",function(require,module,exports,__dirname,__filename,process,global){var process = module.exports = {}; process.nextTick = (function () { var canSetImmediate = typeof window !== 'undefined' && window.setImmediate; var canPost = typeof window !== 'undefined' && window.postMessage && window.addEventListener ; if (canSetImmediate) { return function (f) { return window.setImmediate(f) }; } if (canPost) { var queue = []; window.addEventListener('message', function (ev) { if (ev.source === window && ev.data === 'browserify-tick') { ev.stopPropagation(); if (queue.length > 0) { var fn = queue.shift(); fn(); } } }, true); return function nextTick(fn) { queue.push(fn); window.postMessage('browserify-tick', '*'); }; } return function nextTick(fn) { setTimeout(fn, 0); }; })(); process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.binding = function (name) { if (name === 'evals') return (require)('vm') else throw new Error('No such module. (Possibly not yet loaded)') }; (function () { var cwd = '/'; var path; process.cwd = function () { return cwd }; process.chdir = function (dir) { if (!path) path = require('path'); cwd = path.resolve(dir, cwd); }; })(); }); require.define("/haml-coffee.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() { var Code, Comment, Directive, Filter, Haml, HamlCoffee, Node, Text, indent, whitespace; Node = require('./nodes/node'); Text = require('./nodes/text'); Haml = require('./nodes/haml'); Code = require('./nodes/code'); Comment = require('./nodes/comment'); Filter = require('./nodes/filter'); Directive = require('./nodes/directive'); whitespace = require('./util/text').whitespace; indent = require('./util/text').indent; module.exports = HamlCoffee = (function() { HamlCoffee.VERSION = '1.12.0'; function HamlCoffee(options) { var segment, segments, _base, _base1, _base10, _base11, _base12, _base13, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _base9, _i, _len; this.options = options != null ? options : {}; if ((_base = this.options).placement == null) { _base.placement = 'global'; } if ((_base1 = this.options).dependencies == null) { _base1.dependencies = { hc: 'hamlcoffee' }; } if ((_base2 = this.options).escapeHtml == null) { _base2.escapeHtml = true; } if ((_base3 = this.options).escapeAttributes == null) { _base3.escapeAttributes = true; } if ((_base4 = this.options).cleanValue == null) { _base4.cleanValue = true; } if ((_base5 = this.options).uglify == null) { _base5.uglify = false; } if ((_base6 = this.options).basename == null) { _base6.basename = false; } if ((_base7 = this.options).extendScope == null) { _base7.extendScope = false; } if ((_base8 = this.options).format == null) { _base8.format = 'html5'; } if ((_base9 = this.options).hyphenateDataAttrs == null) { _base9.hyphenateDataAttrs = true; } if ((_base10 = this.options).preserveTags == null) { _base10.preserveTags = 'pre,textarea'; } if ((_base11 = this.options).selfCloseTags == null) { _base11.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base'; } if (this.options.placement === 'global') { if ((_base12 = this.options).name == null) { _base12.name = 'test'; } if ((_base13 = this.options).namespace == null) { _base13.namespace = 'window.HAML'; } segments = ("" + this.options.namespace + "." + this.options.name).replace(/(\s|-)+/g, '_').split(/\./); this.options.name = this.options.basename ? segments.pop().split(/\/|\\/).pop() : segments.pop(); this.options.namespace = segments.shift(); this.intro = ''; if (segments.length !== 0) { for (_i = 0, _len = segments.length; _i < _len; _i++) { segment = segments[_i]; this.options.namespace += "." + segment; this.intro += "" + this.options.namespace + " ?= {}\n"; } } else { this.intro += "" + this.options.namespace + " ?= {}\n"; } } } HamlCoffee.prototype.indentChanged = function() { return this.currentIndent !== this.previousIndent; }; HamlCoffee.prototype.isIndent = function() { return this.currentIndent > this.previousIndent; }; HamlCoffee.prototype.updateTabSize = function() { if (this.tabSize === 0) { return this.tabSize = this.currentIndent - this.previousIndent; } }; HamlCoffee.prototype.updateBlockLevel = function() { this.currentBlockLevel = this.currentIndent / this.tabSize; if (!this.node.isCommented()) { if (this.currentBlockLevel - Math.floor(this.currentBlockLevel) > 0) { throw "Indentation error in line " + this.lineNumber; } if ((this.currentIndent - this.previousIndent) / this.tabSize > 1) { throw "Block level too deep in line " + this.lineNumber; } } return this.delta = this.previousBlockLevel - this.currentBlockLevel; }; HamlCoffee.prototype.updateCodeBlockLevel = function(node) { if (node instanceof Code) { return this.currentCodeBlockLevel = node.codeBlockLevel + 1; } else { return this.currentCodeBlockLevel = node.codeBlockLevel; } }; HamlCoffee.prototype.updateParent = function() { if (this.isIndent()) { return this.pushParent(); } else { return this.popParent(); } }; HamlCoffee.prototype.pushParent = function() { this.stack.push(this.parentNode); return this.parentNode = this.node; }; HamlCoffee.prototype.popParent = function() { var i, _i, _ref, _results; _results = []; for (i = _i = 0, _ref = this.delta - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { _results.push(this.parentNode = this.stack.pop()); } return _results; }; HamlCoffee.prototype.getNodeOptions = function(override) { if (override == null) { override = {}; } return { parentNode: override.parentNode || this.parentNode, blockLevel: override.blockLevel || this.currentBlockLevel, codeBlockLevel: override.codeBlockLevel || this.currentCodeBlockLevel, escapeHtml: override.escapeHtml || this.options.escapeHtml, escapeAttributes: override.escapeAttributes || this.options.escapeAttributes, cleanValue: override.cleanValue || this.options.cleanValue, format: override.format || this.options.format, hyphenateDataAttrs: override.hyphenateDataAttrs || this.options.format, preserveTags: override.preserveTags || this.options.preserveTags, selfCloseTags: override.selfCloseTags || this.options.selfCloseTags, uglify: override.uglify || this.options.uglify, placement: override.placement || this.options.placement, namespace: override.namespace || this.options.namespace, name: override.name || this.options.name }; }; HamlCoffee.prototype.nodeFactory = function(expression) { var node, options, _ref; if (expression == null) { expression = ''; } options = this.getNodeOptions(); if (expression.match(/^:(escaped|preserve|css|javascript|plain|cdata|coffeescript)/)) { node = new Filter(expression, options); } else if (expression.match(/^(\/|-#)(.*)/)) { node = new Comment(expression, options); } else if (expression.match(/^(-#|-|=|!=|\&=|~)\s*(.*)/)) { node = new Code(expression, options); } else if (expression.match(/^(%|#[^{]|\.|\!)(.*)/)) { node = new Haml(expression, options); } else if (expression.match(/^\+(.*)/)) { node = new Directive(expression, options); } else { node = new Text(expression, options); } if ((_ref = options.parentNode) != null) { _ref.addChild(node); } return node; }; HamlCoffee.prototype.parse = function(source) { var attributes, expression, line, lines, range, result, tabsize, text, ws, _i, _j, _len, _ref, _ref1, _results; if (source == null) { source = ''; } this.lineNumber = this.previousIndent = this.tabSize = this.currentBlockLevel = this.previousBlockLevel = 0; this.currentCodeBlockLevel = this.previousCodeBlockLevel = 0; this.node = null; this.stack = []; this.root = this.parentNode = new Node('', this.getNodeOptions()); lines = source.replace(/\r/g, '').split("\n"); while ((line = lines.shift()) !== void 0) { if ((this.node instanceof Filter) && !this.exitFilter) { if (/^(\s)*$/.test(line)) { this.node.addChild(new Text('', this.getNodeOptions({ parentNode: this.node }))); } else { result = line.match(/^(\s*)(.*)/); ws = result[1]; expression = result[2]; if (this.node.blockLevel >= (ws.length / 2)) { this.exitFilter = true; lines.unshift(line); continue; } range = this.tabSize > 2 ? (function() { _results = []; for (var _i = _ref = this.tabSize; _ref <= 1 ? _i <= 1 : _i >= 1; _ref <= 1 ? _i++ : _i--){ _results.push(_i); } return _results; }).apply(this) : [2, 1]; for (_j = 0, _len = range.length; _j < _len; _j++) { tabsize = range[_j]; text = line.match(RegExp("^\\s{" + ((this.node.blockLevel * tabsize) + tabsize) + "}(.*)")); if (text) { this.node.addChild(new Text(text[1], this.getNodeOptions({ parentNode: this.node }))); break; } } } } else { this.exitFilter = false; result = line.match(/^(\s*)(.*)/); ws = result[1]; expression = result[2]; if (/^\s*$/.test(line)) { continue; } while (/^[%.#].*[{(]/.test(expression) && RegExp("^\\s{" + (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])) { attributes = lines.shift(); expression = expression.replace(/(\s)+\|\s*$/, ''); expression += ' ' + attributes.match(/^\s*(.*?)(\s+\|\s*)?$/)[1]; this.lineNumber++; } while (/^-#/.test(expression) && !/^(\s*)[-=&!~.%#</]/.test(lines[0]) && lines.length > 0) { lines.shift(); this.lineNumber++; } if (expression.match(/(\s)+\|\s*$/)) { expression = expression.replace(/(\s)+\|\s*$/, ' '); while ((_ref1 = lines[0]) != null ? _ref1.match(/(\s)+\|$/) : void 0) { expression += lines.shift().match(/^(\s*)(.*)/)[2].replace(/(\s)+\|\s*$/, ''); this.lineNumber++; } } this.currentIndent = ws.length; if (this.indentChanged()) { this.updateTabSize(); this.updateBlockLevel(); this.updateParent(); this.updateCodeBlockLevel(this.parentNode); } this.node = this.nodeFactory(expression); this.previousBlockLevel = this.currentBlockLevel; this.previousIndent = this.currentIndent; } this.lineNumber++; } return this.evaluate(this.root); }; HamlCoffee.prototype.evaluate = function(node) { var child, _i, _len, _ref; _ref = node.children; for (_i = 0, _len = _ref.length; _i < _len; _i++) { child = _ref[_i]; this.evaluate(child); } return node.evaluate(); }; HamlCoffee.prototype.render = function() { switch (this.options.placement) { case 'amd': return this.renderAmd(); case 'standalone': return this.renderStandalone(); default: return this.renderGlobal(); } }; HamlCoffee.prototype.renderStandalone = function() { var template; return template = "return (context) ->\n (->\n" + (indent(this.precompile(), 2)) + "\n ).call(context)"; }; HamlCoffee.prototype.renderAmd = function() { var m, module, modules, param, params, template, _ref, _ref1; if (/^hamlcoffee/.test(this.options.dependencies['hc'])) { this.options.customHtmlEscape = 'hc.escape'; this.options.customCleanValue = 'hc.cleanValue'; this.options.customPreserve = 'hc.preserve'; this.options.customFindAndPreserve = 'hc.findAndPreserve'; this.options.customSurround = 'hc.surround'; this.options.customSucceed = 'hc.succeed'; this.options.customPrecede = 'hc.precede'; this.options.customReference = 'hc.reference'; } modules = []; params = []; _ref = this.options.dependencies; for (param in _ref) { module = _ref[param]; modules.push(module); params.push(param); } template = indent(this.precompile(), 4); _ref1 = this.findDependencies(template); for (param in _ref1) { module = _ref1[param]; modules.push(module); params.push(param); } if (modules.length !== 0) { modules = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = modules.length; _i < _len; _i++) { m = modules[_i]; _results.push("'" + m + "'"); } return _results; })(); modules = "[" + modules + "], (" + (params.join(', ')) + ")"; } else { modules = ''; } return "define " + modules + " ->\n (context) ->\n render = ->\n \n" + template + "\n render.call(context)"; }; HamlCoffee.prototype.renderGlobal = function() { var template; template = this.intro; if (this.options.extendScope) { template += "" + this.options.namespace + "['" + this.options.name + "'] = (context) -> ( ->\n"; template += " `with (context || {}) {`\n"; template += "" + (indent(this.precompile(), 1)); template += "`}`\n"; template += ").call(context)"; } else { template += "" + this.options.namespace + "['" + this.options.name + "'] = (context) -> ( ->\n"; template += "" + (indent(this.precompile(), 1)); template += ").call(context)"; } return template; }; HamlCoffee.prototype.precompile = function() { var code, fn; fn = ''; code = this.createCode(); if (code.indexOf('$e') !== -1) { if (this.options.customHtmlEscape) { fn += "$e = " + this.options.customHtmlEscape + "\n"; } else { 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, '&#47;')\n .replace(/\"/g, '&quot;')\n"; } } if (code.indexOf('$c') !== -1) { if (this.options.customCleanValue) { fn += "$c = " + this.options.customCleanValue + "\n"; } else { fn += "$c = (text) ->\n"; fn += " switch text\n"; fn += " when null, undefined then ''\n"; fn += " when true, false then '\u0093' + text\n"; fn += " else text\n"; } } if (code.indexOf('$p') !== -1 || code.indexOf('$fp') !== -1) { if (this.options.customPreserve) { fn += "$p = " + this.options.customPreserve + "\n"; } else { fn += "$p = (text) -> text.replace /\\n/g, '&#x000A;'\n"; } } if (code.indexOf('$fp') !== -1) { if (this.options.customFindAndPreserve) { fn += "$fp = " + this.options.customFindAndPreserve + "\n"; } else { fn += "$fp = (text) ->\n text.replace /<(" + (this.options.preserveTags.split(',').join('|')) + ")>([^]*?)<\\/\\1>/g, (str, tag, content) ->\n \"<\#{ tag }>\#{ $p content }</\#{ tag }>\"\n"; } } if (code.indexOf('surround') !== -1) { if (this.options.customSurround) { fn += "surround = (start, end, fn) => " + this.options.customSurround + ".call(@, start, end, fn)\n"; } else { fn += "surround = (start, end, fn) => start + fn.call(@)?.replace(/^\\s+|\\s+$/g, '') + end\n"; } } if (code.indexOf('succeed') !== -1) { if (this.options.customSucceed) { fn += "succeed = (start, end, fn) => " + this.options.customSucceed + ".call(@, start, end, fn)\n"; } else { fn += "succeed = (end, fn) => fn.call(@)?.replace(/\s+$/g, '') + end\n"; } } if (code.indexOf('precede') !== -1) { if (this.options.customPrecede) { fn += "precede = (start, end, fn) => " + this.options.customPrecede + ".call(@, start, end, fn)\n"; } else { fn += "precede = (start, fn) => start + fn.call(@)?.replace(/^\s+/g, '')\n"; } } if (code.indexOf('$r') !== -1) { if (this.options.customReference) { fn += "$r = " + this.options.customReference + "\n"; } else { 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"; } } fn += "$o = []\n"; fn += "" + code + "\n"; return fn += "return $o.join(\"\\n\")" + (this.convertBooleans(code)) + (this.removeEmptyIDAndClass(code)) + (this.cleanupWhitespace(code)) + "\n"; }; HamlCoffee.prototype.createCode = function() { var child, code, line, processors, _i, _j, _len, _len1, _ref, _ref1; code = []; this.lines = []; _ref = this.root.children; for (_i = 0, _len = _ref.length; _i < _len; _i++) { child = _ref[_i]; this.lines = this.lines.concat(child.render()); } this.lines = this.combineText(this.lines); this.blockLevel = 0; _ref1 = this.lines; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { line = _ref1[_j]; if (line !== null) { switch (line.type) { case 'text': code.push("" + (whitespace(line.cw)) + (this.getBuffer(this.blockLevel)) + ".push \"" + (whitespace(line.hw)) + line.text + "\""); break; case 'run': if (line.block !== 'end') { code.push("" + (whitespace(line.cw)) + line.code); } else { code.push("" + (whitespace(line.cw)) + (line.code.replace('$buffer', this.getBuffer(this.blockLevel)))); this.blockLevel -= 1; } break; case 'insert': processors = ''; if (line.findAndPreserve) { processors += '$fp '; } if (line.preserve) { processors += '$p '; } if (line.escape) { processors += '$e '; } if (this.options.cleanValue) { processors += '$c '; } code.push("" + (whitespace(line.cw)) + (this.getBuffer(this.blockLevel)) + ".push \"" + (whitespace(line.hw)) + "\" + " + processors + line.code); if (line.block === 'start') { this.blockLevel += 1; code.push("" + (whitespace(line.cw + 1)) + (this.getBuffer(this.blockLevel)) + " = []"); } } } } return code.join('\n'); }; HamlCoffee.prototype.getBuffer = function(level) { if (level > 0) { return "$o" + level; } else { return '$o'; } }; HamlCoffee.prototype.combineText = function(lines) { var combined, line, nextLine; combined = []; while ((line = lines.shift()) !== void 0) { if (line.type === 'text') { while (lines[0] && lines[0].type === 'text' && line.cw === lines[0].cw) { nextLine = lines.shift(); line.text += "\\n" + (whitespace(nextLine.hw)) + nextLine.text; } } combined.push(line); } return combined; }; HamlCoffee.prototype.convertBooleans = function(code) { if (code.indexOf('$c') !== -1) { if (this.options.format === 'xhtml') { return '.replace(/\\s(\\w+)=\'\u0093true\'/mg, " $1=\'$1\'").replace(/\\s(\\w+)=\'\u0093false\'/mg, \'\')'; } else { return '.replace(/\\s(\\w+)=\'\u0093true\'/mg, \' $1\').replace(/\\s(\\w+)=\'\u0093false\'/mg, \'\')'; } } else { return ''; } }; HamlCoffee.prototype.removeEmptyIDAndClass = function(code) { if (code.indexOf('id=') !== -1 || code.indexOf('class=') !== -1) { return '.replace(/\\s(?:id|class)=([\'"])(\\1)/mg, "")'; } else { return ''; } }; HamlCoffee.prototype.cleanupWhitespace = function(code) { if (/\u0091|\u0092/.test(code)) { return ".replace(/[\\s\\n]*\\u0091/mg, '').replace(/\\u0092[\\s\\n]*/mg, '')"; } else { return ''; } }; HamlCoffee.prototype.findDependencies = function(code) { var dependencies, match, module, name, requireRegexp; requireRegexp = /require(?:\s+|\()(['"])(.+?)(\1)\)?/gm; dependencies = {}; while (match = requireRegexp.exec(code)) { module = match[2]; name = module.split('/').pop(); dependencies[name] = module; } return dependencies; }; return HamlCoffee; })(); }).call(this); }); require.define("/nodes/node.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() { var Node, escapeHTML; escapeHTML = require('../util/text').escapeHTML; module.exports = Node = (function() { Node.CLEAR_WHITESPACE_LEFT = '\u0091'; Node.CLEAR_WHITESPACE_RIGHT = '\u0092'; function Node(expression, options) { this.expression = expression != null ? expression : ''; if (options == null) { options = {}; } this.parentNode = options.parentNode; this.children = []; this.opener = this.closer = null; this.silent = false; this.preserveTags = options.preserveTags.split(','); this.preserve = false; this.wsRemoval = { around: false, inside: false }; this.escapeHtml = options.escapeHtml; this.escapeAttributes = options.escapeAttributes; this.cleanValue = options.cleanValue; this.format = options.format; this.hyphenateDataAttrs = options.hyphenateDataAttrs; this.selfCloseTags = options.selfCloseTags.split(','); this.uglify = options.uglify; this.codeBlockLevel = options.codeBlockLevel; this.blockLevel = options.blockLevel; this.placement = options.placement; this.namespace = options.namespace; this.name = options.name; } Node.prototype.addChild = function(child) { this.children.push(child); return this; }; Node.prototype.getOpener = function() { if (this.wsRemoval.around && this.opener.text) { this.opener.text = Node.CLEAR_WHITESPACE_LEFT + this.opener.text; } if (this.wsRemoval.inside && this.opener.text) { this.opener.text += Node.CLEAR_WHITESPACE_RIGHT; } return this.opener; }; Node.prototype.getCloser = function() { if (this.wsRemoval.inside && this.closer.text) { this.closer.text = Node.CLEAR_WHITESPACE_LEFT + this.closer.text; } if (this.wsRemoval.around && this.closer.text) { this.closer.text += Node.CLEAR_WHITESPACE_RIGHT; } return this.closer; }; Node.prototype.isPreserved = function() { if (this.preserve) { return true; } if (this.parentNode) { return this.parentNode.isPreserved(); } else { return false; } }; Node.prototype.isCommented = function() { if (this.constructor.name === 'Comment') { return true; } if (this.parentNode) { return this.parentNode.isCommented(); } else { return false; } }; Node.prototype.markText = function(text, escape) { if (escape == null) { escape = false; } return { type: 'text', cw: this.codeBlockLevel, hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel, text: escape ? escapeHTML(text) : text }; }; Node.prototype.markRunningCode = function(code) { return { type: 'run', cw: this.codeBlockLevel, code: code }; }; Node.prototype.markInsertingCode = function(code, escape, preserve, findAndPreserve) { if (escape == null) { escape = false; } if (preserve == null) { preserve = false; } if (findAndPreserve == null) { findAndPreserve = false; } return { type: 'insert', cw: this.codeBlockLevel, hw: this.uglify ? 0 : this.blockLevel - this.codeBlockLevel, escape: escape, preserve: preserve, findAndPreserve: findAndPreserve, code: code }; }; Node.prototype.evaluate = function() {}; Node.prototype.render = function() { var child, output, rendered, tag, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4; output = []; if (this.silent) { return output; } if (this.children.length === 0) { if (this.opener && this.closer) { tag = this.getOpener(); tag.text += this.getCloser().text; output.push(tag); } else { if (!this.preserve && this.isPreserved()) { output.push(this.getOpener()); } else { output.push(this.getOpener()); } } } else { if (this.opener && this.closer) { if (this.preserve) { this.wsRemoval.inside = true; output.push(this.getOpener()); _ref = this.children; for (_i = 0, _len = _ref.length; _i < _len; _i++) { child = _ref[_i]; _ref1 = child.render(); for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { rendered = _ref1[_j]; rendered.hw = this.blockLevel; output.push(rendered); } } output.push(this.getCloser()); } else { output.push(this.getOpener()); _ref2 = this.children; for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { child = _ref2[_k]; output = output.concat(child.render()); } output.push(this.getCloser()); } } else if (this.opener) { output.push(this.getOpener()); _ref3 = this.children; for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { child = _ref3[_l]; output = output.concat(child.render()); } } else { _ref4 = this.children; for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) { child = _ref4[_m]; output.push(this.markText(child.render().text)); } } } return output; }; return Node; })(); }).call(this); }); require.define("/util/text.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() { module.exports = { whitespace: function(n) { var a; n = n * 2; a = []; while (a.length < n) { a.push(' '); } return a.join(''); }, escapeQuotes: function(text) { if (!text) { return ''; } return text.replace(/"/g, '\\"').replace(/\\\\\"/g, '\\"'); }, unescapeQuotes: function(text) { if (!text) { return ''; } return text.replace(/\\"/g, '"'); }, escapeHTML: function(text) { if (!text) { return ''; } return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;'); }, preserve: function(code) { if (code) { code.replace(/\r/g, ''); return code.replace(/<(pre|textarea)>(.*?)<\/\1>/g, function(text) { return text.replace('\\n', '\&\#x000A;'); }); } }, indent: function(text, spaces) { return text.replace(/^(.*)$/mg, module.exports.whitespace(spaces) + '$1'); } }; }).call(this); }); require.define("/nodes/text.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() { var Node, Text, escapeQuotes, _ref, __hasProp = {}.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; }; Node = require('./node'); escapeQuotes = require('../util/text').escapeQuotes; module.exports = Text = (function(_super) { __extends(Text, _super); function Text() { _ref = Text.__super__.constructor.apply(this, arguments); return _ref; } Text.prototype.evaluate = function() { return this.opener = this.markText(escapeQuotes(this.expression)); }; return Text; })(Node); }).call(this); }); require.define("/nodes/haml.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() { var Haml, Node, escapeQuotes, _ref, __hasProp = {}.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; }; Node = require('./node'); escapeQuotes = require('../util/text').escapeQuotes; module.exports = Haml = (function(_super) { __extends(Haml, _super); function Haml() { _ref = Haml.__super__.constructor.apply(this, arguments); return _ref; } Haml.prototype.evaluate = function() { var assignment, code, identifier, match, prefix, tokens; tokens = this.parseExpression(this.expression); if (tokens.doctype) { return this.opener = this.markText("" + (escapeQuotes(this.buildDocType(tokens.doctype)))); } else { if (this.isNotSelfClosing(tokens.tag)) { prefix = this.buildHtmlTagPrefix(tokens); if (tokens.assignment) { match = tokens.assignment.match(/^(=|!=|&=|~)\s*(.*)$/); identifier = match[1]; assignment = match[2]; if (identifier === '~') { code = "\#{$fp " + assignment + " }"; } else if (identifier === '&=' || (identifier === '=' && this.escapeHtml)) { if (this.preserve) { if (this.cleanValue) { code = "\#{ $p($e($c(" + assignment + "))) }"; } else { code = "\#{ $p($e(" + assignment + ")) }"; } } else { if (this.cleanValue) { code = "\#{ $e($c(" + assignment + ")) }"; } else { code = "\#{ $e(" + assignment + ") }"; } } } else if (identifier === '!=' || (identifier === '=' && !this.escapeHtml)) { if (this.preserve) { if (this.cleanValue) { code = "\#{ $p($c(" + assignment + ")) }"; } else { code = "\#{ $p(" + assignment + ") }"; } } else { if (this.cleanValue) { code = "\#{ $c(" + assignment + ") }"; } else { code = "\#{ " + assignment + " }"; } } } this.opener = this.markText("" + prefix + ">" + code); return this.closer = this.markText("</" + tokens.tag + ">"); } else if (tokens.text) { this.opener = this.markText("" + prefix + ">" + tokens.text); return this.closer = this.markText("</" + tokens.tag + ">"); } else { this.opener = this.markText(prefix + '>'); return this.closer = this.markText("</" + tokens.tag + ">"); } } else { tokens.tag = tokens.tag.replace(/\/$/, ''); prefix = this.buildHtmlTagPrefix(tokens); if (tokens.text) { this.opener = this.markText("" + prefix + ">" + tokens.text); return this.closer = this.markText("</" + tokens.tag + ">"); } else { return this.opener = this.markText("" + prefix + (this.format === 'xhtml' ? ' /' : '') + ">" + tokens.text); } } } }; Haml.prototype.parseExpression = function(exp) { var attributes, classes, id, key, tag, value, _ref1, _ref2; tag = this.parseTag(exp); if (this.preserveTags.indexOf(tag.tag) !== -1) { this.preserve = true; } id = this.interpolateCodeAttribute((_ref1 = tag.ids) != null ? _ref1.pop() : void 0, true); classes = tag.classes; attributes = {}; if (tag.attributes) { _ref2 = tag.attributes; for (key in _ref2) { value = _ref2[key]; if (key === 'id') { if (id) { id += '_' + this.interpolateCodeAttribute(value, true); } else { id = this.interpolateCodeAttribute(value, true); } } else if (key === 'class') { classes || (classes = []); classes.push(value); } else { attributes[key] = value; } } } return { doctype: tag.doctype, tag: tag.tag, id: id, classes: classes, text: escapeQuotes(tag.text), attributes: attributes, assignment: tag.assignment, reference: tag.reference }; }; Haml.prototype.parseTag = function(exp) { 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; try { doctype = (_ref1 = exp.match(/^(\!{3}.*)/)) != null ? _ref1[1] : void 0; if (doctype) { return { doctype: doctype }; } haml = exp.match(/^((?:[#%\.][a-z0-9_:\-]*[\/]?)+)/i)[0]; rest = exp.substring(haml.length); if (rest.match(/^[{([]/)) { reference = ''; htmlAttributes = ''; rubyAttributes = ''; _ref2 = ['[', '{', '(', '[', '{', '(']; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { start = _ref2[_i]; if (start === rest[0]) { end = (function() { switch (start) { case '{': return '}'; case '(': return ')'; case '[': return ']'; } })(); level = 0; for (pos = _j = 0, _ref3 = rest.length; 0 <= _ref3 ? _j <= _ref3 : _j >= _ref3; pos = 0 <= _ref3 ? ++_j : --_j) { ch = rest[pos]; if (ch === start) { level += 1; } if (ch === end) { if (level === 1) { break; } else { level -= 1; } } } switch (start) { case '{': rubyAttributes += rest.substring(0, pos + 1); rest = rest.substring(pos + 1); break; case '(': htmlAttributes += rest.substring(0, pos + 1); rest = rest.substring(pos + 1); break; case '[': reference = rest.substring(1, pos); rest = rest.substring(pos + 1); } } } assignment = rest || ''; } else { reference = ''; htmlAttributes = ''; rubyAttributes = ''; assignment = rest; } attributes = {}; _ref4 = [this.parseAttributes(htmlAttributes), this.parseAttributes(rubyAttributes)]; for (_k = 0, _len1 = _ref4.length; _k < _len1; _k++) { attr = _ref4[_k]; for (key in attr) { val = attr[key]; attributes[key] = val; } } if (whitespace = (_ref5 = assignment.match(/^[<>]{0,2}/)) != null ? _ref5[0] : void 0) { assignment = assignment.substring(whitespace.length); } if (assignment[0] === ' ') { assignment = assignment.substring(1); } if (assignment && !assignment.match(/^(=|!=|&=|~)/)) { text = assignment.replace(/^ /, ''); assignment = void 0; } if (whitespace) { if (whitespace.indexOf('>') !== -1) { this.wsRemoval.around = true; } if (whitespace.indexOf('<') !== -1) { this.wsRemoval.inside = true; this.preserve = true; } } tag = haml.match(/\%([a-z_\-][a-z0-9_:\-]*[\/]?)/i); ids = haml.match(/\#([a-z_\-][a-z0-9_\-]*)/gi); classes = haml.match(/\.([a-z0-9_\-]*)/gi); return { tag: tag ? tag[1] : 'div', ids: ids ? (function() { var _l, _len2, _results; _results = []; for (_l = 0, _len2 = ids.length; _l < _len2; _l++) { id = ids[_l]; _results.push("'" + (id.substr(1)) + "'"); } return _results; })() : void 0