-
-
Save jharjono/859008 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby | |
# Libraries::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
require 'rubygems' | |
require 'sinatra/base' | |
require 'slim' | |
require 'sass' | |
require 'coffee-script' | |
# Application::::::::::::::::::::::::::::::::::::::::::::::::::: | |
class SassHandler < Sinatra::Base | |
set :views, File.dirname(__FILE__) + '/templates/sass' | |
get '/css/*.css' do | |
filename = params[:splat].first | |
sass filename.to_sym | |
end | |
end | |
class CoffeeHandler < Sinatra::Base | |
set :views, File.dirname(__FILE__) + '/templates/coffee' | |
get "/js/*.js" do | |
filename = params[:splat].first | |
coffee filename.to_sym | |
end | |
end | |
class MyApp < Sinatra::Base | |
use SassHandler | |
use CoffeeHandler | |
# Configuration::::::::::::::::::::::::::::::::::::::::::::::: | |
set :public, File.dirname(__FILE__) + '/public' | |
set :views, File.dirname(__FILE__) + '/templates' | |
# Route Handlers:::::::::::::::::::::::::::::::::::::::::::::: | |
get '/' do | |
slim :index | |
end | |
end | |
if __FILE__ == $0 | |
MyApp.run! :port => 4567 | |
end |
Thanks :)
Only a note:
:public is no longer used to avoid overloading Module#public, use :public_folder or :public_dir instead
This is great! Exactly what I needed to see while playing with Sinatra
thank you - i spent hours wrangling with AssetPipeline and Sinatra::SprocketsPipeline - this is all i needed and it works great!
of course keep in mind your use of filename.to_sym
is very insecure :) in a real production app use a whitelist before calling #to_sym
Has this worked for anybody? I have seen several tuts on how to set up assets on sinatra and non i mean non worked, i am so pissed right now, i am thinking of switching to flask. Nothing i have tried worked. Why is it so difficult????? Everybody only has this one page setup, it that all there is? I want to pack my css into its onw folder and my js too, heck i want to use foundation and nothing has work so far. Attached is my structure...
Thanks! This is killer.