Skip to content

Commit

Permalink
Merge pull request #1754 from codevise/proc-asset-host
Browse files Browse the repository at this point in the history
Support proc as asset host
  • Loading branch information
tf committed Nov 2, 2021
2 parents 51f5aa9 + 2ffa234 commit 1841764
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ module PageflowScrolled
# @api private
module WebpackPublicPathHelper
def scrolled_webpack_public_path_script_tag
content_tag(:script, WebpackPublicPathHelper.js_snippet.html_safe)
content_tag(:script, WebpackPublicPathHelper.js_snippet(request).html_safe)
end

def self.js_snippet
asset_host = Rails.configuration.action_controller.asset_host
def self.js_snippet(request = nil)
config_host = Rails.configuration.action_controller.asset_host
packs_dir = Webpacker.config.public_output_path.basename
asset_host = if config_host.respond_to?(:call)
config_host.call(packs_dir, request)
else
config_host
end

"var __webpack_public_path__ = '#{asset_host}/#{packs_dir}/';"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ module PageflowScrolled
visible: false,
text: "var __webpack_public_path__ = '/packs-test/';")
end

it 'can deal with proc asset host' do
allow(Rails.configuration.action_controller).to receive(:asset_host)
.and_return(lambda do |source, request = nil, *_|
'2' + source.to_s if request && source
end)

html = helper.scrolled_webpack_public_path_script_tag

expect(html)
.to have_selector(
'script',
visible: false,
text: "var __webpack_public_path__ = '2packs-test/packs-test/';"
)
end
end
end
end

0 comments on commit 1841764

Please sign in to comment.