Skip to content

Commit

Permalink
Added -c, -css ENGINE option to express(1)
Browse files Browse the repository at this point in the history
For example $ express
will now just create style.css

where as $ express --css sass
will generate style.sass for you and setup the compiler middleware

etc
  • Loading branch information
tj committed Oct 20, 2010
1 parent e09bf5c commit 7bb466d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
62 changes: 56 additions & 6 deletions bin/express
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ var version = '1.0.0rc4';

var stdin;

/**
* CSS engine to utilize.
*/

var cssEngine = 'none';

/**
* Usage documentation.
*/
Expand All @@ -28,8 +34,9 @@ var usage = ''
+ '\x1b[1mUsage\x1b[0m: express [options] [PATH]\n'
+ '\n'
+ '\x1b[1mOptions\x1b[0m:\n'
+ ' -v, --version Output framework version\n'
+ ' -h, --help Output help information\n';
+ ' -c, --css ENGINE Utilize stylesheet ENGINE (less|sass). Defaults to plain css\n'
+ ' -v, --version Output framework version\n'
+ ' -h, --help Output help information\n';

/**
* Jade layout template.
Expand All @@ -44,17 +51,38 @@ var jadeLayout = [
, ' body!= body'
].join('\n');

/**
* Default css template.
*/

var css = [
'body {'
, ' padding: 50px;'
, ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;'
, '}'
].join('\n');

/**
* Default less template.
*/

var less = [
'body {'
, ' padding: 50px;'
, ' font: 14px "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;'
, ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;'
, '}'
].join('\n');

/**
* Default sass template.
*/

var sass = [
'body'
, ' :padding 50px'
, ' :font 14px "Lucida Grande", Helvetica, Arial, sans-serif'
].join('\n');

/**
* Jade index template.
*/
Expand Down Expand Up @@ -110,8 +138,7 @@ var app = [
, ' app.set(\'views\', __dirname + \'/views\');'
, ' app.set(\'view engine\', \'jade\');'
, ' app.use(express.bodyDecoder());'
, ' app.use(express.methodOverride());'
, ' app.use(express.compiler({ src: __dirname + \'/public\', enable: [\'less\'] }));'
, ' app.use(express.methodOverride());__CSS__'
, ' app.use(app.router);'
, ' app.use(express.staticProvider(__dirname + \'/public\'));'
, '});'
Expand Down Expand Up @@ -159,6 +186,12 @@ while (args.length) {
case '--version':
abort(version);
break;
case '-c':
case '--css':
args.length
? (cssEngine = args.shift())
: abort('--css requires an argument');
break;
default:
path = arg;
}
Expand Down Expand Up @@ -196,7 +229,16 @@ function createApplicationAt(path) {
mkdir(path + '/public/javascripts');
mkdir(path + '/public/images');
mkdir(path + '/public/stylesheets', function(){
write(path + '/public/stylesheets/style.less', less);
switch (cssEngine) {
case 'less':
write(path + '/public/stylesheets/style.less', less);
break;
case 'sass':
write(path + '/public/stylesheets/style.sass', sass);
break;
default:
write(path + '/public/stylesheets/style.css', css);
}
});
mkdir(path + '/views/partials', function(){
write(path + '/views/layout.jade', jadeLayout);
Expand All @@ -205,6 +247,14 @@ function createApplicationAt(path) {
mkdir(path + '/test', function(){
write(path + '/test/app.test.js', appTest);
});
switch (cssEngine) {
case 'sass':
case 'less':
app = app.replace('__CSS__', '\n app.use(express.compiler({ src: __dirname + \'/public\', enable: [\'' + cssEngine + '\'] }));');
break;
default:
app = app.replace('__CSS__', '');
}
write(path + '/app.js', app);
});
}
Expand Down
3 changes: 2 additions & 1 deletion docs/executable.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## Synopsis

express [-h|--help] [-v|--version] [PATH]
express [-h|--help] [-v|--version] [-c|-css ENGINE] [PATH]

## Description

Expand All @@ -11,6 +11,7 @@ application structure, this executable creates a maintainable base app.

## Options

-c, --css ENGINE Utilize css ENGINE (less|sass). Defaults to plain css
-v, --version Output framework version
-h, --help Display help information

0 comments on commit 7bb466d

Please sign in to comment.