Inital Commit
[oweals/finalsclub.git] / node_modules / jade / support / stylus / lib / nodes / string.js
1
2 /*!
3  * Stylus - String
4  * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
5  * MIT Licensed
6  */
7
8 /**
9  * Module dependencies.
10  */
11
12 var Node = require('./node')
13   , nodes = require('./');
14
15 /**
16  * Initialize a new `String` with the given `val`.
17  *
18  * @param {String} val
19  * @api public
20  */
21
22 var String = module.exports = function String(val){
23   Node.call(this);
24   this.val = val;
25   this.string = val;
26 };
27
28 /**
29  * Inherit from `Node.prototype`.
30  */
31
32 String.prototype.__proto__ = Node.prototype;
33
34 /**
35  * Return quoted string.
36  *
37  * @return {String}
38  * @api public
39  */
40
41 String.prototype.toString = function(){
42   return '"' + this.val + '"';
43 };
44
45 /**
46  * Return a clone of this node.
47  * 
48  * @return {Node}
49  * @api public
50  */
51
52 String.prototype.clone = function(){
53   var clone = new String(this.val);
54   clone.lineno = this.lineno;
55   return clone;
56 };
57
58 /**
59  * Return Boolean based on the length of this string.
60  *
61  * @return {Boolean}
62  * @api public
63  */
64
65 String.prototype.toBoolean = function(){
66   return nodes.Boolean(this.val.length);
67 };
68
69 /**
70  * Coerce `other` to a string.
71  *
72  * @param {Node} other
73  * @return {String}
74  * @api public
75  */
76
77 String.prototype.coerce = function(other){
78   if (other instanceof String) {
79     return other;
80   } else {
81     return new String(other.toString());
82   }
83 };
84
85 /**
86  * Operate on `right` with the given `op`.
87  *
88  * @param {String} op
89  * @param {Node} right
90  * @return {Node}
91  * @api public
92  */
93
94 String.prototype.operate = function(op, right){
95   switch (op) {
96     case '+':
97       return new String(this.val + right.val);
98     default:
99       return Node.prototype.operate.call(this, op, right);
100   }
101 };