Sha256: 922c802fd3931c14e13bdaa2b9961a84e2ba14d18db9afe043ed9e82b0de2345
Contents?: true
Size: 1.47 KB
Versions: 100
Compression:
Stored size: 1.47 KB
Contents
/*! * Stylus - Literal * Copyright(c) 2010 LearnBoost <dev@learnboost.com> * MIT Licensed */ /** * Module dependencies. */ var Node = require('./node') , nodes = require('./'); /** * Initialize a new `Literal` with the given `str`. * * @param {String} str * @api public */ var Literal = module.exports = function Literal(str){ Node.call(this); this.val = str; this.string = str; }; /** * Inherit from `Node.prototype`. */ Literal.prototype.__proto__ = Node.prototype; /** * Return hash. * * @return {String} * @api public */ Literal.prototype.__defineGetter__('hash', function(){ return this.val; }); /** * Return literal value. * * @return {String} * @api public */ Literal.prototype.toString = function(){ return this.val; }; /** * Coerce `other` to a literal. * * @param {Node} other * @return {String} * @api public */ Literal.prototype.coerce = function(other){ switch (other.nodeName) { case 'ident': case 'string': case 'literal': return new Literal(other.string); default: return Node.prototype.coerce.call(this, other); } }; /** * Operate on `right` with the given `op`. * * @param {String} op * @param {Node} right * @return {Node} * @api public */ Literal.prototype.operate = function(op, right){ var val = right.first; switch (op) { case '+': return new nodes.Literal(this.string + this.coerce(val).string); default: return Node.prototype.operate.call(this, op, right); } };
Version data entries
100 entries across 86 versions & 2 rubygems