lib/parser.js
function getComponents(templateSrc, filename, options){
  var $ = cheerio.load('<div>' + templateSrc + '</div>');
  var components = [];

  var nodeIndex = 0;

  $('*').contents().map(function(index, $el) {
  
    if ($el.type === 'comment') {
      var src = $el.data.trim();

      // keyword check
      if(isComponentComment(src, options.keyword)){
        src = src.substring(options.keyword.length);
        var meta = YAML.safeLoad(src) || {};
        
        var nodes = getComponentHtml($, $el, $.html($($el).nextAll()), options.keyword, meta);
        var html = nodes.filter(function(node) { 
          return (node.trim() !== '');
        }).join('\n');

        var output = render(html, meta, options.block);

        var component = {
          meta: meta,
          file: filename,
          output: output.trim()
        };

        // push comment
        return components.push(component);
      }
    }
  }.bind(this));

  return components;
}
function getComponents(templateSrc, filename, options){
  var $ = cheerio.load('<div>' + templateSrc + '</div>');
  var components = [];

  var nodeIndex = 0;

  $('*').contents().map(function(index, $el) {
  
    if ($el.type === 'comment') {
      var src = $el.data.trim();

      // keyword check
      if(isComponentComment(src, options.keyword)){
        src = src.substring(options.keyword.length);
        var meta = YAML.safeLoad(src) || {};
        
        var nodes = getComponentHtml($, $el, $.html($($el).nextAll()), options.keyword, meta);
        var html = nodes.filter(function(node) { 
          return (node.trim() !== '');
        }).join('\n');

        var output = render(html, meta, options.block);

        var component = {
          meta: meta,
          file: filename,
          output: output.trim()
        };

        // push comment
        return components.push(component);
      }
    }
  }.bind(this));

  return components;
}
function getComponents ( templateSrc , filename , options ) { var $ = cheerio . load ( '<div>' + templateSrc + '</div>' ) ; var components = [ ] ; var nodeIndex = 0 ; $ ( '*' ) . contents ( ) . map ( function ( index , $el ) { if ( $el . type === 'comment' ) { var src = $el . data . trim ( ) ; // keyword check if ( isComponentComment ( src , options . keyword ) ) { src = src . substring ( options . keyword . length ) ; var meta = YAML . safeLoad ( src ) || { } ; var nodes = getComponentHtml ( $ , $el , $ . html ( $ ( $el ) . nextAll ( ) ) , options . keyword , meta ) ; var html = nodes . filter ( function ( node ) { return ( node . trim ( ) !== '' ) ; } ) . join ( '\n' ) ; var output = render ( html , meta , options . block ) ; var component = { meta : meta , file : filename , output : output . trim ( ) } ; // push comment return components . push ( component ) ; } } } . bind ( this ) ) ; return components ; }
Returns all components for the given code
Returns all components for the given code