Skip to content

Instantly share code, notes, and snippets.

@statonjr
Created January 3, 2013 23:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statonjr/4448445 to your computer and use it in GitHub Desktop.
Save statonjr/4448445 to your computer and use it in GitHub Desktop.
Static resource for webmachine-ruby
class StaticResource < Webmachine::Resource
def encodings_provided
{"gzip" => :encode_gzip, "identity" => :encode_identity}
end
def allowed_methods
%W[GET]
end
def generate_etag
Digest::MD5.hexdigest(Time.now.utc.to_i.to_s + request.body.to_s)
end
def languages_provided
["en-us"]
end
def resource_exists?
File.exists?(request.disp_path)
end
def content_types_provided
[['text/css', :to_css], ['application/javascript', :to_js]]
end
def to_css
File.read(request.disp_path)
end
def to_js
File.read(request.disp_path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment