Class: Cell::ViewModel
- Inherits:
 - 
      Object
      
        
- Object
 - Cell::ViewModel
 
 
- Includes:
 - Caching, Prefixes, Layout, ProcessOptions, Rendering, TemplateFor
 
- Defined in:
 - lib/cell/layout.rb,
lib/cell/view_model.rb 
Direct Known Subclasses
Defined Under Namespace
Modules: Escaped, Helpers, Layout, Partial, ProcessOptions, Rendering, TemplateFor Classes: Context, OutputBuffer
Instance Attribute Summary collapse
- 
  
    
      #model  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute model.
 
Class Method Summary collapse
- 
  
    
      .call(model = nil, options = {}, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Public entry point.
 - .controller_path ⇒ Object
 - .property(*names) ⇒ Object
 - .templates ⇒ Object
 
Instance Method Summary collapse
- 
  
    
      #cell(name, model = nil, options = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Build nested cell in instance.
 - #context ⇒ Object
 - 
  
    
      #initialize(model = nil, options = {})  ⇒ ViewModel 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of ViewModel.
 - #to_s ⇒ Object
 
Methods included from Abstract
Methods included from Util
Methods included from Layout
Methods included from ProcessOptions
Methods included from TemplateFor
Methods included from Caching
#cache?, #cache_store, included, #render_state
Methods included from Rendering
Methods included from Prefixes
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, ={}) setup!(model, ) end  | 
  
Instance Attribute Details
#model ⇒ Object (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, ={}, &block) if model.is_a?(Hash) and array = model[:collection] return Collection.new(array, model.merge(), self) end build(model, ) end  | 
  
.controller_path ⇒ Object
      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  | 
  
.templates ⇒ Object
      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, ={}) context = Context[[:context], self.context] self.class.cell(name, model, .merge(context: context)) end  | 
  
#context ⇒ Object
      74 75 76  | 
    
      # File 'lib/cell/view_model.rb', line 74 def context @options[:context] end  | 
  
#to_s ⇒ Object
      124 125 126  | 
    
      # File 'lib/cell/view_model.rb', line 124 def to_s call end  |