Code coverage report for jade\lib\nodes\tag.js

Statements: 100% (36 / 36)      Branches: 100% (17 / 17)      Functions: 100% (5 / 5)      Lines: 100% (33 / 33)      Ignored: none     

All files » jade\lib\nodes\ » tag.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    1 1 1                   1 2325 2325 2325       1 1   1                 1 1 1   1 1 1 1 1                   1 3369                   1 1332   1   1231 1117       1332     994     233 33 36 30   3       200    
'use strict';
 
var Attrs = require('./attrs');
var Block = require('./block');
var inlineTags = require('../inline-tags');
 
/**
 * Initialize a `Tag` node with the given tag `name` and optional `block`.
 *
 * @param {String} name
 * @param {Block} block
 * @api public
 */
 
var Tag = module.exports = function Tag(name, block) {
  Attrs.call(this);
  this.name = name;
  this.block = block || new Block;
};
 
// Inherit from `Attrs`.
Tag.prototype = Object.create(Attrs.prototype);
Tag.prototype.constructor = Tag;
 
Tag.prototype.type = 'Tag';
 
/**
 * Clone this tag.
 *
 * @return {Tag}
 * @api private
 */
 
Tag.prototype.clone = function(){
  var err = new Error('tag.clone is deprecated and will be removed in v2.0.0');
  console.warn(err.stack);
 
  var clone = new Tag(this.name, this.block.clone());
  clone.line = this.line;
  clone.attrs = this.attrs;
  clone.textOnly = this.textOnly;
  return clone;
};
 
/**
 * Check if this tag is an inline tag.
 *
 * @return {Boolean}
 * @api private
 */
 
Tag.prototype.isInline = function(){
  return ~inlineTags.indexOf(this.name);
};
 
/**
 * Check if this tag's contents can be inlined.  Used for pretty printing.
 *
 * @return {Boolean}
 * @api private
 */
 
Tag.prototype.canInline = function(){
  var nodes = this.block.nodes;
 
  function isInline(node){
    // Recurse if the node is a block
    if (node.isBlock) return node.nodes.every(isInline);
    return node.isText || (node.isInline && node.isInline());
  }
 
  // Empty tag
  if (!nodes.length) return true;
 
  // Text-only or inline-only tag
  if (1 == nodes.length) return isInline(nodes[0]);
 
  // Multi-line inline-only tag
  if (this.block.nodes.every(isInline)) {
    for (var i = 1, len = nodes.length; i < len; ++i) {
      if (nodes[i-1].isText && nodes[i].isText)
        return false;
    }
    return true;
  }
 
  // Mixed tag
  return false;
};