Skip to content
Myr

partial.js

This file

Path

lib/view/partial.js

66 lines · 1.2 KiB · JavaScript

Last changed by

moved files from lib/express/* to lib/Tj Holowaychukbefore adoption3d597a5

History of this file

Take it

moved files from lib/express/* to lib/Tj Holowaychukbefore adoption3d597a5

lines 1–66why, one step back
1
2/*!3 * Express - view - Partial4 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>5 * MIT Licensed6 */78/**9 * Module dependencies.10 */1112var View = require('./view')13 , basename = require('path').basename;1415/**16 * Memory cache.17 */1819var cache = {};2021/**22 * Initialize a new `Partial` for the given `view` and `options`.23 *24 * @param {String} view25 * @param {Object} options26 * @api private27 */2829var Partial = exports = module.exports = function Partial(view, options) {30 options = options || {};31 View.call(this, view, options);32};3334/**35 * Inherit from `View.prototype`.36 */3738Partial.prototype.__proto__ = View.prototype;3940/**41 * Resolve partial object name from the view path.42 *43 * Examples:44 *45 * "user.ejs" becomes "user"46 * "forum thread.ejs" becomes "forumThread"47 * "forum/thread/post.ejs" becomes "post"48 * "blog-post.ejs" becomes "blogPost"49 *50 * @return {String}51 * @api private52 */5354exports.resolveObjectName = function(view){55 return cache[view] || (cache[view] = view56 .split('/')57 .slice(-1)[0]58 .split('.')[0]59 .replace(/^_/, '')60 .replace(/[^a-zA-Z0-9 ]+/g, ' ')61 .split(/ +/).map(function(word, i){62 return i63 ? word[0].toUpperCase() + word.substr(1)64 : word;65 }).join(''));66};