Class: Cell::ViewModel
- 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
Defined Under Namespace
Modules: Helpers, LinkToHelper
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
properties :title, :body.
Attributes inherited from Rails
Attributes inherited from Rack
Attributes included from Caching
#cache_configured, #cache_store
Class Method Summary collapse
Instance Method Summary collapse
- #call(state = :show) ⇒ Object
- #cell(name, *args) ⇒ Object
-
#initialize(*args) ⇒ ViewModel
constructor
A new instance of ViewModel.
- #render(options = {}) ⇒ Object
Methods included from Helpers
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
Methods inherited from Base
cell_for, class_from_cell_name
Methods included from Builder::ClassMethods
Methods included from Base::SelfContained
Methods included from Base::Prefixes
Methods included from Caching
#cache?, #cache_configured?, #render_state
Methods included from Rendering
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
#model ⇒ Object (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(={}) if .is_a?(Hash) .reverse_merge!(:view => state_for_implicit_render) else = {:view => .to_s} end super end |