New page templates or categories code

New page templates or categories code

In some case it might be useful to add a new page that is part of a particular category, or has some default content. e.g. Add a new bug report, or Add a new contact).

Bil Kleb has had success in writting this (copied from soks mailing list):

Earlier, we had discussed adding various page categories, i.e., templates

FWIW, here is what I hacked in to get there:

start.rb:


# defined a new type of summary:
class AutomaticCategorySummary
  def initialize( wiki, pagename )
    plural = pagename.sub(/y$/,'ie') + 's'
    AutomaticSummary.new( wiki, {
                          :regexp_for_title => /#{pagename}:/i,
                          :lines_to_include => 10,
                          :reverse_sort => true,
                          :pagename => "All #{plural}" } )
    AutomaticSummary.new( wiki, {
                          :regexp_for_title => /#{pagename}:/i,
                          :max_pages_to_show => 1,
                          :lines_to_include => 10,
                          :reverse_sort => true,
                          :pagename => "Latest #{plural}" } )
  end
end

# added :categories key to the CUSTOMSETTINGS hash:
 :categories => [ 'Trip report', 'Contact', 'Phone Call', 'Idea', 'Story', 'Thought' ]

# added to self.start:
  CUSTOMSETTINGS[:categories].each do |name|
    AutomaticCategorySummary.new( wiki, name )
  end if CUSTOMSETTINGS.has_key? :categories

view/frame.rhtml:


# replaced "Add a new .*" section:
  Add new:
  <a href='<%= url 'Type a title here', 'edit' %>'>+ Page</a>
  <% if $SETTINGS.has_key? :categories %>
    <% $SETTINGS[:categories].each do |name| %>
      <a href='<%= url "#{name}: Type a title here", 'edit' %>'>+ <%= name %></a>
    <% end %>
  <% end %>
  <a href='<%= url 'Picture of Type a title here', 'edit' %>'>+ Image</a>
  <a href='<%= url 'Attached Type a title here', 'edit' %>'>+ File</a>

views/Page_edit.rhtml


 <td><input name='newtitle' size = '60' value='<%= pagename %>'
            onClick="this.value=this.value.replace('Type a title here','')"/></td>
Edit this page or watch for changes using RSS.