]> git.openstreetmap.org Git - rails.git/blob - config/initializers/inline_svg.rb
Merge remote-tracking branch 'upstream/pull/6913'
[rails.git] / config / initializers / inline_svg.rb
1 # frozen_string_literal: true
2
3 module OpenStreetMap
4   class SvgToSymbolTransform < InlineSvg::CustomTransformation
5     def transform(doc)
6       with_svg(doc) do |svg|
7         svg.name = "symbol"
8       end
9     end
10   end
11
12   class AssetRoutingTransform < InlineSvg::CustomTransformation
13     def transform(doc)
14       with_svg(doc) do |svg|
15         svg.css("image").each do |image|
16           image["href"] = ActionController::Base.helpers.asset_path(image["href"].sub(%r{\A[./]+}, ""))
17         end
18       end
19     end
20   end
21 end
22
23 InlineSvg.configure do |config|
24   config.add_custom_transformation(:attribute => :to_symbol, :transform => OpenStreetMap::SvgToSymbolTransform)
25   config.add_custom_transformation(:attribute => :asset_path, :transform => OpenStreetMap::AssetRoutingTransform, :default_value => true)
26 end