|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- '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 if (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;
- };
|