Skip to content

Instantly share code, notes, and snippets.

@scottymac
Created May 31, 2009 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottymac/121038 to your computer and use it in GitHub Desktop.
Save scottymac/121038 to your computer and use it in GitHub Desktop.
### /lib/rack/sass ###
require 'sass'
module Rack
class Sass < Rack::File
def initialize(root, options = {})
@root = root
@options = options
end
def _call(env)
@path_info = Utils.unescape(env["PATH_INFO"])
return forbidden if @path_info.include? ".."
return forbidden unless @path_info.include? ".css"
@path = F.join(@root, @path_info).gsub(/\.css/, '.sass')
begin
if F.file?(@path) && F.readable?(@path)
serving
else
raise Errno::EPERM
end
rescue SystemCallError
not_found
end
end
def serving
body = ::Sass::Engine.new(F.read(@path), @options).render
[200, {
"Last-Modified" => F.mtime(@path).httpdate,
"Content-Type" => Mime.mime_type(".css"),
"Content-Length" => Utils.bytesize(body).to_s
}, [body]]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment