Created
February 5, 2010 19:47
-
-
Save rufo/296149 to your computer and use it in GitHub Desktop.
This is a template prototyping app in Sinatra. Dirt simple, but hey.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'preview' | |
require 'rack' | |
run Sinatra::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
require 'rubygems' | |
require 'haml' | |
require 'compass' | |
require 'sinatra' | |
set :app_file, __FILE__ | |
set :root, File.dirname(__FILE__) | |
set :views, 'views' | |
configure do # if you don't want to use compass this can go | |
Compass.configuration do |config| | |
config.project_path = File.dirname(__FILE__) | |
config.sass_dir = File.join(Sinatra::Application.views, 'stylesheets') | |
config.http_images_path = "/images/" | |
end | |
end | |
get '/' do | |
haml :history # this is just the default page - change :history to a different file if you want a different default | |
end | |
get '/:name.html' do # if you want a different prefix - or no prefix - change .html here | |
haml :"#{params[:name]}" | |
end | |
get '/stylesheets/:name.css' do | |
content_type 'text/css' | |
sass :"stylesheets/#{params[:name]}", Compass.sass_engine_options # if you don't want Compass, comment this out | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'haml' | |
require 'compass' | |
build_ns = namespace :build do | |
task :haml do | |
Dir["views/*.haml"].each do |haml_filename| | |
puts "Processing #{haml_filename}..." | |
haml = IO.read(haml_filename) | |
html = Haml::Engine.new(haml).render | |
File.open("compiled/#{File.basename(haml_filename).sub("haml", "html")}", "w") {|f| f.write(html)} | |
end | |
end | |
task :sass do | |
Compass.configuration do |config| # remove this block if you don't want compass | |
config.project_path = File.dirname(__FILE__) | |
config.css_dir = "/stylesheets" | |
config.sass_dir = "views/stylesheets" | |
config.images_dir = "public/images" | |
config.http_images_path = "/images" | |
config.javascripts_dir = "/javascripts" | |
config.output_style = :expanded | |
config.sass_options = {:line_comments => true} | |
end | |
Dir["views/stylesheets/*.sass"].each do |sass_filename| | |
next if File.basename(sass_filename)[0,1] == "_" | |
puts "Processing #{sass_filename}..." | |
sass = IO.read(sass_filename) | |
css = Sass::Engine.new(sass, Compass.sass_engine_options).render # remove compass.sass_engine_options if you're using Compass | |
File.open("compiled/stylesheets/#{File.basename(sass_filename).sub("sass", "css")}", "w") {|f| f.write(css)} | |
end | |
end | |
end | |
task :default => [build_ns[:haml], build_ns[:sass]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment