Comments (9)
@apotonick This is really great news. I've been using cells for years and it has served me wonderfully. Thank you for all the work you and the others have put into it. I'm looking forward to the new version. I really mean it: thank you!!!
from cells.
Foremost encapsulation. I've created created messy frontends with rails partials. That never happened to me while i was using cells. Especially, when creating them in the controller. I am actually considering rails for some future projects again - just because of cells.
Nesting? I've had only a few cases, where I had actually missed it in terms of composition. Usually I try to keep the components simple and flat. But that's me.
In my line of work so far, I haven't run into any issues with html escaping or maybe I have, but then it hasn't bothered me as much to really remember it.
Yes, I use context, when it's the only feasible solution. If overused, it can turn into messy solutions from a standpoint of code readability.
I am sorry, i can't be more specific at the moment.
from cells.
For me, the best feature is the encapsulation.
Not really ever missed 'proper' nesting - in fact I'm not really sure what this would be?
Not having easy control over the initializer is a little bit odd at times. Or rather I guess always having to have a model
is. Sometimes we have cells that have no model, but do take a variety of options to alter their rendering. We also pretty much always do alias something model
in every cell in order to have better documentation as to what the cell's model is.
Escaping was a problem for us, but we actually put in for ourselves (see attached code)
We use context
, but not in the way you might think. We fetch current_user
via context[:current_user] || context[:controller].current_user
(which allows us to pass in current_user in tests where the controller method isn't available.
module Cell
# Cells do not escape any html by default, which might be dangerous.
# Overriding setting below re-enables escaping and html_safe? feature
module Slim
def template_options_for(_options)
{
template_class: ::Slim::Template,
suffix: "slim",
disable_escape: false,
escape_code: false,
use_html_safe: true,
buffer: "@output_buffer",
generator: Temple::Generators::RailsOutputBuffer
}
end
module Helpers
def with_output_buffer(block_buffer = ActionView::OutputBuffer.new)
old_buffer = @output_buffer
@output_buffer = block_buffer
yield
@output_buffer = old_buffer
block_buffer
end
end
Cell::ViewModel.include(Helpers)
end
module HtmlSafetyFixes
module HtmlSafe
def html_safe?
true
end
end
module CollectionJoin
def join(separator = '')
separator = ''.html_safe + separator
outputs = @ary.map.with_index do |model, i|
cell = @cell_class.build(model, @options)
block_given? ? yield(cell, i) : cell
end
outputs
.map { |output| ''.html_safe + output }
.join(separator)
.html_safe
end
end
::Cell::ViewModel.include(HtmlSafe)
::Cell::Collection.include(HtmlSafe)
::Cell::Collection.prepend(CollectionJoin)
end
end
from cells.
@mkastner fixed it, thanks for pointing it out. We released new website for TRB which made this URL invalid.
from cells.
Hey @mkastner we actually have some goodies planned for Cells 5.
from cells.
😊 Thanks @mkastner! Since you're here, can you answer me a few questions?
- What do you like about Cells? (e.g. encapsulation?)
- What is definitely missing? (e.g. proper nesting)
- Have you had issues with HTML escaping? (we're working on a different approach here)
- Do you use "advanced" features such as
:context
?
from cells.
@samstickland Oh cool, thanks! One thing I want to change is that cells always receive one object only in the initializer, one that responds to a hash interface.
from cells.
@apotonick We also ended up adding a module to make the option handling easier.. The purpose was so that the code ends up self-documenting the options the cell supports. It looks like this:
class SomeCell < Trailblazer::Cell
include ::Cell::OptionHandling
option :option_one
option :option_two, required: true
option :option_three, default: 'something'
And the methods option_one
, option_two
are available in the cell.
from cells.
BTW, we've deployed a change on documentation website which handles broken URLs and suggests new page links 🍻
from cells.
Related Issues (20)
- Cells + Airbrake issue - double exceptions raised HOT 2
- Using Cells with Rails engine that has html.erb partials not being picked up HOT 5
- Confusing file structure - views or view? HOT 7
- Template Missing ... again! HOT 21
- how to render erb templates when haml/hamlit and erb extensions installed HOT 3
- Render an array inside view cell HOT 1
- Escaping implementation seems to be a glaring LAYER VIOLATION, methinks.
- Is there some way to do html escaping default with options?
- Publish latest version on Rubygems HOT 10
- should default to file_name.html.erb or .haml HOT 1
- Can't get form_with to work from a cell in Rails 6 HOT 3
- License HOT 1
- Form Input renders as raw text in cell HOT 1
- Feature Request: Support Recyclable Cache Key
- Default cache key produces clashes HOT 4
- Options hash is same instance passed to each cell when using collections HOT 1
- Slim v5 breaks cells HOT 9
- Ruby 3.0 ArgumentError: wrong number of arguments error with keyword args for Cell::Testing
- Ruby 3.0 ArgumentError: wrong number of arguments error with Caching
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cells.