2011-01-10 06:18:05 +00:00
function showInstallCommand ( ) {
var cmd = $ ( "#existence" ) . val ( ) ;
var commands = [ ] ;
var notes = [ ] ;
var project _name = "<myproject>" ;
var can _be _bare = true ;
commands . push ( "$ gem install compass" ) ;
if ( cmd == "init" ) {
commands . push ( "$ cd " + project _name ) ;
project _name = "." ;
}
if ( $ ( "#app-type" ) . val ( ) == "rails" ) {
if ( cmd == "create" ) {
commands . push ( "$ rails new " + project _name ) ;
}
cmd = "init rails" ;
can _be _bare = false ;
} else if ( $ ( "#app-type" ) . val ( ) == "other" ) {
if ( cmd == "init" ) {
cmd = "create" ;
}
} else if ( $ ( "#app-type" ) . val ( ) == "stand-alone" ) {
if ( cmd == "init" ) {
cmd = "install" ;
can _be _bare = false ;
}
}
var framework = $ ( "#framework" ) . val ( ) ;
var create _command ;
if ( cmd == "install" ) {
create _command = "$ compass install " + framework + " " + project _name ;
} else {
create _command = "$ compass " + cmd + " " + project _name ;
}
if ( framework != "compass" && framework != "bare" && cmd != "install" ) {
create _command = create _command + " --using " + framework ;
} else if ( framework == "bare" ) {
if ( can _be _bare ) {
create _command = create _command + " --bare" ;
} else {
notes . push ( "<p class='note warning'>You cannot create a bare project in this configuration. Feel free to remove any stylesheets that you don't want.</p>" ) ;
}
}
if ( $ ( "#syntax" ) . val ( ) == "sass" ) {
create _command = create _command + " --syntax sass" ;
}
if ( $ ( "#options" ) . val ( ) == "customized" ) {
2011-03-21 07:57:07 +00:00
$ ( "#directories" ) . show ( ) ;
create _command = create _command +
" --sass-dir \"" + $ ( "#sassdir" ) . val ( ) + "\"" +
" --css-dir \"" + $ ( "#cssdir" ) . val ( ) + "\"" +
" --javascripts-dir \"" + $ ( "#jsdir" ) . val ( ) + "\"" +
" --images-dir \"" + $ ( "#imagesdir" ) . val ( ) + "\"" ;
} else {
$ ( "#directories" ) . hide ( ) ;
2011-01-10 06:18:05 +00:00
}
commands . push ( create _command ) ;
var instructions = "<pre><code>" + commands . join ( "\n" ) + "</code></pre>" ;
if ( instructions . match ( /</ ) ) {
notes . push ( "<p class='note'>Note: Values indicated by <> are placeholders. Change them to suit your needs.</em>" ) ;
}
$ ( "#steps" ) . html ( instructions + notes . join ( "" ) ) ;
}
function attachMadlibBehaviors ( ) {
$ ( "#app-type" ) . change ( function ( event ) {
var val = $ ( event . target ) . val ( ) ;
if ( val == "other" ) {
$ ( "#options" ) . val ( "customized" ) ;
$ ( ".madlib" ) . addClass ( "customizable" ) ;
} else if ( val == "rails" ) {
$ ( "#options" ) . val ( "default" ) ;
$ ( ".madlib" ) . removeClass ( "customizable" ) ;
} else {
$ ( ".madlib" ) . addClass ( "customizable" ) ;
}
} ) ;
$ ( "#existence, #app-type, #framework, #syntax, #options" ) . change ( showInstallCommand ) ;
2011-03-21 07:57:07 +00:00
$ ( ".madlib input" ) . keyup ( function ( ) { setTimeout ( showInstallCommand , 0.1 ) } ) ;
2011-01-10 06:18:05 +00:00
}
function setupMadlib ( ) {
attachMadlibBehaviors ( ) ;
showInstallCommand ( ) ;
}
$ ( setupMadlib ) ;