-
Notifications
You must be signed in to change notification settings - Fork 8
Architecture Components
Turbinado adds components to the usual Rails MVC organization. Components are a way to group together a Controller and Views that are tightly related and are used by other Controllers and Views. Components are very similar to Rails’ Cells. Many of the details of Components’ Controllers and Views are the same as for regular Controllers and Views so those details will be omitted here.
As an example of the creation and usage of a component, see:
- /App/Components/Page/Controller.hs – the Controller for the Page Components
- /App/Components/Page/Views/List.hs – the View for a list of Pages
- /App/Components/Page/Views/Show.hs – the View for a particular Page
- /App/Controllers/Architecture.hs – a Controller which uses the Page Component (actually, the Component is used in the View)
- /App/Views/Architecture/Show.hs – a View which uses the Page Component (look for the insertComponent call)
Many pages on the Turbinado website use and display Pages. Rather than having every controller understand how to load and display a Page, all of the Page load/display functionality was placed into the Page Component. Now it easy for any Controller/View to use Page functionality without having to understand Pages.
Components have:
- A single controller in /App/Components/ComponentName/Controller.hs.
- A set of Views in /App/Components/ComponentName/Views/*.hs.
Components are called in Views in this example as follows:
<% insertComponent "Page" "ListOnly" [("pages-prefix", "architecture")] %>
This inserts a Component called “Page” and calls the “ListOnly” function of the Component. In addition, a setting is created with “pages-prefix” equal to “architecture”. This particular call inserts a list of Pages whose ids start with “architecture” and is used on the Architecture page to show a list of Architecture Pages.