Skip to content

Commit

Permalink
Merge pull request #1776 from tf/scrolled-theme-icons-rel
Browse files Browse the repository at this point in the history
Always use relative paths for custom icons
  • Loading branch information
tf authored Feb 10, 2022
2 parents acece58 + b1c399e commit 23c7d72
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
module PageflowScrolled
# @api private
module ThemesHelper
def scrolled_theme_asset_path(theme, path, theme_file_role: nil)
theme.files.dig(theme_file_role, :resized) ||
def scrolled_theme_asset_path(theme, path, theme_file_role: nil, relative_url: false)
path =
theme.files.dig(theme_file_role, :resized) ||
asset_pack_path("media/pageflow-scrolled/themes/#{theme.name}/#{path}")

if relative_url
URI.parse(path).path
else
path
end
end

def scrolled_theme_stylesheet_pack_tags(theme)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ json.theme do
json.icons do
theme.options.fetch(:custom_icons, []).each do |icon_name|
json.set!(icon_name,
scrolled_theme_asset_path(theme, "icons/#{icon_name}.svg"))
scrolled_theme_asset_path(theme, "icons/#{icon_name}.svg",
relative_url: true))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,25 @@ def render(helper, entry, options = {})
})
end

it 'does not use asset host in icon paths to allow xlink:href usage' do
controller.config.asset_host = 'some-asset-host'
pageflow_configure do |config|
config.themes.register(:default, custom_icons: [:share])
end
entry = create(:published_entry)
result = render(helper, entry)

expect(result).to include_json(config: {
theme: {
assets: {
icons: {
share: %r{^/packs.*share.*svg$}
}
}
}
})
end

it 'renders empty icons object if theme has no custom icons' do
pageflow_configure do |config|
config.themes.register(:default, custom_icons: [])
Expand Down

0 comments on commit 23c7d72

Please sign in to comment.