Skip to content

Added support for theme folder #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ var renderFile = module.exports = function(file, options, fn){
options.locals.layout = layout.bind(options);
options.locals.partial = partial.bind(options);

//Check if the theme folder is set in options.settings['theme']
if (options.settings['theme']) {
//Get the file path relative to the theme folder by replacing the options.settings.views path with the options.settings['theme'] path
var themeFilePath = dirname(file).replace(resolve(options.settings.views), resolve(options.settings['theme']))
//If the current file exists reletive to the theme folder set the file to that path
var engine = options.settings['view engine'] || 'ejs'
, desiredExt = '.' + engine
, ext = extname(file) || desiredExt
, key = [themeFilePath, file, ext].join('-');
//Load from the cache if it's already been resolved
if (options.cache && cache[key]) file = cache[key]; console.log('template loaded from cache');
if (fs.existsSync(resolve(themeFilePath, basename(file)))) {
cache[key] = resolve(themeFilePath, basename(file));
file = resolve(themeFilePath, basename(file));
}
}

ejs.renderFile(file, options, function(err, html) {

if (err) {
Expand Down