Slide 1

Slide 1 text

Krzysztof Piotrowski RoR developer 2nIT www.2n.pl

Slide 2

Slide 2 text

Trailblazer 2.1 Cells - Lighting Talk

Slide 3

Slide 3 text

Content: ● Cells purpose ● Cells itselfs ● Some code example ● Summary

Slide 4

Slide 4 text

Cells purpose Cells purpose ● Removing business (and other) logic from views ● Code readability goes up by a mile ● Following OOP/SOLID/SRR/etc. ● No more partials and helpers using global state of the app. ● Cells want to segregate your UI into logical fragments ● Rendering a template anywhere you want with eaze ● Providing a logical and clean files structure and architecture

Slide 5

Slide 5 text

Cell https://github.com/trailblazer/cells - View Object à la Controller - Does not have to be coupled with TB - It can render html anywhere (good to be used with emails as well as classic app views) - Not Rails dependent - Layout change with eaze (so controller doesn’t care about it since it is not his responsibility) - Cells will encourage and reward you for building the code for view in a way that provides the application with encapsulated UI fragments having access to only stuff they actually need to render a part of UI/view

Slide 6

Slide 6 text

Object that renders a template

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

proposals_controlller.rb && index.html.haml

Slide 9

Slide 9 text

event_row.rb

Slide 10

Slide 10 text

event_row.haml

Slide 11

Slide 11 text

Proposal::Cell::Index.new(user, current_user: other_user, layout: Cfp::Cell::BaseLayout)

Slide 12

Slide 12 text

● Formats for views you can work on using cells: haml, hamlit, erb, slim ● Cells can handle not only Active Records objects passed to it - they are fine handling basically anything you want. ● Context withinh a cell rendered from controller contains its data by default and passes it further ● You can also generate form inputs via Cells ● You can redefine #show method and pass arguments Few other hints / informations

Slide 13

Slide 13 text

● Summary <

Slide 14

Slide 14 text

Be careful!