Module: Cells::Rails::ActionController
- Defined in:
- lib/cells/rails.rb
Instance Method Summary collapse
- #cell_for(name, *args, &block) ⇒ Object (also: #cell)
- #concept_for(name, *args, &block) ⇒ Object (also: #concept)
-
#expire_cell_state(cell_class, state, args = {}, opts = nil) ⇒ Object
Expires the cached cell state view, similar to ActionController::expire_fragment.
-
#render_cell(name, state, *args, &block) ⇒ Object
Renders the cell state and returns the content.
Instance Method Details
#cell_for(name, *args, &block) ⇒ Object Also known as: cell
6 7 8 9 |
# File 'lib/cells/rails.rb', line 6 def cell_for(name, *args, &block) return Cell::Rails::ViewModel.cell(name, self, *args, &block) if args.first.is_a?(Hash) and args.first[:collection] # FIXME: we only want this feature in view models for now. ::Cell::Base.cell_for(name, self, *args, &block) end |
#concept_for(name, *args, &block) ⇒ Object Also known as: concept
12 13 14 |
# File 'lib/cells/rails.rb', line 12 def concept_for(name, *args, &block) return Cell::Concept.cell(name, self, *args, &block) end |
#expire_cell_state(cell_class, state, args = {}, opts = nil) ⇒ Object
Expires the cached cell state view, similar to ActionController::expire_fragment. Usually, this method is used in Sweepers. Beside the obvious first two args cell_name and state you can pass in additional cache key args and cache store specific opts.
Example:
class ListSweeper < ActionController::Caching::Sweeper
observe List, Item
def after_save(record)
expire_cell_state :my_listing, :display_list
end
will expire the view for state :display_list in the cell MyListingCell.
50 51 52 53 |
# File 'lib/cells/rails.rb', line 50 def expire_cell_state(cell_class, state, args={}, opts=nil) key = cell_class.state_cache_key(state, args) cell_class.expire_cache_key(key, opts) end |
#render_cell(name, state, *args, &block) ⇒ Object
Renders the cell state and returns the content. You may pass options here, too. They will be around in @opts.
Example:
@box = render_cell(:posts, :latest, :user => current_user)
If you need the cell instance before it renders, you can pass a block receiving the cell.
Example:
@box = render_cell(:comments, :top5) do |cell|
cell.markdown! if config.parse_comments?
end
31 32 33 |
# File 'lib/cells/rails.rb', line 31 def render_cell(name, state, *args, &block) ::Cell::Rails.render_cell_for(name, state, self, *args, &block) end |