Currently the generated files looks like this:
So in the same folder, we find both view pages from the parent widget and widget code from the child widget.
Unrelated information in the same folder == mess.
I propose to change it to:
Generated widgets are saved inside their own folder. Inside a widget'…
…s folder there is a 'views' folder, where its views are located. This makes tree of widgets much more cleaner, since now there is separation between where the code and views are located
│ ├── list
│ │ ├── contents
│ │ │ ├── course
│ │ │ │ └── views
│ │ │ └── views
│ │ ├── header
│ │ │ └── views
│ │ └── views
│ ├── new_course
│ │ └── views
│ └── views
Sorry, that was an example structure give by Nerian. Each 'sub-widget' gets its own directory, which makes it easy to figure out that 'list' is a sub-widget of 'panel' for example.
This pull request is not complete, it just a discussion starter.
I have changed the generators so that they create the aforementioned structure of folders. There are more things that needs to be changed; for example, apotomo need to be aware of the new location of the views files. I don't know how to change that. Perhaps it need to be done at Cells.
This is how the proposed structure looks like for a simple 2 levels widget:
And a complex one:
Looks cleaner. This ain't gonna be easy to introduce since it changes the entire assets layout. Maybe we can have a module AlternativeAssets in cells? Why not start a discussion on the mailing list about that, I guess there will be some good opinions there. Can you send a mail to it?
I think it is better if we just support one way to do it. Less complexity in the long term.
But I agree in that it is a major change. Maybe is time for Cells 4.x.x :)
I'll send an email to the list
where would a "layouts" folder go? as per some of the examples on the apotomo.de site, this was always a question anyway....but with this proposed change, it seem it would be a sibling-folder to Views? or a child? And would it be available to that widget and its descendent, only?
This is just a half baked suggestion but I am wondering is it possible to have rails like directory structure. Widgets are more like of a controller. So we can have a controller folder inside widgets and a view folder. With view folder there will be different folder for each widget. Generally I hate having very deep file structures and its just make them browsing difficult. Instead we can have some navigation convention to quickly find files. Below is an example of what I am thinking
We can put layouts inside the views/ folder of each widget. No need to create a subfolder. We can use naming convention like *_layout to differentiate it from normal views.
Layouts inside the view folder of a widget will be just available to that widget. We can have widgets/views/ where global layouts can be stored. Those would be accessible from all widgets.
The widgets/views/ folder would store both layouts and views. Anything that we want to make available for all widgets. For example, views for pagination.
I prefer a self contained widgets structure instead of spreading every widget on widget/controllers/ and widget/views/. It would be easier to navigate.
Also, as per the mailing list discussion, we can create css/ and js/ folders for each widget and have it work with Sprokets.
That would be totally epic.
widgets/views/ # Accessible by all widgets
This looks seriously good :)
@apotonick Thoughts? :)
I just started working with apotomo these days but this reorganization proposal, including assets, looks much cleaner than the current state. Unless I'm missing something, of course.
Is this still being worked on?
I'm a user of Cells, but not Apotomo. Is there any reason this type of change is happening in Apotomo instead of Cells? I'd much prefer this layout, including the asset pipeline integration. I'm looking at starting to make Cells do this, but was wondering if there was a reason you are all looking to do this at the Apotomo level.
@blazes816 The only reason is that I used Apotomo and not Cells at the time I made this pull request :)
But I agree with you in that this change should be made at Cell's level and then propagate to Apotomo.
Alright great, thanks. Just making sure I wasn't missing something. I'll start on making it work in Cells.
Right, this will go to cells. Can anybody explain how we would test the whole assets change?
Right now is tested like this in Apotomo:
Yeah but this is just the generator, we also have to make the view finding work, and everything is running ok in a Rails app with asset pipeline etc. That's what I'm asking for.
I would imagine the same way assets are tested for Rails core. I'll dig around in their tests and see if I can find anything specific.
Here's what I have so far: https://github.com/blazes816/cells/tree/nested_cells
No asset pipeline yet. Just the nested structure.
Note that render :partial isn't working. I'm working on figuring that out since it looks like rails handles that directly.
Hey @kristianmandrup I checked your fork and it looks like the alternative view layout is pretty simple to implement. I'd love to do that in cells itself. If we can get your coffeescript/.. generators to work and @blazes816 asset pipeline it would be perfect.
Hello! Why don't you consider more Rails-way: app/widgets, app/widgets_views?
Yes, that was also an option I thought about. The only problem with this design, is that it makes it harder to move around a widget, fx changing the namespace. Then you have to synchronize within two separate folders.
app/widgets/controllers and app/widgets/views might be an idea? why not have helpers, decorators or even commands also? Lot's of options!
I'd love to have widgets as a self-contained folder to make reusability across projects as simple as possible. Something like
Or is that stupid? I guess Kristian proposed that a long time ago and I promised him to write it (also, a long time ago) ;-)
Yes, he did it, and I should recreate this patch (it's our agreement :-)). But I think it should be rewritten for Cells...
Yes, that was the alternative approach - breaking the "rails structure convention", which makes it easy to move everything belonging to one widget in one go, like changing internal namespace structure, without having to synchronize in various disparate places!!!
I also believe it belongs more in cells? perhaps next major version (major breaking changes!)
It should be in cells, right. We could introduce a switch where you can have the old behavior back. Now we need to discuss the structure thoroughly before we implement it. BTW- I don't see a problem with breaking Rails' convention here as I am not a big fan of the global directories at all!
This is now implemented in Cells: apotonick/cells@25b65d1