Sha256: 65df4985988a909736b346cf0159dc9f13b4ac0b35f0ece2f53a66a0d34fa5e9

Contents?: true

Size: 1.79 KB

Versions: 38

Compression:

Stored size: 1.79 KB

Contents

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

/**
 * Module dependencies.
 */

var Attrs = require('./attrs'),
    Block = require('./block'),
    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) {
  this.name = name;
  this.attrs = [];
  this.block = block || new Block;
};

/**
 * Inherit from `Attrs`.
 */

Tag.prototype.__proto__ = Attrs.prototype;

/**
 * Clone this tag.
 *
 * @return {Tag}
 * @api private
 */

Tag.prototype.clone = function(){
  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;
};

Version data entries

38 entries across 38 versions & 2 rubygems

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