Created
May 31, 2009 21:13
-
-
Save scottymac/121038 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### /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