module Cell::ViewModel::Rendering

Public Instance Methods

call(state=:show, *args, &block) click to toggle source

Invokes the passed method (defaults to :show) while respecting caching. In Rails, the return value gets marked html_safe.

# File lib/cell/view_model.rb, line 91
def call(state=:show, *args, &block)
  content = render_state(state, *args, &block)
  content.to_s
end
render(options={}, &block) click to toggle source

render :show

# File lib/cell/view_model.rb, line 102
def render(options={}, &block)
  options = normalize_options(options)
  render_to_string(options, &block)
end
show(&block) click to toggle source

Since 4.1, you get the show method for free.

# File lib/cell/view_model.rb, line 97
def show(&block)
  render(&block)
end

Private Instance Methods

render_state(*args, &block) click to toggle source
# File lib/cell/view_model.rb, line 113
def render_state(*args, &block)
  __send__(*args, &block)
end
render_template(template, options, &block) click to toggle source
# File lib/cell/view_model.rb, line 117
def render_template(template, options, &block)
  template.render(self, options[:locals], &block) # DISCUSS: hand locals to layout?
end
render_to_string(options, &block) click to toggle source
# File lib/cell/view_model.rb, line 108
def render_to_string(options, &block)
  template = find_template(options)
  render_template(template, options, &block)
end