Merge pull request #434 from bhollis/asset_hash
Add an option to asset_hash to allow excluding files
This commit is contained in:
commit
3356153d55
|
@ -5,12 +5,13 @@ module Middleman::Extensions
|
||||||
def registered(app, options)
|
def registered(app, options)
|
||||||
exts = options[:exts] || %w(.ico .manifest .jpg .jpeg .png .gif .js .css)
|
exts = options[:exts] || %w(.ico .manifest .jpg .jpeg .png .gif .js .css)
|
||||||
|
|
||||||
|
ignore = Array(options[:ignore])
|
||||||
|
|
||||||
app.ready do
|
app.ready do
|
||||||
sitemap.register_resource_list_manipulator(
|
sitemap.register_resource_list_manipulator(
|
||||||
:asset_hash,
|
:asset_hash,
|
||||||
AssetHashManager.new(self, exts)
|
AssetHashManager.new(self, exts, ignore)
|
||||||
)
|
)
|
||||||
|
|
||||||
use Middleware, :exts => exts, :middleman_app => self
|
use Middleware, :exts => exts, :middleman_app => self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,16 +19,17 @@ module Middleman::Extensions
|
||||||
end
|
end
|
||||||
|
|
||||||
class AssetHashManager
|
class AssetHashManager
|
||||||
def initialize(app, exts)
|
def initialize(app, exts, ignore)
|
||||||
@app = app
|
@app = app
|
||||||
@exts = exts
|
@exts = exts
|
||||||
|
@ignore = ignore
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the main sitemap resource list
|
# Update the main sitemap resource list
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def manipulate_resource_list(resources)
|
def manipulate_resource_list(resources)
|
||||||
resources.each do |resource|
|
resources.each do |resource|
|
||||||
if @exts.include? resource.ext
|
if @exts.include?(resource.ext) && @ignore.none? {|ignore| resource.path =~ ignore }
|
||||||
# figure out the path Sprockets would use for this asset
|
# figure out the path Sprockets would use for this asset
|
||||||
if resource.ext == '.js'
|
if resource.ext == '.js'
|
||||||
sprockets_path = resource.path.sub(@app.js_dir,'').sub(/^\//,'')
|
sprockets_path = resource.path.sub(@app.js_dir,'').sub(/^\//,'')
|
||||||
|
|
Loading…
Reference in a new issue