Class: Cell::ViewModel

Inherits:
Object
  • Object
show all
Extended by:
Abstract, Util, Helpers, Uber::Delegates, Uber::InheritableAttr
Includes:
Caching, Prefixes, Layout, ProcessOptions, Rendering, TemplateFor
Defined in:
lib/cell/layout.rb,
lib/cell/view_model.rb

Direct Known Subclasses

Concept

Defined Under Namespace

Modules: Escaped, Helpers, Layout, Partial, ProcessOptions, Rendering, TemplateFor Classes: OutputBuffer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Abstract

abstract!, abstract?

Methods included from Util

util

Methods included from Layout

included

Methods included from ProcessOptions

#process_options!

Methods included from TemplateFor

#find_template, #template_for

Methods included from Caching

#cache?, #cache_store, included, #render_state

Methods included from Rendering

#call, #render, #show

Methods included from Prefixes

#_prefixes, included

Constructor Details

#initialize(model = nil, options = {}) ⇒ ViewModel

Returns a new instance of ViewModel.



66
67
68
# File 'lib/cell/view_model.rb', line 66

def initialize(model=nil, options={})
  setup!(model, options)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



25
26
27
# File 'lib/cell/view_model.rb', line 25

def model
  @model
end

Class Method Details

.call(model = nil, options = {}, &block) ⇒ Object

Public entry point. Use this to instantiate cells with builders.

SongCell.(@song)
SongCell.(collection: Song.all)


45
46
47
48
49
50
51
# File 'lib/cell/view_model.rb', line 45

def call(model=nil, options={}, &block)
  if model.is_a?(Hash) and array = model[:collection]
    return Collection.new(array, model.merge(options), self)
  end

  build(model, options)
end

.controller_pathObject



21
22
23
# File 'lib/cell/view_model.rb', line 21

def self.controller_path
  @controller_path ||= util.underscore(name.sub(/Cell$/, ''))
end

.property(*names) ⇒ Object



37
38
39
# File 'lib/cell/view_model.rb', line 37

def property(*names)
  delegates :model, *names # Uber::Delegates.
end

.templatesObject



13
14
15
# File 'lib/cell/view_model.rb', line 13

def templates
  @templates ||= Templates.new # note: this is shared in subclasses. do we really want this?
end

Instance Method Details

#cell(name, model = nil, options = {}) ⇒ Object

Build nested cell in instance.



62
63
64
# File 'lib/cell/view_model.rb', line 62

def cell(name, model=nil, options={})
  self.class.cell(name, model, options.merge(context: context))
end

#contextObject

TODO: explicit test.



70
71
72
# File 'lib/cell/view_model.rb', line 70

def context # TODO: explicit test.
  @options[:context]
end

#to_sObject



110
111
112
# File 'lib/cell/view_model.rb', line 110

def to_s
  call
end