Hacking Typo 5.1.2
I am creating a website that required some data tables. Typo does not have any built in functionality to accomplish this, but since it is just a rails app, it is fairly easy to add such functionality. So here is what I wanted to do and how I accomplished it.
1) Add the tables I need to typo
2) Create the admin screens to add/update/delete data from these tables and integrate them into Typos admin interface.
3) Pull the data from these tables into blog posts in a semi dynamic fashion.
Read on for how I accomplished these tasks.
1) Add tables.
Since Typo has not adopted the Rails 2 convention of using time stamped migrations, I just did this by hand – not a big deal.
2) Create admin screens.
I will assume that you know how to create normal rails models/controllers and views to match your tables. I just did it by using the built in rails script/generate scaffold routine. They don’t need to be fancy, this is just for admin use. Of course when you create these models/controllers and views they have no security and are not part of the Typo interface. When you have them working normally to your satisfaction here is how to add them to Typo admin interface.
a) Move the controller to the admin app/controller/admin directory. Edit the controller code and Change the class declaration from;
class MyController < ApplicationController
to
class Admin::MyController < Admin::BaseController
of course MyController is the name of your controller.
This controller now participates in the Typo admin security system.
To add this controller to the admin interface you will need to edit config/initializers/access_rules.rb
There you will find the AccessConrol.map and a series of map.project_modules below. These modules correspond to the new AccessControl system and to the Admin Menus.
The data tables I added would be considered content so I added the controllers I created to the content map. Just add a line for each controller you wish to access. Now your controller is callable for the admin interface. Note if you don’t add the controller here, the security system will not let you access the controller.
b) Now we have to get the views into the admin area so the controller can find them. Like the controller just move your view subdirectory to the view admin subdirectory. Your views will now use the admin layout. The final change you should make is to edit your views to further integrate them into the admin interface. First set the @page_heading variable and add the code to pull in the appropriate submenu. The beginning of each of my views looks like this:
<% @page_heading = "My Page Heading" %>
<% subtabs_for(:content) %>
You should change the :content to match the menu you placed your controller under.
All done.
3) Pull the data from these tables into blog posts in a semi dynamic fashion.
Now for the harder part – of course since I already did it, it can be easy for you. I created a textfilter macro that allows me to call rails methods in which I create the view code I want to display for the database record. I called this macro RunCode. So in the blog post I can simply enter
Have fun hacking Typo.
Trackbacks
Use the following link to trackback from your own site:
http://www.pigstye.net/trackbacks?article_id=hacking-typo-5-1-2&day=14&month=08&year=2008
