lib/prez/assets.rb in prez-0.0.3 vs lib/prez/assets.rb in prez-0.0.4
- old
+ new
@@ -1,6 +1,7 @@
require "coffee-script"
+require "prez/cache"
require "prez/data_uri"
require "prez/error"
require "prez/files"
require "prez/sass_extensions"
require "sass"
@@ -24,21 +25,33 @@
def self_closing?
false
end
+ def compiled_contents
+ Prez::Cache.get "asset:#{extension}:compiled:#{file}", contents do
+ compile contents
+ end
+ end
+
+ def compile(contents)
+ contents
+ end
+
def minified_contents
- minify contents
+ Prez::Cache.get "asset:#{extension}:minified:#{file}", compiled_contents do
+ minify compiled_contents
+ end
end
def minify(contents)
contents
end
def to_tag
if dev? && !self_closing?
- "#{open}\n#{contents}#{close}"
+ "#{open}\n#{compiled_contents}#{close}"
else
"#{open}#{minified_contents.strip}#{close}"
end
end
end
@@ -87,11 +100,11 @@
else
raise Prez::Error.new("Unknown image extension '#{extension}'")
end
end
- def minify(contents)
+ def compile(contents)
Prez::DataUri.new(image_type, contents).to_s
end
end
class Javascript < Prez::Assets::Tagged
@@ -105,12 +118,19 @@
def close
%{</script>}
end
+ def compile(contents)
+ if file =~ /\.coffee$/
+ CoffeeScript.compile contents
+ else
+ contents
+ end
+ end
+
def minify(contents)
- contents = CoffeeScript.compile contents if file =~ /\.coffee$/
Uglifier.compile contents
end
end
class Stylesheet < Prez::Assets::Tagged
@@ -124,14 +144,21 @@
def close
%{</style>}
end
+ def compile(contents)
+ Sass::Engine.new(contents,
+ syntax: :scss,
+ style: :expanded,
+ load_paths: [File.dirname(file)]).render
+ end
+
def minify(contents)
Sass::Engine.new(contents,
syntax: :scss,
style: :compressed,
- load_paths: [File.expand_path("..", file)]).render
+ load_paths: [File.dirname(file)]).render
end
end
class << self
def image(name, options = {})