class Semistatic::Presenters::PagePresenter
Attributes
helpers[RW]
page[RW]
Public Class Methods
new(page, helpers)
click to toggle source
# File lib/semistatic/presenters/page_presenter.rb, line 8 def initialize(page, helpers) @page = page @helpers = helpers end
Public Instance Methods
input(form)
click to toggle source
@param ActionView::Helpers::FormBuilder form @return String # => the input element for the form
# 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)
click to toggle source
ouput a part @param Symbol name # the part name
# when :page_title => page.title # else render the part as with its type renderer
@return string
# 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)
click to toggle source
render the part as html @param Symbol name # the part name @return String
# File lib/semistatic/presenters/page_presenter.rb, line 37 def output_html(part) helpers.raw part.value end
output_image(part, size = :original)
click to toggle source
render the part as html @param Symbol name # the part name @param Symbol size # defaults to :original @return String
# 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)
click to toggle source
render the part as simple formated text @param Symbol name # the part name @return String
# File lib/semistatic/presenters/page_presenter.rb, line 44 def output_text(part) helpers.simple_format(part.value) end