Class: FlexiAdmin::Components::Shared::MediumComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- FlexiAdmin::Components::Shared::MediumComponent
- Defined in:
- lib/flexi_admin/components/shared/medium_component.rb
Instance Attribute Summary collapse
-
#attachment ⇒ Object
Returns the value of attribute attachment.
-
#autoplay ⇒ Object
Returns the value of attribute autoplay.
-
#css_class ⇒ Object
Returns the value of attribute css_class.
-
#variant ⇒ Object
Returns the value of attribute variant.
Instance Method Summary collapse
- #image_src ⇒ Object
-
#initialize(attachment:, variant:, autoplay: false, css_class: nil) ⇒ MediumComponent
constructor
attachment: ActiveStorage::Attached::One.
- #media? ⇒ Boolean
- #render_media ⇒ Object
Constructor Details
#initialize(attachment:, variant:, autoplay: false, css_class: nil) ⇒ MediumComponent
attachment: ActiveStorage::Attached::One
10 11 12 13 14 15 |
# File 'lib/flexi_admin/components/shared/medium_component.rb', line 10 def initialize(attachment:, variant:, autoplay: false, css_class: nil) @attachment = @variant = variant @autoplay = autoplay @css_class = css_class end |
Instance Attribute Details
#attachment ⇒ Object
Returns the value of attribute attachment.
5 6 7 |
# File 'lib/flexi_admin/components/shared/medium_component.rb', line 5 def @attachment end |
#autoplay ⇒ Object
Returns the value of attribute autoplay.
5 6 7 |
# File 'lib/flexi_admin/components/shared/medium_component.rb', line 5 def autoplay @autoplay end |
#css_class ⇒ Object
Returns the value of attribute css_class.
5 6 7 |
# File 'lib/flexi_admin/components/shared/medium_component.rb', line 5 def css_class @css_class end |
#variant ⇒ Object
Returns the value of attribute variant.
5 6 7 |
# File 'lib/flexi_admin/components/shared/medium_component.rb', line 5 def variant @variant end |
Instance Method Details
#image_src ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/flexi_admin/components/shared/medium_component.rb', line 23 def image_src return if .blank? return unless .attached? if .class != ActiveStorage::Attached::One raise "ActiveStorage::Attached::One required, got #{.class}" end return helpers.url_for() unless variant helpers.url_for(.variant(variant)) rescue ActiveStorage::InvariableError helpers.url_for() end |
#media? ⇒ Boolean
17 18 19 20 21 |
# File 'lib/flexi_admin/components/shared/medium_component.rb', line 17 def media? return false if .blank? true end |
#render_media ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/flexi_admin/components/shared/medium_component.rb', line 38 def render_media case .content_type.split("/").first when "image" content_tag :img, nil, src: image_src, class: css_class when "video" content_tag :video, nil, src: image_src, controls: true, class: css_class, onmouseover: autoplay ? "this.play()" : nil, onmouseout: autoplay ? "this.pause()" : nil end end |