Permalink
Browse files

Factored out the view master creation. Tweaked the view, action and c…

…ontroller creation so that rendered pages are more sensible when the app name is unknown.
  • Loading branch information...
1 parent 50b3074 commit c7417d965ebd34e62f83c609bdc72f618ae4ba6a @thatismatt committed Jun 11, 2010
Showing with 26 additions and 20 deletions.
  1. +26 −20 lib/josi/tasks/create.js
View
@@ -71,18 +71,7 @@ var createApp = function(appName) {
);
createController(appName, 'home');
fs.mkdirSync(appName + '/views', 0777);
- fs.writeFileSync(appName + '/views/master.html',
- [ '<html>',
- ' <head>',
- ' <title><%= title %></title>',
- ' </head>',
- ' <body>',
- ' <h1><%= title %></h1>',
- ' <%= main %>',
- ' </body>',
- '</html>', ''
- ].join('\r\n')
- );
+ createViewMaster(appName);
createView(appName, 'home', 'index');
};
@@ -95,15 +84,15 @@ var createController = function(appName, controllerName) {
if (utilities.fileOrDirectoryExists(filename)) {
throw new Error('Controller already exists');
}
- // todo: if appname is '.' create a different index action
fs.writeFileSync(filename,
[ 'var view = require(\'josi/actionresults\').view;',
'',
'this.index = function() {',
' return view({',
- ' title: \'' + appName + ' - a josi app\',',
- ' name: \'' + appName + '\',',
- ' description: \'' + appName + ' is a <a href="http://thatismatt.github.com/josi/">josi</a> app\'',
+ ' title: \'' + (appName == '.' ? 'A josi app' : appName + ' - a josi app') + '\',',
+ ' controller: \'' + controllerName + '\',',
+ ' action: \'index\',',
+ ' description: \'' + (appName == '.' ? 'This' : appName) + ' is a <a href="http://thatismatt.github.com/josi/">josi</a> app\'',
' });',
'};', ''
].join('\r\n')
@@ -124,21 +113,38 @@ var createView = function(appName, controllerName, viewName) {
throw new Error('View already exists');
}
fs.writeFileSync(filename,
- [ '<p>App name: <b><%= name %></b></p>',
+ [ '<p>Controller: <b><%= controller %></b></p>',
+ '<p>Action: <b><%= action %></b></p>',
'<p><%= description %></p>', ''
].join('\r\n')
);
};
+var createViewMaster = function(appName) {
+ fs.writeFileSync(appName + '/views/master.html',
+ [ '<html>',
+ ' <head>',
+ ' <title><%= title %></title>',
+ ' </head>',
+ ' <body>',
+ ' <h1><%= title %></h1>',
+ ' <%= main %>',
+ ' </body>',
+ '</html>', ''
+ ].join('\r\n')
+ );
+};
+
var addActionToController = function(controllerName, actionName) {
var writeStream = fs.createWriteStream('controllers/' + controllerName + '.js', { flags: 'a' });
writeStream.write(
[ '',
'this.' + actionName + ' = function() {',
' return view({',
- ' title: \'' + controllerName + '.' + actionName + '\',',
- ' name: \'' + controllerName + '.' + actionName + '\',',
- ' description: \'This is the ' + actionName + ' action on the ' + controllerName + ' controller.\'',
+ ' title: \'A josi app\',',
+ ' controller: \'' + controllerName + '\',',
+ ' action: \'' + actionName + '\',',
+ ' description: \'This is a <a href="http://thatismatt.github.com/josi/">josi</a> app\'',
' });',
'};', ''
].join('\r\n')

0 comments on commit c7417d9

Please sign in to comment.