Skip to content

Commit

Permalink
Make custom icon directory name configurable via theme options
Browse files Browse the repository at this point in the history
This enabled toggling between different icon sets using theme option
overrides.

REDMINE-20841
  • Loading branch information
tf committed Oct 10, 2024
1 parent ad6fa1a commit 9fea091
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ json.theme do

json.icons({})
json.icons do
icons_directory = theme.options.fetch(:custom_icons_directory, 'icons')

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, File.join(icons_directory, "#{icon_name}.svg"),
relative_url: true))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ def render(helper, entry, options = {})
config.themes.register(:default, custom_icons: [:share])
end
entry = create(:published_entry, type_name: 'scrolled')

result = render(helper, entry)

expect(result).to include_json(config: {
Expand All @@ -711,6 +712,31 @@ def render(helper, entry, options = {})
})
end

it 'supports custom icons directories' do
pageflow_configure do |config|
config.themes.register(:default,
custom_icons: [:share],
custom_icons_directory: 'icons/someSet')
end
entry = create(:published_entry, type_name: 'scrolled')
theme_directory = Rails.root.join('app/javascript/pageflow-scrolled/themes/default')
FileUtils.mkdir_p(theme_directory.join('icons/someSet'))
FileUtils.cp(theme_directory.join('icons/share.svg'),
theme_directory.join('icons/someSet/share.svg'))

result = render(helper, entry)

expect(result).to include_json(config: {
theme: {
assets: {
icons: {
share: %r{themes/default/icons/someSet/share.*svg$}
}
}
}
})
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|
Expand Down

0 comments on commit 9fea091

Please sign in to comment.