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 ;
2012-01-31 02:50:33 +00:00
var in _working _dir = false ;
var use _bundler = false ;
if ( $ ( "#app-type" ) . val ( ) != "rails" ) {
commands . push ( "$ gem install compass" ) ;
}
2011-01-10 06:18:05 +00:00
if ( cmd == "init" ) {
commands . push ( "$ cd " + project _name ) ;
2012-01-31 02:50:33 +00:00
in _working _dir = true
2011-01-10 06:18:05 +00:00
project _name = "." ;
2012-01-31 02:50:33 +00:00
$ ( ".creating" ) . hide ( ) ;
} else {
$ ( ".creating" ) . show ( ) ;
if ( $ ( "#project_name" ) . val ( ) != "" )
project _name = $ ( "#project_name" ) . val ( ) ;
}
if ( $ ( "#app-type" ) . val ( ) == "rails" ) {
notes . push ( "<p class='note warning'>Rails 2.3 and 3.0 users require additional installation steps. For full rails installation and upgrade instructions please refer to the compass-rails <a href='https://github.com/Compass/compass-rails/blob/master/README.md'>README</a>.</p>" ) ;
use _bundler = true ;
2011-01-10 06:18:05 +00:00
}
if ( $ ( "#app-type" ) . val ( ) == "rails" ) {
if ( cmd == "create" ) {
commands . push ( "$ rails new " + project _name ) ;
2012-01-31 02:50:33 +00:00
commands . push ( "$ cd " + project _name ) ;
in _working _dir = true
project _name = "." ;
2011-01-10 06:18:05 +00:00
}
2012-01-31 02:50:33 +00:00
commands . push ( "> Edit Gemfile and add this:" ) ;
commands . push ( " group :assets do" ) ;
commands . push ( " gem 'compass-rails'" ) ;
commands . push ( " # Add any compass extensions here" ) ;
commands . push ( " end" ) ;
commands . push ( "$ bundle" ) ;
2011-01-10 06:18:05 +00:00
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" ) {
2012-01-31 02:50:33 +00:00
create _command = "$ compass install " + framework ;
2011-01-10 06:18:05 +00:00
} else {
2012-01-31 02:50:33 +00:00
create _command = "$ compass " + cmd ;
}
if ( ! in _working _dir ) {
create _command = create _command + " " + project _name ;
2011-01-10 06:18:05 +00:00
}
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 ( ) ;
2012-01-31 02:50:33 +00:00
if ( $ ( "#sassdir" ) . val ( ) != "" )
create _command += " --sass-dir \"" + $ ( "#sassdir" ) . val ( ) + "\"" ;
if ( $ ( "#cssdir" ) . val ( ) != "" )
create _command += " --css-dir \"" + $ ( "#cssdir" ) . val ( ) + "\"" ;
if ( $ ( "#jsdir" ) . val ( ) != "" )
create _command += " --javascripts-dir \"" + $ ( "#jsdir" ) . val ( ) + "\"" ;
if ( $ ( "#imagesdir" ) . val ( ) != "" )
create _command += " --images-dir \"" + $ ( "#imagesdir" ) . val ( ) + "\"" ;
2011-03-21 07:57:07 +00:00
} else {
$ ( "#directories" ) . hide ( ) ;
2011-01-10 06:18:05 +00:00
}
2012-01-31 02:50:33 +00:00
if ( use _bundler ) {
create _command = "$ bundle exec " + create _command . replace ( /\$ / , '' ) ;
}
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 ) ;