Module: InlineSvg::TransformPipeline::Transformations
- Defined in:
- lib/inline_svg/transform_pipeline/transformations.rb,
lib/inline_svg/transform_pipeline/transformations/size.rb,
lib/inline_svg/transform_pipeline/transformations/title.rb,
lib/inline_svg/transform_pipeline/transformations/width.rb,
lib/inline_svg/transform_pipeline/transformations/height.rb,
lib/inline_svg/transform_pipeline/transformations/view_box.rb,
lib/inline_svg/transform_pipeline/transformations/no_comment.rb,
lib/inline_svg/transform_pipeline/transformations/aria_hidden.rb,
lib/inline_svg/transform_pipeline/transformations/description.rb,
lib/inline_svg/transform_pipeline/transformations/id_attribute.rb,
lib/inline_svg/transform_pipeline/transformations/transformation.rb,
lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb,
lib/inline_svg/transform_pipeline/transformations/class_attribute.rb,
lib/inline_svg/transform_pipeline/transformations/data_attributes.rb,
lib/inline_svg/transform_pipeline/transformations/style_attribute.rb,
lib/inline_svg/transform_pipeline/transformations/aria_hidden_attribute.rb,
lib/inline_svg/transform_pipeline/transformations/preserve_aspect_ratio.rb
Defined Under Namespace
Classes: AriaAttributes, AriaHidden, AriaHiddenAttribute, ClassAttribute, DataAttributes, Description, Height, IdAttribute, NoComment, NullTransformation, PreserveAspectRatio, Size, StyleAttribute, Title, Transformation, ViewBox, Width
Class Method Summary
collapse
Class Method Details
.all_default_values ⇒ Object
65
66
67
68
69
70
71
|
# 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
|
39
40
41
|
# File 'lib/inline_svg/transform_pipeline/transformations.rb', line 39
def self.all_transformations
in_priority_order(built_in_transformations.merge(custom_transformations))
end
|
Transformations are run in priority order, lowest number first:
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 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
|
22
23
24
|
# 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) ⇒ Object
53
54
55
|
# 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) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# 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) ⇒ Object
35
36
37
|
# 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) ⇒ Object
26
27
28
29
30
31
32
33
|
# 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
|
.params_with_defaults(params) ⇒ Object
57
58
59
|
# 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) ⇒ Object
61
62
63
|
# File 'lib/inline_svg/transform_pipeline/transformations.rb', line 61
def self.without_empty_values(params)
params.reject {|key, value| value.nil?}
end
|