attrs.forEach(function(attr){
      var key = attr.name;
      var escaped = attr.escaped;

      if (key !== 'class' && visited.indexOf(key) !== -1) throw new Error('Duplicate key "' + key + '" is not allowed.');
      visited.push(key);

      if (key === 'class') {
        classes.push(attr.val);
        classEscaping.push(attr.escaped);
      } else if (isConstant(attr.val)) {
        if (buffer) {
          this.buffer(runtime.attr(key, toConstant(attr.val), escaped, this.terse));
        } else {
          var val = toConstant(attr.val);
          if (escaped && !(key.indexOf('data') === 0 && typeof val !== 'string')) {
            val = runtime.escape(val);
          }
          buf.push(JSON.stringify(key) + ': ' + JSON.stringify(val));
        }
      } else {
        if (buffer) {
          this.bufferExpression('jade.attr("' + key + '", ' + attr.val + ', ' + JSON.stringify(escaped) + ', ' + JSON.stringify(this.terse) + ')');
        } else {
          var val = attr.val;
          if (escaped && !(key.indexOf('data') === 0)) {
            val = 'jade.escape(' + val + ')';
          } else if (escaped) {
            val = '(typeof (jade.interp = ' + val + ') == "string" ? jade.escape(jade.interp) : jade.interp)"';
          }
          buf.push(JSON.stringify(key) + ': ' + val);
        }
      }
    }.bind(this));
Beispiel #2
0
  return attrs.map(function( attr ){

    if( isConstant( attr.val ) ){
      return attr;
    }
    attr.escaped = false;
    attr.val = util.format( "'{%s}'", attr.val );
    return attr;
  });
Beispiel #3
0
 attrs.forEach(function (attr) {
   var key = attr.name;
   var escaped = attr.escaped;
   if (key === 'class') {
     classes.push(attr.val);
     classEscaping.push(attr.escaped);
   } else if (isConstant(attr.val)) {
     this.buffer(runtime.attr(key, toConstant(attr.val), escaped, this.terse));
   } else {
     this.bufferExpression('jade.attr("' + key + '", ' + attr.val + ', ' + JSON.stringify(escaped) + ', ' + JSON.stringify(this.terse) + ')');
   }
 }.bind(this));
Beispiel #4
0
 bufferExpression: function (src) {
   var fn = Function('', 'return (' + src + ');');
   if (isConstant(src)) {
     return this.buffer(fn(), false)
   }
   if (this.lastBufferedIdx == this.buf.length) {
     if (this.lastBufferedType === 'text') this.lastBuffered += '"';
     this.lastBufferedType = 'code';
     this.lastBuffered += ' + (' + src + ')';
     this.buf[this.lastBufferedIdx - 1] = 'buf.push(' + this.bufferStartChar + this.lastBuffered + ');'
   } else {
     this.buf.push('buf.push(' + src + ');');
     this.lastBufferedType = 'code';
     this.bufferStartChar = '';
     this.lastBuffered = '(' + src + ')';
     this.lastBufferedIdx = this.buf.length;
   }
 },
Beispiel #5
0
    jade.Compiler.prototype.attrs = function(attrs, buffer) {
      for (var index = attrs.length - 1;index >= 0;--index) {
          var attr = attrs[index];
          var key = attr.name;
          var escaped = attr.escaped;
          var val = attr.val;
          if (!isConstant(val)) {
              var needEcho = true;
              if (val.substring(0,1) === '-') {
                  needEcho = false;
                  val = val.substring(1);
              }
              if (escaped && needEcho) {
                  val = 'htmlspecialchars(' + val + ', ENT_QUOTES, \'UTF-8\')';
              }

              if (needEcho) {
                  val = '"<?php echo ' + val + '; ?>"';
              } else {
                  val = '"<?php ' + val + '; ?>"';
              }

              attr.escaped = false;
              attr.val = val;
          }
          if (this.options.usestrip && key.lastIndexOf('__pairstrip', 0) === 0) {
              // support __pairstrip attribute
              var val = stripquotes(val);

              attrs.splice(index, 1);
              if(buffer) {
                  this.buffer(" " + val + " ");
              } else {
                  buf.push(" " + val + " ");
              }
          }
      }

      return this.exAttrs(attrs, buffer);

    };
Beispiel #6
0
        attrs.forEach(function(attr){
            if (attr.name == 'attributes') {
                return inherits = true;
            }

            escaped[attr.name] = attr.escaped;
            if (attr.name == 'class') {
                classes.push('(' + attr.val + ')');
            } else {
                var val = attr.val;
                if (!isConstant(val)) {
                    if (attr.escaped) {
                        val = 'htmlspecialchars(' + val + ', ENT_QUOTES, \'UTF-8\')';
                    }

                    val = '"<?php echo ' + val + '; ?>"';
                    escaped[attr.name] = false;
                }

                var pair = "'" + attr.name + "':(" + val + ')';
                buf.push(pair);
            }
        });
Beispiel #7
0
 , constant = attrs.every(function(attr){ return isConstant(attr.val) })
Beispiel #8
0
function isConstant(src) {
  // return constantinople(str);
  return constantinople(src, {pug: runtime, 'pug_interp': undefined});
}
Beispiel #9
0
function isConstant(src) {
  return constantinople(src, {jade: runtime, 'jade_interp': undefined});
}
Beispiel #10
0
function isConstant(str) {
  return constantinople(str);
}