Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 0.10.1
Fetching contributors…

Cannot retrieve contributors at this time

executable file 142 lines (118 sloc) 2.185 kb
#!/usr/bin/env bash
#
# Output usage information and exit.
#
function usage() {
echo 'usage: express [options] [dir]'
exit 1
}
#
# Create template in the givin [dir] or cwd.
#
# [dir]
#
function create_template() {
local dir=${1-.}
mkdir -p $dir
[[ $(ls $dir) ]] && confirm "$dir is not empty, continue?"
mkdir -p $dir/public/{javascripts,stylesheets,images}
mkdir -p $dir/views/partials
app_template > $dir/app.js
layout_template > $dir/views/layout.html.haml
front_template > $dir/views/front.html.haml
sass_template > $dir/views/style.css.sass
echo template created in $dir
}
#
# views/style.css.sass
#
function sass_template() {
cat <<-EOF
blue: #03ADF0
light: #4d4d4d
lighter: #eee
body
:margin 80px
:font 14px/1.5 "Helvetica Nueue", "Lucida Grande", "Arial", sans-serif
code
:padding 3px 10px
:border 1px solid !lighter
:color !light
a
:color !blue
:text-decoration none
&:hover
:text-decoration underline
EOF
}
#
# views/front.html.haml
#
function front_template() {
cat <<-EOF
%h1 Express
%p
Generated by the
<code>express</code>
executable.
%p
Visit
%a{ href: 'http://expressjs.com' } ExpressJS.com
for more information.
EOF
}
#
# views/layout.html.haml
#
function layout_template() {
cat <<-EOF
!!! strict
%html
%head
%title Express
%link{ rel: 'stylesheet', href: 'style.css' }
%body!= body
EOF
}
#
# app.js
#
function app_template() {
cat <<-EOF
// If you are using the kiwi package manager
var kiwi = require('kiwi'),
express = kiwi.require('express')
// Otherwise you will need to expose the path to express
// require.paths.unshift('path/to/express/lib')
// require('express')
configure(function(){
set('root', __dirname)
})
get('/', function(){
this.render('front.html.haml')
})
get('/*.css', function(path){
this.render(path + '.css.sass', { layout: false })
})
run()
EOF
}
#
# Confirm <msg> or exit.
#
# <msg>
#
function confirm() {
echo -n "$1 "
read answer
case $answer in
n|N|no) exit 1 ;;
y|Y|yes) ;;
*) confirm "yes or no?" ;;
esac
}
# Process arguments
case $1 in
-h|--help|help) usage ;;
*) create_template $1 ;;
esac
Jump to Line
Something went wrong with that request. Please try again.