From 86b06e9b6f63a17e77fa2864b3bcca448ce750db Mon Sep 17 00:00:00 2001 From: Thomas Klemm Date: Tue, 3 Jan 2012 21:10:54 +0100 Subject: [PATCH 1/4] renamed :public to :public_folder accoring to sinatra api change, in order to prevent deprecation warning --- app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.rb b/app.rb index 37e5172..ad5d65c 100755 --- a/app.rb +++ b/app.rb @@ -9,7 +9,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 From 9da1106cf374a6e38683c41be053d6cf9a48fcc8 Mon Sep 17 00:00:00 2001 From: Toby Foster Date: Tue, 29 Jan 2013 18:26:48 +0000 Subject: [PATCH 2/4] Add coffeescript Require coffee-script Add tasks to compile, watch coffee scripts Convert public/javascripts/application.js to coffeescript --- Gemfile | 5 ++- Gemfile.lock | 8 +++++ app.rb | 3 +- public/javascripts/application.js | 16 +++++----- tasks/scripts.rake | 48 ++++++++++++++++++++++++++++ views/javascripts/application.coffee | 4 +++ 6 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 tasks/scripts.rake create mode 100644 views/javascripts/application.coffee 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 ad5d65c..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' @@ -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..881cf0e --- /dev/null +++ b/tasks/scripts.rake @@ -0,0 +1,48 @@ +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 compile new changes without closures" + task :bare => :clear do + system "coffee -o public/javascripts/ -cbw views/javascripts/" + end + end + + namespace :compile do + task :default => :clear do + puts "*** Compiling scripts ***" + system "coffee -o public/javascripts/ -c views/javascripts/" + end + + desc "Join and compile the scripts" + task :join => :clear do + puts "*** Compiling scripts ***" + system "coffee -o public/javascripts/ -cj views/javascripts/" + end + + desc "Join and compile the scripts without closures" + task :bare => :clear do + puts "*** Compiling scripts ***" + system "coffee -o public/javascripts/ -cb views/javascripts/" + end + 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') From 820025720f001c67c1bd8cd2225250a46ebec319 Mon Sep 17 00:00:00 2001 From: Toby Foster Date: Tue, 29 Jan 2013 18:29:39 +0000 Subject: [PATCH 3/4] Correct description of rake scripts:compile:bare --- tasks/scripts.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/scripts.rake b/tasks/scripts.rake index 881cf0e..0451b03 100644 --- a/tasks/scripts.rake +++ b/tasks/scripts.rake @@ -39,7 +39,7 @@ namespace :scripts do system "coffee -o public/javascripts/ -cj views/javascripts/" end - desc "Join and compile the scripts without closures" + desc "Compile the scripts without closures" task :bare => :clear do puts "*** Compiling scripts ***" system "coffee -o public/javascripts/ -cb views/javascripts/" From 43233959a8a4183bd868feef80e28a59b6ce9cda Mon Sep 17 00:00:00 2001 From: Toby Foster Date: Tue, 29 Jan 2013 23:08:59 +0000 Subject: [PATCH 4/4] Fix broken compile tasks, add new compile and watch tasks Join and/or bare tasks for both compile and watch scripts --- tasks/scripts.rake | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tasks/scripts.rake b/tasks/scripts.rake index 0451b03..d589a43 100644 --- a/tasks/scripts.rake +++ b/tasks/scripts.rake @@ -21,28 +21,51 @@ namespace :scripts do system "coffee -o public/javascripts/ -cw views/javascripts/" end - desc "Watch the scripts and compile new changes without closures" + 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/" + 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 -o public/javascripts/ -cj views/javascripts/" + 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/" + 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