Class: Spina::ContentPresenter
- Inherits:
-
Object
- Object
- Spina::ContentPresenter
- Defined in:
- app/presenters/spina/content_presenter.rb
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #attachment_url(attachment) ⇒ Object
- #html(name) ⇒ Object
- #image_tag(image, variant_options = {}, options = {}) ⇒ Object
- #image_url(image, variant_options = {}) ⇒ Object
-
#initialize(view_context, container) ⇒ ContentPresenter
constructor
A new instance of ContentPresenter.
- #text(name) ⇒ Object
Constructor Details
#initialize(view_context, container) ⇒ ContentPresenter
Returns a new instance of ContentPresenter.
5 6 7 8 |
# File 'app/presenters/spina/content_presenter.rb', line 5 def initialize(view_context, container) @view_context = view_context || Spina::Current.page&.view_context @container = container end |
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
3 4 5 |
# File 'app/presenters/spina/content_presenter.rb', line 3 def container @container end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
3 4 5 |
# File 'app/presenters/spina/content_presenter.rb', line 3 def view_context @view_context end |
Instance Method Details
#attachment_url(attachment) ⇒ Object
31 32 33 34 |
# File 'app/presenters/spina/content_presenter.rb', line 31 def () = find_part() unless .is_a? Spina::Parts::Attachment view_context.main_app.url_for() if .present? end |
#html(name) ⇒ Object
15 16 17 18 |
# File 'app/presenters/spina/content_presenter.rb', line 15 def html(name) html = find_part(name)&.content RichTextPresenter.new(view_context, html) end |
#image_tag(image, variant_options = {}, options = {}) ⇒ Object
20 21 22 23 24 |
# File 'app/presenters/spina/content_presenter.rb', line 20 def image_tag(image, = {}, = {}) image = find_part(image) unless image.is_a? Spina::Parts::Image = {alt: image&.alt} view_context.image_tag main_app_image_url(image, ), .merge() if image.present? end |
#image_url(image, variant_options = {}) ⇒ Object
26 27 28 29 |
# File 'app/presenters/spina/content_presenter.rb', line 26 def image_url(image, = {}) image = find_part(image) unless image.is_a? Spina::Parts::Image main_app_image_url(image, ) if image.present? end |
#text(name) ⇒ Object
10 11 12 13 |
# File 'app/presenters/spina/content_presenter.rb', line 10 def text(name) part = find_part(name) part&.content.to_s end |