Permalink
Browse files

sinatra + haml, sass, coffee, concat & compression

  • Loading branch information...
0 parents commit 0c4c9d5b13a49d6772a9faf96c0f51f74519847a @mislav committed Jul 4, 2011
Showing with 1,500 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +20 −0 Gemfile
  3. +77 −0 app.rb
  4. +13 −0 config.ru
  5. +807 −0 public/underscore.js
  6. +568 −0 public/zepto.js
  7. +1 −0 views/app.coffee
  8. +6 −0 views/index.haml
  9. +6 −0 views/style.sass
@@ -0,0 +1,2 @@
+.bundle
+.sass-cache
20 Gemfile
@@ -0,0 +1,20 @@
+source :rubygems
+
+gem 'sinatra'
+gem 'activesupport'
+gem 'i18n' # stupid activesupport dependency
+
+group :development do
+ gem 'shotgun'
+ gem 'thin'
+ gem 'ruby-debug', :platforms => :mri_18
+ gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :mri_19
+end
+
+gem 'haml'
+gem 'sass'
+gem 'compass'
+gem 'coffee-script'
+# gem 'therubyracer', :group => :development
+gem 'therubyracer-heroku', '~> 0.8.1.pre3', :group => :production
+gem 'uglifier'
77 app.rb
@@ -0,0 +1,77 @@
+# encoding: utf-8
+require 'sinatra'
+require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/numeric/time'
+require 'active_support/core_ext/integer/time'
+require 'active_support/core_ext/time/acts_like'
+require 'haml'
+require 'sass'
+require 'compass'
+require 'uglifier'
+require 'coffee_script'
+
+Compass.configuration do |config|
+ config.project_path = settings.root
+ config.sass_dir = 'views'
+end
+
+set :haml, format: :html5
+
+set :sass do
+ Compass.sass_engine_options.merge style: settings.production? ? :compressed : :nested,
+ cache_location: File.join(ENV['TMPDIR'], 'sass-cache')
+end
+
+configure :development do
+ set :logging, false
+end
+
+JS_ASSETS = %w[zepto.js underscore.js app.coffee]
+
+helpers do
+ def javascript_includes
+ assets = settings.production? ? 'all.js' : JS_ASSETS.map {|f| File.basename(f, '.*') + '.js' }
+ assets.map {|a| %(<script src="/#{a}"></script>) }.join("\n")
+ end
+
+ def file_mtime(name)
+ name = File.join(settings.views, name) unless name.include? '/'
+ File.mtime name
+ end
+end
+
+get "/" do
+ haml :index
+end
+
+get "/style.css" do
+ expires 1.day
+ last_modified file_mtime('style.sass')
+ sass :style
+end
+
+get "/app.js" do
+ expires 5.minutes
+ last_modified file_mtime('app.coffee')
+ coffee :app
+end
+
+# poor man's Sprockets
+get "/all.js" do
+ content_type 'application/javascript'
+
+ files = JS_ASSETS.map do |name|
+ dir = (".coffee" == File.extname(name)) ? settings.views : settings.public
+ File.join(dir, name)
+ end
+
+ expires 1.day
+ last_modified files.map {|f| file_mtime(f) }.max
+
+ contents = files.map do |name|
+ content = File.read name
+ content = CoffeeScript.compile content if ".coffee" == File.extname(name)
+ content
+ end
+ Uglifier.new.compile contents.join(";")
+end
@@ -0,0 +1,13 @@
+require 'rubygems'
+require 'bundler'
+
+Bundler.setup
+$LOAD_PATH.unshift ENV['APP_ROOT'] || File.expand_path('..', __FILE__)
+# $LOAD_PATH.unshift File.join($LOAD_PATH.first, 'lib')
+
+Encoding.default_external = 'utf-8'
+
+# require 'ruby-debug' if ENV['RACK_ENV'] == 'development'
+
+require 'app'
+run Sinatra::Application
Oops, something went wrong.

0 comments on commit 0c4c9d5

Please sign in to comment.