Class: Cell::ViewModel

Inherits:
Rails
  • Object
show all
Extended by:
Helpers
Includes:
ActionView::Context, ActionView::Helpers::UrlHelper, OptionsConstructor, LinkToHelper
Defined in:
lib/cell/view_model.rb

Overview

TODO: warn when using ::property but not passing in model in constructor.

Direct Known Subclasses

Concept

Defined Under Namespace

Modules: Helpers, LinkToHelper

Instance Attribute Summary collapse

Attributes inherited from Rails

#parent_controller

Attributes inherited from Rack

#request

Attributes included from Caching

#cache_configured, #cache_store

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

collection

Methods included from LinkToHelper

#convert_options_to_data_attributes, #link_to, #link_to_remote_options?

Methods inherited from Rails

#cache_configured?, #cache_store, cache_store, cell_for, expire_cache_key

Methods included from Rails::LinkToHelper

#convert_options_to_data_attributes, #link_to, #link_to_remote_options?

Methods inherited from Rack

render_cell_state

Methods inherited from Base

cell_for, class_from_cell_name

Methods included from Builder::ClassMethods

#build, #builders

Methods included from Base::SelfContained

#self_contained!

Methods included from Base::Prefixes

#_prefixes

Methods included from Caching

#cache?, #cache_configured?, #render_state

Methods included from Rendering

#render_state

Constructor Details

#initialize(*args) ⇒ ViewModel



52
53
54
55
# File 'lib/cell/view_model.rb', line 52

def initialize(*args)
  super
  _prepare_context # happens in AV::Base at the bottom.
end

Instance Attribute Details

#modelObject (readonly)

properties :title, :body



16
17
18
# File 'lib/cell/view_model.rb', line 16

def model
  @model
end

Class Method Details

.property(*names) ⇒ Object



40
41
42
# File 'lib/cell/view_model.rb', line 40

def property(*names)
  delegate *names, :to => :model
end

Instance Method Details

#call(state = :show) ⇒ Object



67
68
69
70
71
# File 'lib/cell/view_model.rb', line 67

def call(state=:show)
  # it is ok to call to_s.html_safe here as #call is a defined rendering method.
  # DISCUSS: IN CONCEPT: render( view: implicit_state)
  render_state(state).to_s.html_safe
end

#cell(name, *args) ⇒ Object



47
48
49
# File 'lib/cell/view_model.rb', line 47

def cell(name, *args)
  self.class.cell(name, parent_controller, *args)
end

#render(options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/cell/view_model.rb', line 57

def render(options={})
  if options.is_a?(Hash)
    options.reverse_merge!(:view => state_for_implicit_render)
  else
    options = {:view => options.to_s}
  end

  super
end