lib/linner.rb in linner-0.3.2 vs lib/linner.rb in linner-0.4.0
- old
+ new
@@ -1,5 +1,7 @@
+require "nokogiri"
+
require "linner/version"
require "linner/command"
require "linner/asset"
require "linner/helper"
require "linner/reactor"
@@ -7,10 +9,13 @@
require "linner/template"
require "linner/notifier"
require "linner/compressor"
require "linner/environment"
+Encoding.default_external = Encoding::UTF_8
+Encoding.default_internal = Encoding::UTF_8
+
module Linner
extend self
attr_accessor :compile
@@ -38,13 +43,14 @@
@options
end
def perform(*asset)
env.groups.each do |config|
- concat(config) if config["concat"]
copy(config) if config["copy"]
+ concat(config) if config["concat"]
end
+ revision if compile? and env.revision
end
private
def concat(config)
config["concat"].each_with_index do |pair, index|
@@ -69,21 +75,32 @@
FileUtils.cp_r path, dest_path
end
end
end
+ def revision
+ revision = File.join env.public_folder, env.revision
+ doc = Nokogiri::HTML.parse(File.read revision)
+ doc.search("script").each do |x|
+ next unless src = x.attributes["src"]
+ asset = Asset.new(File.join env.public_folder, src)
+ x.set_attribute "src", asset.revision!
+ end
+ doc.search("link").each do |x|
+ next unless href = x.attributes["href"]
+ asset = Asset.new(File.join env.public_folder, href)
+ x.set_attribute "href", asset.revision!
+ end
+ File.open(revision, "w") do |f|
+ f.write doc.to_html
+ end
+ end
+
def cache_miss?(path)
asset = Asset.new(path)
- if asset.stylesheet? and Tilt[path] != Tilt::CSSTemplate
- partials = Sass::Engine.for_file(path, sass_engine_options).dependencies.map{|m| m.options[:filename]}
- cache_missed = partials.select do |partial|
- partial_asset = Asset.new(partial)
- (cache[partial] and cache[partial].mtime == partial_asset.mtime) ? false : cache[partial] = partial_asset
- end
- unless cache_missed.empty?
- cache[path] = asset
- return true
- end
+ if cache[path] and cache[path].mtime == asset.mtime
+ false
+ else
+ cache[path] = asset
end
- (cache[path] and cache[path].mtime == asset.mtime) ? false : cache[path] = asset
end
end