Skip to content

Commit

Permalink
fix(view) view generator generates jade templates
Browse files Browse the repository at this point in the history
A jade template will be generated when the app is configured
to use jade
  • Loading branch information
Gonzalo Ruiz de Villa committed Sep 6, 2013
1 parent 53a4d4e commit 5574ec9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions templates/common/view.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p This is the <%= name %> view.
2 changes: 2 additions & 0 deletions view/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Example:

This will create:
app/views/thing.html
or
app/jade/views/thing.jade
37 changes: 34 additions & 3 deletions view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var path = require('path');
var util = require('util');
var yeoman = require('yeoman-generator');
var fs = require('fs');


module.exports = Generator;
Expand All @@ -21,9 +22,39 @@ function Generator() {
util.inherits(Generator, yeoman.generators.NamedBase);

Generator.prototype.createViewFiles = function createViewFiles() {
var targetPath = this.name;
if (this.name.indexOf('/') === -1) {
var data;
var appPath = this.env.options.appPath;
var fullPathJade = path.join(appPath, 'jade/index.jade');
if (fs.existsSync(fullPathJade)) {
data = createJadeViewFiles(this.name, this.env);
}else {
data = createHtmlViewFiles(this.name, this.env);
}
this.template(data.template, data.targetPath);

}

function createHtmlViewFiles(name, env) {
var targetPath = name;
if (name.indexOf('/') === -1) {
targetPath = 'views/' + targetPath;
}
this.template('common/view.html', path.join(this.env.options.appPath, targetPath + '.html'));
targetPath = path.join(env.options.appPath, targetPath + '.html');
return {
targetPath: targetPath,
template: 'common/view.html',
}
};

function createJadeViewFiles(name, env) {
var targetPath = name;
if (name.indexOf('/') === -1) {
targetPath = 'jade/views/' + targetPath;
}
targetPath = path.join(env.options.appPath, targetPath + '.jade');
return {
targetPath: targetPath,
template: 'common/view.jade',
}
};

0 comments on commit 5574ec9

Please sign in to comment.