UNPKG

jade

Version:

Jade template engine

98 lines (80 loc) 1.53 kB
/*! * Stylus - Ident * Copyright(c) 2010 LearnBoost <dev@learnboost.com> * MIT Licensed */ /** * Module dependencies. */ var Node = require('./node') , nodes = require('./'); /** * Initialize a new `Ident` by `name` with the given `val` node. * * @param {String} name * @param {Node} val * @api public */ var Ident = module.exports = function Ident(name, val){ Node.call(this); this.name = name; this.string = name; this.val = val || nodes.null; }; /** * Check if the variable has a value. * * @return {Boolean} * @api public */ Ident.prototype.__defineGetter__('isEmpty', function(){ return undefined == this.val; }); /** * Return hash. * * @return {String} * @api public */ Ident.prototype.__defineGetter__('hash', function(){ return this.name; }); /** * Inherit from `Node.prototype`. */ Ident.prototype.__proto__ = Node.prototype; /** * Return a clone of this node. * * @return {Node} * @api public */ Ident.prototype.clone = function(){ var clone = new Ident(this.name, this.val.clone()); clone.lineno = this.lineno; return clone; }; /** * Return <name>. * * @return {String} * @api public */ Ident.prototype.toString = function(){ return this.name; }; /** * Coerce `other` to an ident. * * @param {Node} other * @return {String} * @api public */ Ident.prototype.coerce = function(other){ if (other instanceof nodes.Literal || other instanceof Ident) { return other; } else { return Node.prototype.coerce.call(this, other); } };