class Serif::FileDigest
Constants
- DIGEST_CACHE
- Syntax
file_digest “file.css” [prefix:.]
Public Class Methods
new(tag_name, markup, tokens)
click to toggle source
Calls superclass method
# File lib/serif/site.rb, line 31 def initialize(tag_name, markup, tokens) super if markup =~ Syntax @path = $1 if $2 @prefix = $2.gsub(/\s*prefix\s*:\s*/, "") else @prefix = "" end else raise SyntaxError.new("Syntax error for file_digest") end end
Public Instance Methods
render(context)
click to toggle source
Takes the given path and returns the MD5 hex digest of the file’s contents.
The path argument is first stripped, and any leading “/” has no effect.
# File lib/serif/site.rb, line 52 def render(context) return "" unless ENV["ENV"] == "production" full_path = File.join(context["site"]["directory"], @path.strip) return @prefix + DIGEST_CACHE[full_path] if DIGEST_CACHE[full_path] digest = Digest::MD5.hexdigest(File.read(full_path)) DIGEST_CACHE[full_path] = digest @prefix + digest end