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: Context, 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.



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

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

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



27
28
29
# File 'lib/cell/view_model.rb', line 27

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)


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

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



23
24
25
# File 'lib/cell/view_model.rb', line 23

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

.property(*names) ⇒ Object



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

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

.templatesObject



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

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.



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

def cell(name, model=nil, options={})
  context = Context[options[:context], self.context]

  self.class.cell(name, model, options.merge(context: context))
end

#contextObject



74
75
76
# File 'lib/cell/view_model.rb', line 74

def context
  @options[:context]
end

#to_sObject



124
125
126
# File 'lib/cell/view_model.rb', line 124

def to_s
  call
end