Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Error is on require, so move require back down to #content.

  • Loading branch information...
commit 615dd8177120b30be0a41750ee6ceb781ad3fd08 1 parent be4aed1
@gkellogg gkellogg authored
Showing with 9 additions and 7 deletions.
  1. +9 −7 lib/sinatra/simple_assets.rb
View
16 lib/sinatra/simple_assets.rb
@@ -1,6 +1,4 @@
require 'sinatra/base'
-require 'uglifier'
-require 'cssmin'
module Sinatra
module SimpleAssets
@@ -41,18 +39,22 @@ def hashed_path
end
def hash
- @hash ||= Digest::SHA1.hexdigest content
- rescue ExecJS::RuntimeUnavailable
- # Find the most recent compressed version if the JS runtime is unavailable
- fname = Dir.glob("#{@root}/#{@path}/#{@name}-*.#{@type}").sort_by {|f| File.mtime(f)}.last
- fname.match(/-(.*)\.#{@type}/) && $1
+ @hash ||= begin
+ Digest::SHA1.hexdigest content
+ rescue
+ # Find the most recent compressed version if the JS runtime is unavailable
+ fname = Dir.glob("#{@root}/#{@path}/#{@name}-*.#{@type}").sort_by {|f| File.mtime(f)}.last
+ fname.match(/-(.*)\.#{@type}/) && $1
+ end
end
def content
case @type
when :js
+ require 'uglifier'
@content ||= Uglifier.new.compress combined
when :css
+ require 'cssmin'
@content ||= CSSMin.minify combined
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.