Ruby, on its own, does not support a program created of labelled fragments, so we embed the code fragments in XML to label and organize them.
|SiteMap XML format|
|Section||XML Tag||Typical Usage||Purpose|
|Whole Program||<sitemap>||<sitemap>…</sitemap>||A pair of <sitemap></sitemap> tags enclose the entire specification.|
|The <class_body> tag declares any libraries that need to be imported.|
|Variable Definitions||<var>||<var name="fruit_bar" default='"hello"'/>
|Each <var tag defines one variable (aka attribute) on the instance. The tag generates ruby variable definitions. There many be multiple <var> tags. Note how you must use both single and double quotes around the default value, to satisfy both XML and Ruby. Note how you abbreviate, leaving off the </var> and use a trailing /> instead.|
|Conditional Definitions||<cond>||<cond name="not_yet_verified">
`logged_in` && user.verified == 0
|Each <cond tag defines a named boolean expression. The names of conditions will become the names of Ruby methods. The CDATA contents will become the body of the corresponding method definition, usually just single boolean expression, but it could be more complex chunk code containing return statements. You may also use any of the defined @instance variables in your computation. See the sample sitemap.xml for more complex examples. You can include any Ruby code that you would include in an instance method (that's what's generated.) You have access to the instance's variables, attributes, and any classes, etc. that would be available to any other Ruby instance method.|
|Page Definitions||<page>||<page url="/static/home" name="Home"
title="::BuddySystem:: Home" />
|Each <page tag defines one generated HTML page.
The fields are:
|Conditional Page Definitions||<page>||
title="::BuddySystem:: New Participant" link_text='New Participant'>
|This is where the payback for the awkward XML syntax comes. You can define
boolean conditions for a page that must be satisfied for the page to be relevant,
to appear on the menu. This is almost identical to the <page
definition earlier. What is different is the addition of embedded references to
the boolean conditions defined earlier. Also there in a the rurl
parameter on the <page tag. Note the that the
condition names are enclosed in graves ` , not double or single quotes.
<item page="Home" hide_in_nav='false'>
|Here XML comes into its own. The nested structure of XML maps perfectly onto
the nested structure of menus. We have a hierarchy with a <menu
tag at the top defining each menu. Under that are nested <item
tags, defining the various menu times and subitems. In this example the root
menu has an item that links to the Home page and a subitem under that links to
the About page. The precise wordings for the various links come from the <page
tags defined earlier.
The fields on the <item tag are:
<item page="Edit_phone" hide_in_nav='true'>
<value><![CDATA[ params[:id] ]]>
|<param tags let you extend the URL that the menu
item links to. You can specify a suffix that is either part of the URI or a
The field on the <param tag is:
Note how Ruby string literals are enclosed in both single and double quotes to satisfy both XML and Ruby.