Class: Govspeak::ImagePresenter
- Inherits:
-
Object
- Object
- Govspeak::ImagePresenter
- Defined in:
- lib/govspeak/presenters/image_presenter.rb
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
Instance Method Summary collapse
- #alt_text ⇒ Object
- #caption ⇒ Object
- #credit ⇒ Object
- #figcaption? ⇒ Boolean
- #figcaption_html ⇒ Object
- #id ⇒ Object
-
#initialize(image, locale: "en") ⇒ ImagePresenter
constructor
A new instance of ImagePresenter.
- #url ⇒ Object
Constructor Details
#initialize(image, locale: "en") ⇒ ImagePresenter
Returns a new instance of ImagePresenter.
5 6 7 8 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 5 def initialize(image, locale: "en") @image = image @locale = locale end |
Instance Attribute Details
#image ⇒ Object (readonly)
Returns the value of attribute image.
3 4 5 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 3 def image @image end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
3 4 5 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 3 def locale @locale end |
Instance Method Details
#alt_text ⇒ Object
14 15 16 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 14 def alt_text image.respond_to?(:alt_text) ? image.alt_text : image[:alt_text] end |
#caption ⇒ Object
18 19 20 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 18 def caption (image.respond_to?(:caption) ? image.caption : image[:caption]).to_s.strip.presence end |
#credit ⇒ Object
22 23 24 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 22 def credit (image.respond_to?(:credit) ? image.credit : image[:credit]).to_s.strip.presence end |
#figcaption? ⇒ Boolean
30 31 32 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 30 def figcaption? caption.present? || credit.present? end |
#figcaption_html ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 34 def figcaption_html lines = [] lines << "<figcaption>" lines << %(<p>#{caption}</p>) if caption.present? lines << %(<p>#{Govspeak::TranslationHelper.t_with_fallback('govspeak.image.figure.credit', credit:, locale:)}</p>) if credit.present? lines << "</figcaption>" lines.join end |
#id ⇒ Object
26 27 28 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 26 def id nil end |
#url ⇒ Object
10 11 12 |
# File 'lib/govspeak/presenters/image_presenter.rb', line 10 def url image.respond_to?(:url) ? image.url : image[:url] end |