Class: Semistatic::Presenters::PagePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/semistatic/presenters/page_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, helpers) ⇒ PagePresenter

Returns a new instance of PagePresenter.



8
9
10
11
# File 'lib/semistatic/presenters/page_presenter.rb', line 8

def initialize(page, helpers)
  @page = page
  @helpers = helpers
end

Instance Attribute Details

#helpersObject

Returns the value of attribute helpers.



5
6
7
# File 'lib/semistatic/presenters/page_presenter.rb', line 5

def helpers
  @helpers
end

#pageObject

Returns the value of attribute page.



5
6
7
# File 'lib/semistatic/presenters/page_presenter.rb', line 5

def page
  @page
end

Instance Method Details

#input(form) ⇒ Object

Returns String # => the input element for the form.

Parameters:

  • ActionView::Helpers::FormBuilder

    form

Returns:

  • String # => the input element for the form



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/semistatic/presenters/page_presenter.rb', line 60

def input(form)
  part = form.object
  case part.type
    when :string
      form.text_field :value
    when :html
      form.text_area :value, class: 'html wysiwyg tinymce'
    when :text
      form.text_area :value
    when :image
      input = form.file_field :file
      if part.file?
        input = output(part.name) + input
      end
      helpers.(:div, input)
  end
end

#output(name) ⇒ Object

ouput a part

Parameters:

  • Symbol

    name # the part name # when :page_title => page.title # else render the part as with its type renderer

Returns:

  • string



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/semistatic/presenters/page_presenter.rb', line 19

def output(name)
  if name.to_sym == :page_title
    @page.title
  else
    part = @page.part(name)
    method = "output_#{part.type}"

    if respond_to?(method)
      send(method, part)
    else
      part.value
    end
  end
end

#output_html(part) ⇒ Object

render the part as html

Parameters:

  • Symbol

    name # the part name

Returns:

  • String



37
38
39
# File 'lib/semistatic/presenters/page_presenter.rb', line 37

def output_html(part)
  helpers.raw part.value
end

#output_image(part, size = :original) ⇒ Object

render the part as html

Parameters:

  • Symbol

    name # the part name

  • Symbol

    size # defaults to :original

Returns:

  • String



52
53
54
55
56
# File 'lib/semistatic/presenters/page_presenter.rb', line 52

def output_image(part, size = :original)
  if part.file?
    helpers.image_tag(part.file.url(size))
  end
end

#output_text(part) ⇒ Object

render the part as simple formated text

Parameters:

  • Symbol

    name # the part name

Returns:

  • String



44
45
46
# File 'lib/semistatic/presenters/page_presenter.rb', line 44

def output_text(part)
  helpers.simple_format(part.value)
end