UNPKG

jade

Version:

Jade template engine

102 lines (84 loc) 1.62 kB
/*! * Stylus - String * Copyright(c) 2010 LearnBoost <dev@learnboost.com> * MIT Licensed */ /** * Module dependencies. */ var Node = require('./node') , nodes = require('./'); /** * Initialize a new `String` with the given `val`. * * @param {String} val * @api public */ var String = module.exports = function String(val){ Node.call(this); this.val = val; this.string = val; }; /** * Inherit from `Node.prototype`. */ String.prototype.__proto__ = Node.prototype; /** * Return quoted string. * * @return {String} * @api public */ String.prototype.toString = function(){ return '"' + this.val + '"'; }; /** * Return a clone of this node. * * @return {Node} * @api public */ String.prototype.clone = function(){ var clone = new String(this.val); clone.lineno = this.lineno; return clone; }; /** * Return Boolean based on the length of this string. * * @return {Boolean} * @api public */ String.prototype.toBoolean = function(){ return nodes.Boolean(this.val.length); }; /** * Coerce `other` to a string. * * @param {Node} other * @return {String} * @api public */ String.prototype.coerce = function(other){ if (other instanceof String) { return other; } else { return new String(other.toString()); } }; /** * Operate on `right` with the given `op`. * * @param {String} op * @param {Node} right * @return {Node} * @api public */ String.prototype.operate = function(op, right){ switch (op) { case '+': return new String(this.val + right.val); default: return Node.prototype.operate.call(this, op, right); } };