diff --git a/Gemfile b/Gemfile index 9ea6e58..9143c02 100644 --- a/Gemfile +++ b/Gemfile @@ -5,9 +5,12 @@ gem 'sinatra', '~> 1.2.3' gem 'shotgun', '~> 0.9' gem 'haml', '~> 3.1.4' +# Coffeescript +gem 'coffee-script', '~> 2.2.0' + # Sass & Compass gem 'sass', '~> 3.1.12' gem 'compass', '~> 0.11.6' # Sass libraries -gem 'grid-coordinates', '~> 1.1.4' \ No newline at end of file +gem 'grid-coordinates', '~> 1.1.4' diff --git a/Gemfile.lock b/Gemfile.lock index 91a7bad..e3f1c81 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,14 +2,21 @@ GEM remote: http://rubygems.org/ specs: chunky_png (1.2.5) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.4.0) compass (0.11.6) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) + execjs (1.4.0) + multi_json (~> 1.0) fssm (0.2.7) grid-coordinates (1.1.9) compass (>= 0.11.5) haml (3.1.4) + multi_json (1.5.0) rack (1.4.0) rake (0.9.2) sass (3.1.12) @@ -24,6 +31,7 @@ PLATFORMS ruby DEPENDENCIES + coffee-script (~> 2.2.0) compass (~> 0.11.6) grid-coordinates (~> 1.1.4) haml (~> 3.1.4) diff --git a/app.rb b/app.rb index 37e5172..be240c8 100755 --- a/app.rb +++ b/app.rb @@ -1,6 +1,7 @@ require 'rubygems' require 'sinatra' require 'haml' +require 'coffee-script' # Helpers require './lib/render_partial' @@ -9,7 +10,7 @@ set :app_file, __FILE__ set :root, File.dirname(__FILE__) set :views, 'views' -set :public, 'public' +set :public_folder, 'public' set :haml, {:format => :html5} # default Haml format is :xhtml # Application routes @@ -19,4 +20,4 @@ get '/about' do haml :about, :layout => :'layouts/page' -end \ No newline at end of file +end diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 4c92ecc..efba86a 100755 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1,10 +1,10 @@ -$(document).ready(function() { +// Generated by CoffeeScript 1.4.0 +(function() { - // Open external links in a new window - hostname = window.location.hostname - $("a[href^=http]") - .not("a[href*='" + hostname + "']") - .addClass('link external') - .attr('target', '_blank'); + $(function() { + var hostname; + hostname = window.location.hostname; + return $("a[href^=http]").not("a[href*=" + hostname + "]").addClass('link external').attr('target', '_blank'); + }); -}); +}).call(this); diff --git a/tasks/scripts.rake b/tasks/scripts.rake new file mode 100644 index 0000000..d589a43 --- /dev/null +++ b/tasks/scripts.rake @@ -0,0 +1,71 @@ +namespace :scripts do + desc "Watch the scripts and compile new changes" + task :watch => ["watch:default"] + + desc "List the scripts" + task :list do + system "ls -lh public/javascripts" + end + + desc "Compile the scripts" + task :compile => ["compile:default"] + + desc "Clear the scripts" + task :clear do + puts "*** Clearing scripts ***" + system "rm -Rfv public/javascripts/*.js" + end + + namespace :watch do + task :default => :clear do + system "coffee -o public/javascripts/ -cw views/javascripts/" + end + + desc "Watch the scripts and join and compile changes" + task :join => :clear do + puts "*** Compiling scripts ***" + system "coffee -j public/javascripts/application.js -cw views/javascripts/*.coffee" + end + + desc "Watch the scripts and compile changes without closures" + task :bare => :clear do + system "coffee -o public/javascripts/ -cbw views/javascripts/" + end + + desc "Watch the scripts and join and compile changes without closures" + task :barejoin => :clear do + system "coffee -j public/javascripts/application.js -cbw views/javascripts/*.coffee" + end + + desc "Watch the scripts and join and compile changes without closures" + task :joinbare => ["compile:barejoin"] + end + + namespace :compile do + task :default => :clear do + puts "*** Compiling scripts ***" + system "coffee -o public/javascripts/ -c views/javascripts/*.coffee" + end + + desc "Join and compile the scripts" + task :join => :clear do + puts "*** Compiling scripts ***" + system "coffee -j public/javascripts/application.js -c views/javascripts/*.coffee" + end + + desc "Compile the scripts without closures" + task :bare => :clear do + puts "*** Compiling scripts ***" + system "coffee -o public/javascripts/ -cb views/javascripts/*.coffee" + end + + desc "Join and compile the scripts without closures" + task :barejoin => :clear do + puts "*** Compiling scripts ***" + system "coffee -j public/javascripts/application.js -cb views/javascripts/*.coffee" + end + + desc "Join and compile the scripts without closures" + task :joinbare => ["compile:barejoin"] + end +end diff --git a/views/javascripts/application.coffee b/views/javascripts/application.coffee new file mode 100644 index 0000000..ee77382 --- /dev/null +++ b/views/javascripts/application.coffee @@ -0,0 +1,4 @@ +$ -> + # Open external links in a new window + hostname = window.location.hostname + $("a[href^=http]").not("a[href*=#{hostname}]").addClass('link external').attr('target', '_blank')