Another simple tutorial which builds upon the SimpleLetter tutorial shown before. This is part of the SimpleTutorials section of the web site.

NOTE! This is still under construction as of

Error: Failed to load processor Timestamp
No macro or processor named 'Timestamp' found

, please check back in a few days.

One of the annoying things about the basic Streamlined Framework is that all the default menus have TBD as their default strings. So let's take a look at what it takes to update these and start changing them to achive our own look.

To save time, I'm going to assume that you've already done the SimpleLetter tutorial, and I'm just going to copy it all to a new directory so that we save time and energy.

> cp -r SimpleLetter SimpleLetterMenu

Now the basic definitions for the menus are found in vendor/plugins/streamlined/lib/streamlined/helpers/layout_helper.rb, and the one we're interested in looks like this:

def streamlined_side_menus
  [
    ["TBD", {:action=>"list"}]
  ]
end

The next step is to edit the file app/helpers/letter_helper.rb and make it look like this:

module LetterHelper
  def streamlined_side_menus
    [
     ["List It", {:action=>"list"}]
    ]
  end
end

Now let's fire up the server

> script/server

and see what we get when we goto !http://localhost:3000/letter

Notice how the menu on the left has changed into List It as we asked it to. Very nice. Now let's add some more entries in the file app/helpers/letter_helper.rb and make it look like this:

module LetterHelper
  def streamlined_side_menus
    [
     ["New", {:action=>"new"}],
     ["List It", {:action=>"list"}]
    ]
  end
end

Don't forget the comma at the end of line, to keep the entries seperated. If you forgot it, you'll get a decent error showing you what went wrong. This is one area I prefer about Perl, where a trailing comma is just ignored and does not create an extra entry in an array.

We can do the same customization with the top menu as well, since that is also pre-defined for us in the vendor/plugins/streamlined/lib/streamlined/helpers/layout_helper.rb file:

def streamlined_top_menus
  [
    ["TBD", {:action=>"new"}]
  ] 
end

In this example, I'll instead define my own version in the application wide helper file app/helpers/application_helper.rb so that we have consistent menus for all controllers. Before we had just modified the helper for the letter controller.

Here's what the file looks like now:

# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def streamlined_top_menus
    [
     ["New Letter", {:action=>"new"}]
    ]
  end
end

So you can now reload the web page and see how the top menu is updated to reflect what you say. But since we only have one controller in this application, how do we know that this will work the way we want? So let's do the following, after first stopping the server:

> script/generate controller person
> script/server
>>>

Now we can goto the URL http://localhost:3000/person/ and see what we get. Nothing. We didn't update the controller for the person to know how to act like a Streamlined Framework application. So we now need to do a quick edit to app/controllers/person_controller.rb to make it looks like this:

 class PersonController < ApplicationController
  acts_as_streamlined
end

We then cruise back to !http://localhost:3000/person/ and we now see the People table with two columns of data, along with the usual show, edit, and delete buttons for each row. But notice how the menu on the left has changed back to the TDB we originally had. As you probably remember, we only over-rode the side menu in the app/helpers/letter_helper.rb file, so it only affected the letter controller and it's methods.

Now let's take another look at this screen. What's ugly about it? Why the second column is, where it lists Letters that each person is linked too. Depending on how much data you've entered while playing, you may or may not have multiple rows for the same person listed. So let's see how we can tweak the display parameters.

> mkdir app/streamlined

This directory should probably be created by default when Streamlined is installed, but it's not at of 0.9RC2, so we have to do it ourselves.

Now we're going to edit the file app/streamlined/person_ui.rb and tell it which columns we want displayed:

  Streamlined.ui_for(Person) do
    user_columns :name 
  end

Now cruise back to http://localhost:3000/person/ and see how the person view looks now.

more to follow

John