module InlineSvg::TransformPipeline::Transformations
Public Class Methods
all_default_values()
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 65 def self.all_default_values custom_transformations .values .select {|opt| opt[:default_value] != nil} .map {|opt| [opt[:attribute], opt[:default_value]]} .inject({}) {|options, attrs| options.merge!(attrs[0] => attrs[1])} end
all_transformations()
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 39 def self.all_transformations in_priority_order(built_in_transformations.merge(custom_transformations)) end
built_in_transformations()
click to toggle source
Transformations
are run in priority order, lowest number first:
# File lib/inline_svg/transform_pipeline/transformations.rb, line 3 def self.built_in_transformations { id: { transform: IdAttribute, priority: 1 }, desc: { transform: Description, priority: 2 }, title: { transform: Title, priority: 3 }, aria: { transform: AriaAttributes }, aria_hidden: { transform: AriaHiddenAttribute }, class: { transform: ClassAttribute }, style: { transform: StyleAttribute }, data: { transform: DataAttributes }, nocomment: { transform: NoComment }, preserve_aspect_ratio: { transform: PreserveAspectRatio }, size: { transform: Size }, width: { transform: Width }, height: { transform: Height }, view_box: { transform: ViewBox }, } end
custom_transformations()
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 22 def self.custom_transformations magnify_priorities(InlineSvg.configuration.custom_transformations) end
in_priority_order(transforms)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 53 def self.in_priority_order(transforms) transforms.sort_by { |_, options| options.fetch(:priority, transforms.size) } end
lookup(transform_params)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 43 def self.lookup(transform_params) return [] unless transform_params.any? || custom_transformations.any? transform_params_with_defaults = params_with_defaults(transform_params) all_transformations.map { |name, definition| value = transform_params_with_defaults[name] definition.fetch(:transform, no_transform).create_with_value(value) if value }.compact end
magnify(priority=0)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 35 def self.magnify(priority=0) (priority + 1) * built_in_transformations.size end
magnify_priorities(transforms)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 26 def self.magnify_priorities(transforms) transforms.inject({}) do |output, (name, definition)| priority = definition.fetch(:priority, built_in_transformations.size) output[name] = definition.merge( { priority: magnify(priority) } ) output end end
no_transform()
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 73 def self.no_transform InlineSvg::TransformPipeline::Transformations::NullTransformation end
params_with_defaults(params)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 57 def self.params_with_defaults(params) without_empty_values(all_default_values.merge(params)) end
without_empty_values(params)
click to toggle source
# File lib/inline_svg/transform_pipeline/transformations.rb, line 61 def self.without_empty_values(params) params.reject {|key, value| value.nil?} end