Class: Semistatic::Presenters::PagePresenter
- Inherits:
-
Object
- Object
- Semistatic::Presenters::PagePresenter
- Defined in:
- lib/semistatic/presenters/page_presenter.rb
Instance Attribute Summary collapse
-
#helpers ⇒ Object
Returns the value of attribute helpers.
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
-
#initialize(page, helpers) ⇒ PagePresenter
constructor
A new instance of PagePresenter.
-
#input(form) ⇒ Object
String # => the input element for the form.
-
#output(name) ⇒ Object
ouput a part.
-
#output_html(part) ⇒ Object
render the part as html.
-
#output_image(part, size = :original) ⇒ Object
render the part as html.
-
#output_text(part) ⇒ Object
render the part as simple formated text.
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
#helpers ⇒ Object
Returns the value of attribute helpers.
5 6 7 |
# File 'lib/semistatic/presenters/page_presenter.rb', line 5 def helpers @helpers end |
#page ⇒ Object
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.
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.content_tag(:div, input) end end |
#output(name) ⇒ Object
ouput a part
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
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
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
44 45 46 |
# File 'lib/semistatic/presenters/page_presenter.rb', line 44 def output_text(part) helpers.simple_format(part.value) end |