Sha256: ae0836a888c92c423ac66f2baf125f7ef6a3e133911015149344acf5d5569188

Contents?: true

Size: 1.81 KB

Versions: 33

Compression:

Stored size: 1.81 KB

Contents

/*!
 * Stylus - Group
 * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var Node = require('./node');

/**
 * Initialize a new `Group`.
 *
 * @api public
 */

var Group = module.exports = function Group(){
  Node.call(this);
  this.nodes = [];
  this.extends = [];
};

/**
 * Inherit from `Node.prototype`.
 */

Group.prototype.__proto__ = Node.prototype;

/**
 * Push the given `selector` node.
 *
 * @param {Selector} selector
 * @api public
 */

Group.prototype.push = function(selector){
  this.nodes.push(selector);
};

/**
 * Return this set's `Block`.
 */

Group.prototype.__defineGetter__('block', function(){
  return this.nodes[0].block;
});

/**
 * Assign `block` to each selector in this set.
 *
 * @param {Block} block
 * @api public
 */

Group.prototype.__defineSetter__('block', function(block){
  for (var i = 0, len = this.nodes.length; i < len; ++i) {
    this.nodes[i].block = block;
  }
});

/**
 * Check if this set has only placeholders.
 *
 * @return {Boolean}
 * @api public
 */

Group.prototype.__defineGetter__('hasOnlyPlaceholders', function(){
  return this.nodes.every(function(selector) { return selector.isPlaceholder; });
});

/**
 * Return a clone of this node.
 * 
 * @return {Node}
 * @api public
 */

Group.prototype.clone = function(parent){
  var clone = new Group;
  clone.lineno = this.lineno;
  this.nodes.forEach(function(node){
    clone.push(node.clone(parent, clone));
  });
  clone.filename = this.filename;
  clone.block = this.block.clone(parent, clone);
  return clone;
};

/**
 * Return a JSON representation of this node.
 *
 * @return {Object}
 * @api public
 */

Group.prototype.toJSON = function(){
  return {
    __type: 'Group',
    nodes: this.nodes,
    block: this.block,
    lineno: this.lineno,
    filename: this.filename
  };
};

Version data entries

33 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/poised/node_modules/stylus/lib/nodes/group.js
ela-4.1.6 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-4.1.5 node_modules/poised/node_modules/stylus/lib/nodes/group.js
ela-4.1.5 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-4.1.4 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-4.1.4 node_modules/poised/node_modules/stylus/lib/nodes/group.js
ela-4.1.3 node_modules/poised/node_modules/stylus/lib/nodes/group.js
ela-4.1.3 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-4.1.2 node_modules/poised/node_modules/stylus/lib/nodes/group.js
ela-4.1.2 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-4.1.1 node_modules/poised/node_modules/stylus/lib/nodes/group.js
ela-4.1.1 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-4.1.0 node_modules/poised/node_modules/stylus/lib/nodes/group.js
ela-4.1.0 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-4.0.0 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-3.4.3 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-3.4.2 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-3.4.0 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-3.3.1 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/group.js
ela-3.3.0 node_modules/poised.old/node_modules/stylus/lib/nodes/group.js