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, 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, html_attributes = {}) ⇒ InlineSvgComponent
Returns a new instance of InlineSvgComponent.
10 11 12 13 14 15 16 17 18 |
# File 'app/components/fox_tail/inline_svg_component.rb', line 10 def initialize(path, html_attributes = {}) unless html_attributes.key? :raise html_attributes[:raise] = FoxTail::Base.fox_tail_config.raise_on_asset_not_found end super(html_attributes) @path = path.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
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/components/fox_tail/inline_svg_component.rb', line 20 def call doc = Nokogiri::XML.parse asset_contents sanitized_html_attributes.each { |k, v| doc.child[k.to_s] = v } doc.child[:class] = html_class yield doc if block_given? doc.child.to_s.html_safe rescue FoxTail::AssetNotFound => e raise e if raise_error? Rails.logger.warn "[FoxTail::InlineSvgComponent] #{e.message}" content_tag :svg, nil, class: "hidden asset-not-found" end |