class InlineSvg::Configuration
def add_custom_transformation(options)
def add_custom_transformation(options) if incompatible_transformation?(options.fetch(:transform)) raise InlineSvg::Configuration::Invalid.new("#{options.fetch(:transform)} should implement the .create_with_value and #transform methods") end @custom_transformations.merge!(Hash[ *[options.fetch(:attribute, :no_attribute), options] ]) end
def asset_file=(custom_asset_file)
def asset_file=(custom_asset_file) begin method = custom_asset_file.method(:named) if method.arity == 1 @asset_file = custom_asset_file else raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method with arity 1") end rescue NameError raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method") end end
def asset_finder=(finder)
def asset_finder=(finder) @asset_finder = if finder.respond_to?(:find_asset) finder elsif finder.class.name == "Propshaft::Assembly" InlineSvg::PropshaftAssetFinder else # fallback to a naive static asset finder # (sprokects >= 3.0 && config.assets.precompile = false # See: https://github.com/jamesmartin/inline_svg/issues/25 InlineSvg::StaticAssetFinder end asset_finder end
def incompatible_transformation?(klass)
def incompatible_transformation?(klass) !klass.is_a?(Class) || !klass.respond_to?(:create_with_value) || !klass.instance_methods.include?(:transform) end
def initialize
def initialize @custom_transformations = {} @asset_file = InlineSvg::AssetFile @svg_not_found_css_class = nil @raise_on_file_not_found = false end
def raise_on_file_not_found=(value)
def raise_on_file_not_found=(value) @raise_on_file_not_found = value end
def raise_on_file_not_found?
def raise_on_file_not_found? !!@raise_on_file_not_found end
def svg_not_found_css_class=(css_class)
def svg_not_found_css_class=(css_class) if css_class.present? && css_class.is_a?(String) @svg_not_found_css_class = css_class end end