Sha256: c0afb5f0af9e76dc246f84207a59d9de9f0ef23df3b60ca76514fc0e496e8c23

Contents?: true

Size: 1.92 KB

Versions: 37

Compression:

Stored size: 1.92 KB

Contents

/*!
 * Jade - nodes - Block
 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

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

/**
 * Initialize a new `Block` with an optional `node`.
 *
 * @param {Node} node
 * @api public
 */

var Block = module.exports = function Block(node){
  this.nodes = [];
  if (node) this.push(node);
};

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

Block.prototype.__proto__ = Node.prototype;

/**
 * Block flag.
 */

Block.prototype.isBlock = true;

/**
 * Replace the nodes in `other` with the nodes
 * in `this` block.
 *
 * @param {Block} other
 * @api private
 */

Block.prototype.replace = function(other){
  other.nodes = this.nodes;
};

/**
 * Pust the given `node`.
 *
 * @param {Node} node
 * @return {Number}
 * @api public
 */

Block.prototype.push = function(node){
  return this.nodes.push(node);
};

/**
 * Check if this block is empty.
 *
 * @return {Boolean}
 * @api public
 */

Block.prototype.isEmpty = function(){
  return 0 == this.nodes.length;
};

/**
 * Unshift the given `node`.
 *
 * @param {Node} node
 * @return {Number}
 * @api public
 */

Block.prototype.unshift = function(node){
  return this.nodes.unshift(node);
};

/**
 * Return the "last" block, or the first `yield` node.
 *
 * @return {Block}
 * @api private
 */

Block.prototype.includeBlock = function(){
  var ret = this
    , node;

  for (var i = 0, len = this.nodes.length; i < len; ++i) {
    node = this.nodes[i];
    if (node.yield) return node;
    else if (node.textOnly) continue;
    else if (node.includeBlock) ret = node.includeBlock();
    else if (node.block && !node.block.isEmpty()) ret = node.block.includeBlock();
  }

  return ret;
};

/**
 * Return a clone of this block.
 *
 * @return {Block}
 * @api private
 */

Block.prototype.clone = function(){
  var clone = new Block;
  for (var i = 0, len = this.nodes.length; i < len; ++i) {
    clone.push(this.nodes[i].clone());
  }
  return clone;
};

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
stylus-source-0.49.3 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.42.2 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.42.1 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.42.0 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.41.3 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.41.2 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.41.1 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.41.0 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.40.3 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.40.2 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.40.1 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.40.0 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.39.4 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.39.3 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.39.2 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.39.1 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.39.0 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.38.0 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.37.0 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js
stylus-source-0.36.1 vendor/node_modules/mocha/node_modules/jade/lib/nodes/block.js