Class: Directive
Defined in: | node_modules/grunt-codo/node_modules/codo/node_modules/haml-coffee/src/nodes/directive.coffee |
Inherits: | Node |
Overview
Directive node for HAML statements that change the meaning or do interact uniquely with the HAML document.
Examples:
include a HAML document inside of another
+include 'path/to/template'[, context]
Variables Summary
- directives =
-
{ /* Includes a HAML document inside of the current one. Context included template is defaulted to the context of this template but may be changed by passing a second argument. @example Include with default context +include 'path/to/template' @example Include with custom context +include 'path/to/template', @context */ include: function(expression) { var Compiler, code, compiler, context, e, error, name, source, statement, _ref; try { _ref = expression.match(/\s*['"](.*?)['"](?:,\s*(.*))?\s*/), _ref[0], name = _ref[1], context = _ref[2]; } catch (_error) { e = _error; throw new Error("Failed to parse the include directive from " + expression); } if (!context) { context = 'this'; } statement = (function() { switch (this.placement) { case 'global': return "" + this.namespace + "['" + name + "'](" + context + ")"; case 'amd': return "require('" + name + "')(" + context + ")"; case 'standalone': if (typeof browser !== "undefined" && browser !== null ? browser.process : void 0) { throw new Error("Include directive not available in the Browser when placement is standalone."); } else { try { source = fs.readFileSync(name).toString(); } catch (_error) { error = _error; console.error(" Error opening file: %s", error); console.error(error); } /* Compile and build the source function. */ Compiler = require('../haml-coffee'); compiler = new Compiler(this.options); compiler.parse(source); code = CoffeeScript.compile(compiler.precompile(), { bare: true }); return statement = "`(function(){" + code + "}).apply(" + context + ")`"; } break; default: throw new Error("Include directive not available when placement is " + this.placement); } }).call(this); return this.opener = this.markInsertingCode(statement, false); } }
Map of available directives to methods.
Variable inherited from Node
CLEAR_WHITESPACE_LEFT CLEAR_WHITESPACE_RIGHT
Instance Method Summary
- # (void) evaluate() Evaluate the Haml directive.
Inherited Method Summary
Methods inherited from
Node
#addChild #getOpener #getCloser #isPreserved #isCommented #markText #markRunningCode #markInsertingCode #evaluate #render
Instance Method Details
#
(void)
evaluate()
Evaluate the Haml directive.