lib/code-generator.js
function(block, parent) {
    if (!block.nodes.length) return false;

    // line count
    var lines = block.nodes[block.nodes.length - 1].line - block.nodes[0].line + 1;
    if (lines === 1) return false;

    // word count of Text node values
    var words = 0;
    // number of Code nodes that are in their own lines
    var codesWithOwnLine = 0;
    // if the previous node was the first in its line
    var prevStartLine = false;

    for (var i = 0; i < block.nodes.length; i++) {
      var node = block.nodes[i];
      var prev = block.nodes[i - 1] || parent || {line: -1};
      var next = block.nodes[i];

      if (node.type === 'Text') {
        words += (node.val.match(/\w+(\s+|$)/g) || []).length;
      } else if (node.type === 'Code' && node.buffer && !node.block) {
        if ((node.line > prev.line || prev.type === 'Text' && prev.val === '\n') && prevStartLine) {
          codesWithOwnLine++;
        }
      } else {
        // Technically Tags can also be interpolated, but determine whether to
        // use multiple dot blocks or one single dot block is way too
        // complicated. KISS.
        return false;
      }
      prevStartLine = node.line > prev.line || prev.type === 'Text' && prev.val === '\n';
    }

    return words > 0 && codesWithOwnLine / lines < 0.35;
  }
function(block, parent) {
    if (!block.nodes.length) return false;

    // line count
    var lines = block.nodes[block.nodes.length - 1].line - block.nodes[0].line + 1;
    if (lines === 1) return false;

    // word count of Text node values
    var words = 0;
    // number of Code nodes that are in their own lines
    var codesWithOwnLine = 0;
    // if the previous node was the first in its line
    var prevStartLine = false;

    for (var i = 0; i < block.nodes.length; i++) {
      var node = block.nodes[i];
      var prev = block.nodes[i - 1] || parent || {line: -1};
      var next = block.nodes[i];

      if (node.type === 'Text') {
        words += (node.val.match(/\w+(\s+|$)/g) || []).length;
      } else if (node.type === 'Code' && node.buffer && !node.block) {
        if ((node.line > prev.line || prev.type === 'Text' && prev.val === '\n') && prevStartLine) {
          codesWithOwnLine++;
        }
      } else {
        // Technically Tags can also be interpolated, but determine whether to
        // use multiple dot blocks or one single dot block is way too
        // complicated. KISS.
        return false;
      }
      prevStartLine = node.line > prev.line || prev.type === 'Text' && prev.val === '\n';
    }

    return words > 0 && codesWithOwnLine / lines < 0.35;
  }
function ( block , parent ) { if ( ! block . nodes . length ) return false ; // line count var lines = block . nodes [ block . nodes . length - 1 ] . line - block . nodes [ 0 ] . line + 1 ; if ( lines === 1 ) return false ; // word count of Text node values var words = 0 ; // number of Code nodes that are in their own lines var codesWithOwnLine = 0 ; // if the previous node was the first in its line var prevStartLine = false ; for ( var i = 0 ; i < block . nodes . length ; i ++ ) { var node = block . nodes [ i ] ; var prev = block . nodes [ i - 1 ] || parent || { line : - 1 } ; var next = block . nodes [ i ] ; if ( node . type === 'Text' ) { words += ( node . val . match ( / \w+(\s+|$) / g ) || [ ] ) . length ; } else if ( node . type === 'Code' && node . buffer && ! node . block ) { if ( ( node . line > prev . line || prev . type === 'Text' && prev . val === '\n' ) && prevStartLine ) { codesWithOwnLine ++ ; } } else { // Technically Tags can also be interpolated, but determine whether to // use multiple dot blocks or one single dot block is way too // complicated. KISS. return false ; } prevStartLine = node . line > prev . line || prev . type === 'Text' && prev . val === '\n' ; } return words > 0 && codesWithOwnLine / lines < 0.35 ; }
heuristics to determine if dot syntax is preferred over piped text
heuristics to determine if dot syntax is preferred over piped text