Class: Spina::ContentPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spina/content_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#containerObject (readonly)

Returns the value of attribute container.



3
4
5
# File 'app/presenters/spina/content_presenter.rb', line 3

def container
  @container
end

#view_contextObject (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 attachment_url(attachment)
  attachment = find_part(attachment) unless attachment.is_a? Spina::Parts::Attachment
  view_context.main_app.url_for(attachment) if attachment.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, variant_options = {}, options = {})
  image = find_part(image) unless image.is_a? Spina::Parts::Image
  image_tag_options = {alt: image&.alt}
  view_context.image_tag main_app_image_url(image, variant_options), options.merge(image_tag_options) 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, variant_options = {})
  image = find_part(image) unless image.is_a? Spina::Parts::Image
  main_app_image_url(image, variant_options) 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