Created
October 22, 2011 19:22
-
-
Save jamis/1306388 to your computer and use it in GitHub Desktop.
Sprockets asset resource for Webmachine (asset pipelining!)
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
class Resources::Assets < Webmachine::Resource | |
def content_types_provided | |
@asset = Application.assets[request.uri.path] | |
if @asset.present? | |
[[@asset.content_type, :to_asset]] | |
else | |
accept = request.headers['Accept'] || "text/html" | |
[[accept.split(/,/).first.split(/;/).first.strip, :to_html]] | |
end | |
end | |
def resource_exists? | |
@asset.present? | |
end | |
def generate_etag | |
@asset.digest | |
end | |
def last_modified | |
@asset.mtime | |
end | |
def to_asset | |
@asset.to_s | |
end | |
def to_html | |
Application.logger.error "reached impossible state in asset resource (no asset, but no error) path=#{request.path_tokens.inspect}" | |
"<html><body><h1>Bug!</h1><p>Shouldn't ever get here.</p></body></html>" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment