<commit_before>
// Express - View - Copyright <NAME> <<EMAIL>> (MIT Licensed)

/**
 * Module dependencies.
 */

var posix = require('posix'),
    utils = require('express/utils')

/**
 * Supported template engines.
 */

var engine = {
  ejs: require('ejs'),
  haml: require('haml'),
  sass: require('sass')
}

// --- View

exports.View = Plugin.extend({
  extend: {
    
    /**
     * Initialize extensions.
     */
    
    init: function() {
      
      // Settings
      
      set('views', function(){ return set('root') + '/views' })
      
      // Request
      
      Request.include({

        /**
         * Render _view_ with _options_.
         *
         * Views are looked up relative to the'views' path setting. 
         * View filenames should conform to ANY.ENGINE.TYPE so for example
         * 'layout.ejs.html', 'ejs' represents the template engine, 'html'
         * represents the type of content being rendered, which is then passed
         * to contentType().
         *
         * Engines must export a render() method accepting the template string
         * and a hash of options.
         *
         * Options:
         *
         *  - layout:   Whether or not to use a layout. Defaults to true
         *  - context:  Most engines support an evaluation context (the 'this' keyword)
         *  - locals:   Most engines support a hash of local variable names / values.
         *
         * @param  {string} view
         * @param  {hash} options
         * @settings 'views', 'cache view contents'
         * @api public
         */

        render: function(view, options) {
          var self = this,
              options = options || {},
              path = set('views') + '/' + view,
              type = path.split('.').slice(-2)[0],
              ext = utils.extname(path),
              layout = options.layout === undefined ? true : options.layout
          self.contentType(ext)
          function render(content) {
            content = engine[type].render(content, options)
            if (layout)
              self.render('layout.' + type + '.' + ext, process.mixin(true, options, {
                layout: false,
                locals: {
                  body: content
                }
              }))<commit_msg>Added alternate layout support. Closes #119<commit_after>
// Express - View - Copyright <NAME> <<EMAIL>> (MIT Licensed)

/**
 * Module dependencies.
 */

var posix = require('posix'),
    utils = require('express/utils')

/**
 * Supported template engines.
 */

var engine = {
  ejs: require('ejs'),
  haml: require('haml'),
  sass: require('sass')
}

// --- View

exports.View = Plugin.extend({
  extend: {
    
    /**
     * Initialize extensions.
     */
    
    init: function() {
      
      // Settings
      
      set('views', function(){ return set('root') + '/views' })
      
      // Request
      
      Request.include({

        /**
         * Render _view_ with _options_.
         *
         * Views are looked up relative to the'views' path setting. 
         * View filenames should conform to ANY.ENGINE.TYPE so for example
         * 'layout.ejs.html', 'ejs' represents the template engine, 'html'
         * represents the type of content being rendered, which is then passed
         * to contentType().
         *
         * Engines must export a render() method accepting the template string
         * and a hash of options.
         *
         * Options:
         *
         *  - layout:   The layout to use, none when falsey. Defaults to 'layout'
         *  - context:  Most engines support an evaluation context (the 'this' keyword)
         *  - locals:   Most engines support a hash of local variable names / values.
         *
         * @param  {string} view
         * @param  {hash} options
         * @settings 'views', 'cache view contents'
         * @api public
         */

        render: function(view, options) {
          var self = this,
              options = options || {},
              path = set('views') + '/' + view,
              type = path.split('.').slice(-2)[0],
              ext = utils.extname(path),
              layout = options.layout === undefined ? 'layout' : options.layout
          self.contentType(ext)
          function render(content) {
            content = engine[type].render(content, options)
            if (layout)
              self.render(layout + '.' + type + '.' + ext, process.mixin(true, options, {
                layout: false,
                locals: {
                  body: content
                }
              }))
{'fraction_non_alphanumeric': 0.1222707423580786, 'fraction_numerical': 0.0015283842794759825, 'mean_word_length': 1.6373056994818653, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6408941', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1216, 'n_words': 371}