Class: Middleman::Extensions::AssetHost
- Inherits:
-
Middleman::Extension
- Object
- Middleman::Extension
- Middleman::Extensions::AssetHost
- Defined in:
- middleman-core/lib/middleman-core/extensions/asset_host.rb
Constant Summary
Constants included from Contracts
Instance Attribute Summary
Attributes inherited from Middleman::Extension
Instance Method Summary collapse
-
#initialize(app, options_hash = ::Middleman::EMPTY_HASH, &block) ⇒ AssetHost
constructor
A new instance of AssetHost.
- #manipulate_resource_list_container!(resource_list) ⇒ Object
- #rewrite_url(asset_path, dirpath, _request_path) ⇒ Object
Methods inherited from Middleman::Extension
activated_extension, #add_exposed_to_context, #after_build, #after_configuration, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, #manipulate_resource_list, option, #ready, resources
Methods included from Contracts
Constructor Details
#initialize(app, options_hash = ::Middleman::EMPTY_HASH, &block) ⇒ AssetHost
Returns a new instance of AssetHost.
10 11 12 13 14 15 16 |
# File 'middleman-core/lib/middleman-core/extensions/asset_host.rb', line 10 def initialize(app, = ::Middleman::EMPTY_HASH, &block) super require 'set' @set_of_exts = Set.new(.exts || app.config[:asset_extensions]) @set_of_sources = Set.new .sources end |
Instance Method Details
#manipulate_resource_list_container!(resource_list) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'middleman-core/lib/middleman-core/extensions/asset_host.rb', line 19 def manipulate_resource_list_container!(resource_list) resource_list.by_extensions(@set_of_sources).each do |r| next if Array(.rewrite_ignore || []).any? do |i| ::Middleman::Util.path_match(i, "/#{r.destination_path}") end r.add_filter ::Middleman::InlineURLRewriter.new(:asset_host, app, r, after_filter: :asset_hash, url_extensions: @set_of_exts, ignore: .ignore, proc: method(:rewrite_url)) end end |
#rewrite_url(asset_path, dirpath, _request_path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'middleman-core/lib/middleman-core/extensions/asset_host.rb', line 36 def rewrite_url(asset_path, dirpath, _request_path) uri = ::Middleman::Util.parse_uri(asset_path) relative_path = uri.path[0..0] != '/' full_asset_path = if relative_path dirpath.join(asset_path).to_s else asset_path end asset_prefix = case [:host] when Proc [:host].call(full_asset_path) when String [:host] end File.join(asset_prefix, full_asset_path) end |