Class: FoxTail::InlineSvgComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- Base
- BaseComponent
- FoxTail::InlineSvgComponent
- Defined in:
- app/components/fox_tail/inline_svg_component.rb
Overview
Displays an SVG file inline
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from BaseComponent
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(path_or_html_attributes = {}, html_attributes = {}) ⇒ InlineSvgComponent
constructor
A new instance of InlineSvgComponent.
Methods inherited from BaseComponent
classname_merger, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class
Methods inherited from Base
Constructor Details
#initialize(path_or_html_attributes = {}, html_attributes = {}) ⇒ InlineSvgComponent
Returns a new instance of InlineSvgComponent.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/components/fox_tail/inline_svg_component.rb', line 10 def initialize(path_or_html_attributes = {}, html_attributes = {}) if path_or_html_attributes.is_a?(Hash) html_attributes = path_or_html_attributes path_or_html_attributes = nil end unless html_attributes.key? :raise html_attributes[:raise] = FoxTail::Base.fox_tail_config.raise_on_asset_not_found end super(html_attributes) @path = path_or_html_attributes&.to_s end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'app/components/fox_tail/inline_svg_component.rb', line 6 def path @path end |
Instance Method Details
#call ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/components/fox_tail/inline_svg_component.rb', line 25 def call doc = Nokogiri::XML.parse content? ? content : asset_contents sanitized_html_attributes.each { |k, v| doc.child[k.to_s] = v } node = doc.at_css "svg" node[:class] = html_class yield node if block_given? node.to_s.html_safe # rubocop:disable Rails/OutputSafety rescue FoxTail::AssetNotFound => e raise e if raise_error? Rails.logger.warn "[FoxTail::InlineSvgComponent] #{e.}" content_tag :svg, nil, class: "hidden asset-not-found" end |