Cells v4.1.0 Release Notes
Release Date: 2016-05-08 // almost 8 years ago-
API Fix/Changes
- ๐ All Rails code removed. Make sure to use Cells-rails if you want the old Rails behavior.
๐ The
builds
feature is now optional, you have to includeBuilder
in your cell.class CommentCell < Cell::ViewModel include Cell::Builder builds do |..|
A basic, rendering
#show
method is now provided automatically.ViewModel#render
now accepts a block that can beyield
ed in the view.Passing a block to
ViewModel#call
changed. Usetap
if you want the "old" behavior (which was never official or documented).Comment::Cell.new(comment).().tap { |cell| }
The new behavior is to pass that block to your state method. You can pass it on to
render
, and thenyield
it in the template.def show(&block) render &block # yield in show.haml end
Note that this happens automatically in the default
ViewModel#show
method.๐
Concept#cell
now will resolve a concept cell (Song::Cell
), and not the old-style suffix cell (SongCell
). The same applies toConcept#concept
.concept("song/cell", song).cell("song/cell/composer") #=> resolves to Song::Cell::Composer
This decision has been made in regards of the upcoming Cells 5. It simplifies code dramatically, and we consider it unnatural to mix concept and suffix cells in applications.
In case you were using
@parent_controller
, this doesn't exist anymore (and was never documented, either). Usecontext[:controller]
.::self_contained!
is no longer included intoViewModel
. Please try usingTrailblazer::Cell
instead. If you still need it, here's how.class SongCell < Cell::ViewModel extend SelfContained self_contained!
๐
Cell::Concept
is deprecated and you should be using the excellentTrailblazer::Cell
class instead, because that's what a concept cell tries to be in an awkward way. The latter is usable without Trailblazer.We are hereby dropping support for
Cell::Concept
(it still works).๐ Deprecating
:collection_join
and:method
for collections.
Awesomeness
๐ Introduced the concept of a context object that is being passed to all nested cells. This object is supposed to contain dependencies such as
current_user
, in Rails it contains the "parent_controller" under thecontext[:controller]
key.Simple provide it as an option when rendering the cell.
cell(:song, song, context: { current_user: current_user })
The
#context
method allows to access this very hash.def role context[:current_user].admin? "Admin" : "A nobody" end
The
cell
helper now allows to pass in a constant, too.cell(Song::Cell, song)
๐ New API for
:collection
. If used in views, this happens automatically, but here's how it works now.cell(:comment, collection: Comment.all).() # will invoke show. cell(:comment, collection: Comment.all).(:item) # will invoke item. cell(:comment, collection: Comment.all).join { |cell, i| cell.show(index: i) }
Basically, a
Collection
instance is returned that optionally allows to invoke each cell manually.Layout cells can now be injected to wrap the original content.
cell(:comment, Comment.find(1), layout: LayoutCell)
The LayoutCell will be instantiated and the
show
state invoked. The content cell's content is passed as a block, allowing the layout's view toyield
.This works with
:collection
, too.