-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inline templates #309
Comments
+1 ... i'm finding the similar approach in react.js for simple 'templates' is really nice ... having it along with the normal cell template files would be a nice option to add .... |
Wow, I love this "using the model part" idea - I never thought of this! It shouldn't be hard to implement. We could simply catch the block and evaluate it in cells context. Many people use I had a slightly different idea a few years ago and I was evaluating either Erector or Ambre where you have the templates defined in Ruby, in the cell itself instead of a rather clumsy template snippet. This does not only speed up things but also allows way better overriding semantics, where you can programmatically overwrite parts of your "view" in subclasses. class SongCell < Cell::ViewModel
view do
div do
address1
address2
end
end I remember I loved the Erector gem by @alexch but we never integrated the two projects. Maybe it's time now? 🎆 |
for reference erector and arbre Thats a fuckin' amazing idea... specially because we can "overwrite" and customize views (manually or programmatically) using ruby OOP trying to go one step further on @saturnflyer idea, what is we could create "wrappers" for the view? so we could do: <%= cell :address, location do %>
<%= address1 %><br />
<%= address2 %><br />
<%= address3 %><br />
<%= city_state %><br />
<%= country_and_postal %>
<%- end -%> or
this would be a great addition to "form-builder-sprite-thing" no @apotonick ? |
Another Erector spinoff is https://github.com/ageweke/fortitude which is a On Wed, Jul 22, 2015 at 8:40 AM, Celso Fernandes [email protected]
Alex Chaffee - [email protected] |
I attempted to implement this but don't understand enough about cells structure to do it quickly. def show(&block)
if block
instance_eval(&block)
else
render
end
end But it seems like the block is ignored. Related to the template builders, I'd rather bake in easy support but not the actual implementation. There are already 3 options (Erector, Arbre, and Fortitude) mentioned. Why not take the approach that cells does with rails helpers and just force users to add what they need? |
Both Erector and Fortitude use constructors to initialize view objects
(because, you know, OO), so it would be easy to pass in a cell as a
parameter that then turns into an instance variable. Or to pass in the
cell's model.
Or alternately to give a cell a "view" method that returns a widget
pre-initialized to point to the cell itself. Or to automagically make each
of the model's fields a view instance var. Or...
I've tried a few times but never quite wrapped my head around the Cells
architecture. Can you point me to a tutorial? Or better, a fully functional
app project?
|
I'm kicking the tires of cells and am using a cell to handle the display of an address. I've found that the view object is useful for handling display logic, but the use of an extra template file seems like a lot for the small case I have.
Here's an example cell. It has some simple methods in it so that if I only have 1 value out of a typical pair, it'll only display the one value and won't have hanging commas with something like
, New Netherland
orFranklin,
The template is as small as this:
As I was hooking this up, I wondered about just using the model part of it and not the template file:
I'm not sure that my app would stay this way, but it would allow me to play with handling the display logic and adjusting the layout before deciding to place it into a template file.
I started digging into the code but before trying to figure it out, I wanted both a sanity check and to see if this is something you'd be interested in having in the project.
The text was updated successfully, but these errors were encountered: