2011-11-30 08:43:01 +01:00
|
|
|
# Base helper to manipulate asset paths
|
2011-07-06 19:40:17 +02:00
|
|
|
module Middleman::CoreExtensions::Assets
|
2011-11-30 08:43:01 +01:00
|
|
|
|
|
|
|
# Extension registered
|
2011-07-06 19:40:17 +02:00
|
|
|
class << self
|
2011-11-30 08:43:01 +01:00
|
|
|
# @private
|
2011-07-06 19:40:17 +02:00
|
|
|
def registered(app)
|
2011-11-21 06:21:19 +01:00
|
|
|
# Disable Padrino cache buster
|
|
|
|
app.set :asset_stamp, false
|
2011-07-07 07:41:12 +02:00
|
|
|
|
2011-11-30 08:43:01 +01:00
|
|
|
# Include helpers
|
2011-11-19 01:17:14 +01:00
|
|
|
app.send :include, InstanceMethod
|
2011-07-06 19:40:17 +02:00
|
|
|
end
|
|
|
|
alias :included :registered
|
|
|
|
end
|
|
|
|
|
2011-11-30 08:43:01 +01:00
|
|
|
# Methods to be mixed-in to Middleman::Base
|
2011-11-19 01:17:14 +01:00
|
|
|
module InstanceMethod
|
2011-11-30 08:43:01 +01:00
|
|
|
|
|
|
|
# Get the URL of an asset given a type/prefix
|
|
|
|
#
|
|
|
|
# @param [String] path The path (such as "photo.jpg")
|
|
|
|
# @param [String] prefix The type prefix (such as "images")
|
2011-12-18 05:12:13 +01:00
|
|
|
# @return [String] The fully qualified asset url
|
2011-07-06 19:40:17 +02:00
|
|
|
def asset_url(path, prefix="")
|
2011-11-30 08:43:01 +01:00
|
|
|
# Don't touch assets which already have a full path
|
2012-04-02 03:08:59 +02:00
|
|
|
if path.include?("//")
|
|
|
|
path
|
|
|
|
else # rewrite paths to use their destination path
|
|
|
|
path = File.join(prefix, path)
|
2012-04-04 19:26:07 +02:00
|
|
|
if resource = sitemap.find_resource_by_path(path)
|
|
|
|
path = resource.path
|
|
|
|
end
|
2012-04-02 03:08:59 +02:00
|
|
|
|
|
|
|
File.join(http_prefix, path)
|
|
|
|
end
|
2011-07-06 19:40:17 +02:00
|
|
|
end
|
|
|
|
end
|
2012-04-02 03:08:59 +02:00
|
|
|
end
|