Rack-based HTML rewriter

This commit is contained in:
Thomas Reynolds 2014-04-15 15:16:52 -07:00
parent 1006739e98
commit 927a1758ba
4 changed files with 110 additions and 73 deletions

View file

@ -222,6 +222,19 @@ module Middleman
end
end
def rewrite_paths(body, path, exts, &block)
body.dup.gsub(/([=\'\"\(]\s*)([^\s\'\"\)]+(#{Regexp.union(exts)}))/) do |match|
opening_character = $1
asset_path = $2
if result = yield(asset_path)
"#{opening_character}#{result}"
else
match
end
end
end
private
# Is mime type known to be non-binary?