Class: TypeStation::Presenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/type_station/presenter.rb

Direct Known Subclasses

AdminBarPresenter, PagePresenter

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasePresenter

#initialize

Constructor Details

This class inherits a constructor from TypeStation::BasePresenter

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class TypeStation::BasePresenter

Class Attribute Details

.form_fieldsObject

Returns the value of attribute form_fields.



7
8
9
# File 'app/presenters/type_station/presenter.rb', line 7

def form_fields
  @form_fields
end

Class Method Details

.form_field(name, options) ⇒ Object



9
10
11
12
# File 'app/presenters/type_station/presenter.rb', line 9

def form_field(name, options)
  @form_fields ||= []
  @form_fields << {name: name, type: options[:type].to_s, label: options[:label], options: options[:options], default: options[:default], required: options[:required]}
end

Instance Method Details

#create(type, user_options = {}, &block) ⇒ Object



15
16
17
18
# File 'app/presenters/type_station/presenter.rb', line 15

def create(type, user_options = {}, &block)
  options = { type: type == :page ? nil : type, model_parent_id: @object.to_param, action: :create }.merge(user_options)
  entity_block(h.capture(&block), options)
end

#delete(user_options = {}, &block) ⇒ Object



25
26
27
28
# File 'app/presenters/type_station/presenter.rb', line 25

def delete(user_options = {}, &block)
  options = { action: :delete }.merge(user_options)
  entity_block(h.capture(&block), options)
end

#edit(user_options = {}, &block) ⇒ Object



20
21
22
23
# File 'app/presenters/type_station/presenter.rb', line 20

def edit(user_options = {}, &block)
  options = { action: :edit, presenter: self.class }.merge(user_options)
  entity_block(h.capture(&block), options)
end

#field(name, user_options = {}, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/presenters/type_station/presenter.rb', line 35

def field(name, user_options = {}, &block)
  content = ''
  options = { type: :text, field: name, url: h.type_station.admin_entity_url(@object) }.merge(user_options)

  content_attribute = @object.get name

  if content_attribute.present?
    content_presenter = ContentPresenter.new(content_attribute, h, options)

    if content_presenter.value_is_hash?
      content += h.capture(content_presenter, &block)
    else
      content += content_presenter.value
    end
  else
    content += h.capture(ContentPresenter.new(nil,h, options), &block)
  end

  TypeStation::Blocks::Field.new(h.type_station_authorise, @object, options).render(content)
end

#move(direction, user_options = {}, &block) ⇒ Object



30
31
32
33
# File 'app/presenters/type_station/presenter.rb', line 30

def move(direction, user_options = {}, &block)
  options = { action: :move, options: { direction: "move_#{direction}"} }.merge(user_options)
  entity_block(h.capture(&block), options)
end