Code coverage report for jade/lib/nodes/block.js

Statements: 97.56% (40 / 41)      Branches: 92.86% (13 / 14)      Functions: 100% (7 / 7)      Lines: 100% (35 / 35)      Ignored: none     

All files » jade/lib/nodes/ » block.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119    1                 1 5176 5176       1 1   1           1                   1 1 1   1                     1 6227                   1 194                     1 4                   1 69     69 90 90 70 66 66 66     17                   1 2 2   2 2 1   2    
'use strict';
 
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 = Object.create(Node.prototype);
Block.prototype.constructor = Block;
 
Block.prototype.type = 'Block';
 
/**
 * 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){
  var err = new Error('block.replace is deprecated and will be removed in v2.0.0');
  console.warn(err.stack);
 
  other.nodes = this.nodes;
};
 
/**
 * Push 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 Iif (node.includeBlock) ret = node.includeBlock();
    else if (node.block && !node.block.isEmpty()) ret = node.block.includeBlock();
    if (ret.yield) return ret;
  }
 
  return ret;
};
 
/**
 * Return a clone of this block.
 *
 * @return {Block}
 * @api private
 */
 
Block.prototype.clone = function(){
  var err = new Error('block.clone is deprecated and will be removed in v2.0.0');
  console.warn(err.stack);
 
  var clone = new Block;
  for (var i = 0, len = this.nodes.length; i < len; ++i) {
    clone.push(this.nodes[i].clone());
  }
  return clone;
};