require 'rubygems'
if File.exist?(dir = File.join(File.dirname(__FILE__), 'lib'))
Gem.clear_paths
Gem.path.unshift(File.join(dir, 'gems'))
end
gem 'sinatra', '~> 0.3.2'
require 'sinatra'
gem 'extlib', '~> 0.9.8'
require 'extlib'
module Sinatra
module Sass
def sass(content, options = {})
require 'sass'
require 'compass'
options[:layout] = false
options[:views_directory] = 'sass'
render(:sass, content, options)
end
private
def render_sass(content, options = {})
::Sass::Engine.new(content, {
:style => :compact,
:load_paths => [
'.',
File.dirname(__FILE__) / 'sass'
] + ::Compass::Frameworks::ALL.map{ |f| f.stylesheets_directory }
}).render
end
end
unless RUBY_PLATFORM == 'java'
module Red
def red(content, options = {})
require 'red'
options[:views_directory] = 'red'
render(:red, content, options)
end
private
def render_red(content, options = {})
meta_class.__send__ :include, ::Red
::Red.__send__ :attr_accessor, :content
::Red.content = content
class << ::Red
::Red.init
::Red.content.translate_to_sexp_array.red!
end
end
end
class EventContext
include Red
end
end
end
helpers do
def css_include_tag(*stylesheets)
stylesheets.map do |stylesheet|
"<link href='/stylesheets/#{stylesheet}.css' media='screen' rel='stylesheet' type='text/css' />\n"
end
end
def js_include_tag(*javascripts)
javascripts.map do |javascript|
"<script type='text/javascript' src='/javascripts/#{javascript}.js'></script>\n"
end
end
end
get '/' do
haml :index
end
get '/:name' do
haml params[:name].to_sym
end
get '/stylesheets/:name.css' do
content_type 'text/css', :charset => 'utf-8'
sass params[:name].to_sym
end
unless RUBY_PLATFORM == 'java'
get '/javascripts/:name.js' do
content_type 'text/javascript', :charset => 'utf-8'
red params[:name].to_sym
end
end