lib/application.js
function setupViewPartials() {
  
  // Set view path association object
  this.views.pathAsoc = {};

  // Partial & template regexes
  var self = this;
  var exts = this.templateExtensions;
  var partialRegex = new RegExp('\/views\/(.+)\/partials\/[a-zA-Z0-9-_]+\\.(' + exts.join('|') + ')$');
  var templateRegex = new RegExp('\\.(' + exts.join('|') + ')$');
  var layoutPath = this.mvcpath + 'views/' + this.paths.layout;

  var viewsPath = this.mvcpath + 'views';
  
  var partialPaths = [];
  
  if (fs.existsSync(viewsPath)) {
    
    fileModule.walkSync(viewsPath, function(dirPath, dirs, files) {
      
      for (var path,file,i=0; i < files.length; i++) {

        file = files[i];
        path = dirPath + "/" + file;

        if (partialRegex.test(path)) {

          // Only build valid partial views
          partialPaths.push(path);
          buildPartialView.call(self, path);
          watchPartial.call(self, path, buildPartialView);

        } else if (templateRegex.test(file)) {

          // Build partial views for everything inside app.paths.layout

          if (path.indexOf(layoutPath) === 0) {
            partialPaths.push(path);
            buildPartialView.call(self, path);
            watchPartial.call(self, path, buildPartialView);
          }

          // Only add valid templates to view associations
          self.views.pathAsoc[self.relPath(path.replace(self.regex.templateFile, ''))] = path;

        }
      }
    });
    
  }
  
  // Add Builtin Partials
  
  var Helper = protos.lib.helper;
  var builtinHelper = new Helper();
  
  for (var m in builtinHelper) {
    if (builtinHelper[m] instanceof Function) {
      this.registerViewHelper(m, builtinHelper[m], builtinHelper);
    }
  }
  
  // Helper Partials
  
  Object.keys(this.helpers).forEach(function(alias) {
    var m, method, hkey, helper = self.helpers[alias];
    for (m in helper) {
      if (helper[m] instanceof Function) {
        method = helper[m];
        hkey = (alias == 'main')
          ? util.format('%s', m)
          : util.format('%s_%s', alias, m);
        self.registerViewHelper(hkey, method, helper);
      }
    }
  });
  
  // Event when view partials are loaded

  this.emit('view_partials_loaded', this.views.partials);
  
  // Set shortcode context
  // NOTE: Automatically resets on hot code loading, so it's good.
  
  var shortcodeContext = this.__shortcodeContext = {};
  
  // Only add shortcode filter to context if enabled on config
  
  if (this.config.shortcodeFilter) {
    
    // Register shortcodes from partials
  
    var shortcode = self.shortcode;
    var partials = self.views.partials;
  
    Object.keys(this.views.partials).forEach(function(partial) {
      if (partial[0] === '$') {
        shortcodeContext[partial.replace(/^\$/, '#')] = self.views.partials[partial];
      } else {
        shortcodeContext[partial] = function(buf, params, locals) {
          if (buf) params.content = buf; // Provide wrapped content in params.content
          params.__proto__ = locals; // Set locals as prototype of params
          return partials[partial].call(null, params); // Provide params to partial, which is passed as locals
        }
      }
    });

    this.addFilter('context', function(buf, locals) {
      buf = this.shortcode.parse(buf, locals, shortcodeContext);
      return buf;
    });
    
  }
  
  // Event when view shortcodes are loaded

  this.emit('view_shortcodes_loaded', shortcodeContext);

}
function setupViewPartials() {
  
  // Set view path association object
  this.views.pathAsoc = {};

  // Partial & template regexes
  var self = this;
  var exts = this.templateExtensions;
  var partialRegex = new RegExp('\/views\/(.+)\/partials\/[a-zA-Z0-9-_]+\\.(' + exts.join('|') + ')$');
  var templateRegex = new RegExp('\\.(' + exts.join('|') + ')$');
  var layoutPath = this.mvcpath + 'views/' + this.paths.layout;

  var viewsPath = this.mvcpath + 'views';
  
  var partialPaths = [];
  
  if (fs.existsSync(viewsPath)) {
    
    fileModule.walkSync(viewsPath, function(dirPath, dirs, files) {
      
      for (var path,file,i=0; i < files.length; i++) {

        file = files[i];
        path = dirPath + "/" + file;

        if (partialRegex.test(path)) {

          // Only build valid partial views
          partialPaths.push(path);
          buildPartialView.call(self, path);
          watchPartial.call(self, path, buildPartialView);

        } else if (templateRegex.test(file)) {

          // Build partial views for everything inside app.paths.layout

          if (path.indexOf(layoutPath) === 0) {
            partialPaths.push(path);
            buildPartialView.call(self, path);
            watchPartial.call(self, path, buildPartialView);
          }

          // Only add valid templates to view associations
          self.views.pathAsoc[self.relPath(path.replace(self.regex.templateFile, ''))] = path;

        }
      }
    });
    
  }
  
  // Add Builtin Partials
  
  var Helper = protos.lib.helper;
  var builtinHelper = new Helper();
  
  for (var m in builtinHelper) {
    if (builtinHelper[m] instanceof Function) {
      this.registerViewHelper(m, builtinHelper[m], builtinHelper);
    }
  }
  
  // Helper Partials
  
  Object.keys(this.helpers).forEach(function(alias) {
    var m, method, hkey, helper = self.helpers[alias];
    for (m in helper) {
      if (helper[m] instanceof Function) {
        method = helper[m];
        hkey = (alias == 'main')
          ? util.format('%s', m)
          : util.format('%s_%s', alias, m);
        self.registerViewHelper(hkey, method, helper);
      }
    }
  });
  
  // Event when view partials are loaded

  this.emit('view_partials_loaded', this.views.partials);
  
  // Set shortcode context
  // NOTE: Automatically resets on hot code loading, so it's good.
  
  var shortcodeContext = this.__shortcodeContext = {};
  
  // Only add shortcode filter to context if enabled on config
  
  if (this.config.shortcodeFilter) {
    
    // Register shortcodes from partials
  
    var shortcode = self.shortcode;
    var partials = self.views.partials;
  
    Object.keys(this.views.partials).forEach(function(partial) {
      if (partial[0] === '$') {
        shortcodeContext[partial.replace(/^\$/, '#')] = self.views.partials[partial];
      } else {
        shortcodeContext[partial] = function(buf, params, locals) {
          if (buf) params.content = buf; // Provide wrapped content in params.content
          params.__proto__ = locals; // Set locals as prototype of params
          return partials[partial].call(null, params); // Provide params to partial, which is passed as locals
        }
      }
    });

    this.addFilter('context', function(buf, locals) {
      buf = this.shortcode.parse(buf, locals, shortcodeContext);
      return buf;
    });
    
  }
  
  // Event when view shortcodes are loaded

  this.emit('view_shortcodes_loaded', shortcodeContext);

}
function setupViewPartials ( ) { // Set view path association object this . views . pathAsoc = { } ; // Partial & template regexes var self = this ; var exts = this . templateExtensions ; var partialRegex = new RegExp ( '\/views\/(.+)\/partials\/[a-zA-Z0-9-_]+\\.(' + exts . join ( '|' ) + ')$' ) ; var templateRegex = new RegExp ( '\\.(' + exts . join ( '|' ) + ')$' ) ; var layoutPath = this . mvcpath + 'views/' + this . paths . layout ; var viewsPath = this . mvcpath + 'views' ; var partialPaths = [ ] ; if ( fs . existsSync ( viewsPath ) ) { fileModule . walkSync ( viewsPath , function ( dirPath , dirs , files ) { for ( var path , file , i = 0 ; i < files . length ; i ++ ) { file = files [ i ] ; path = dirPath + "/" + file ; if ( partialRegex . test ( path ) ) { // Only build valid partial views partialPaths . push ( path ) ; buildPartialView . call ( self , path ) ; watchPartial . call ( self , path , buildPartialView ) ; } else if ( templateRegex . test ( file ) ) { // Build partial views for everything inside app.paths.layout if ( path . indexOf ( layoutPath ) === 0 ) { partialPaths . push ( path ) ; buildPartialView . call ( self , path ) ; watchPartial . call ( self , path , buildPartialView ) ; } // Only add valid templates to view associations self . views . pathAsoc [ self . relPath ( path . replace ( self . regex . templateFile , '' ) ) ] = path ; } } } ) ; } // Add Builtin Partials var Helper = protos . lib . helper ; var builtinHelper = new Helper ( ) ; for ( var m in builtinHelper ) { if ( builtinHelper [ m ] instanceof Function ) { this . registerViewHelper ( m , builtinHelper [ m ] , builtinHelper ) ; } } // Helper Partials Object . keys ( this . helpers ) . forEach ( function ( alias ) { var m , method , hkey , helper = self . helpers [ alias ] ; for ( m in helper ) { if ( helper [ m ] instanceof Function ) { method = helper [ m ] ; hkey = ( alias == 'main' ) ? util . format ( '%s' , m ) : util . format ( '%s_%s' , alias , m ) ; self . registerViewHelper ( hkey , method , helper ) ; } } } ) ; // Event when view partials are loaded this . emit ( 'view_partials_loaded' , this . views . partials ) ; // Set shortcode context // NOTE: Automatically resets on hot code loading, so it's good. var shortcodeContext = this . __shortcodeContext = { } ; // Only add shortcode filter to context if enabled on config if ( this . config . shortcodeFilter ) { // Register shortcodes from partials var shortcode = self . shortcode ; var partials = self . views . partials ; Object . keys ( this . views . partials ) . forEach ( function ( partial ) { if ( partial [ 0 ] === '$' ) { shortcodeContext [ partial . replace ( / ^\$ / , '#' ) ] = self . views . partials [ partial ] ; } else { shortcodeContext [ partial ] = function ( buf , params , locals ) { if ( buf ) params . content = buf ; // Provide wrapped content in params.content params . __proto__ = locals ; // Set locals as prototype of params return partials [ partial ] . call ( null , params ) ; // Provide params to partial, which is passed as locals } } } ) ; this . addFilter ( 'context' , function ( buf , locals ) { buf = this . shortcode . parse ( buf , locals , shortcodeContext ) ; return buf ; } ) ; } // Event when view shortcodes are loaded this . emit ( 'view_shortcodes_loaded' , shortcodeContext ) ; }
Configures View Partials
Configures View Partials