require 'rexml/document' require 'rexml/xpath' module BuildMaster class Logo attr_accessor :path, :link, :text def initialize @link = 'index.html' @text = 'logo' end end class MenuGroup attr_reader :title, :link, :items, :more attr_writer :title, :link, :more def initialize(title, link) @title = title @link = link @items = Array.new end def add_to_menu_items item = MenuItem.new('item', nil) @items.push(item) return item end def menu_item(title, link) add_item(MenuItem.new(title, link)) end def add_item(item) @items.push(item) end end class MenuItem attr_reader :title, :link attr_writer :title, :link def initialize(title, link) @title = title @link = link end end class Releases attr_reader :stable_version, :pre_release_version, :snap_shot_version, :download_link, :versioning_link attr_writer :stable_version, :pre_release_version, :snap_shot_version, :download_link, :versioning_link def initialize @pre_release_version = 'n/a' @snap_shot_version = 'n/a' @versioning_link = 'versioning.html' end end class TemplateBuilder attr_accessor :title_header, :css_path, :news_rss, :contact_admin attr_reader :logo, :menu_groups def initialize @title_header = '' @css_path = 'buildmaster.css' @logo = Logo.new @menu_groups = Array.new @contact_admin = 'contact.html' end def add_to_menu_groups group = MenuGroup.new('group', nil) menu_groups.push(group) return group end def menu_group(title, link = nil) group = MenuGroup.new(title, link) menu_groups.push(group) return group end def left_bottom_logo if (@left_bottom_logo.nil?) @left_bottom_logo = Logo.new end return @left_bottom_logo end def releases if (@releases.nil?) @releases = Releases.new end return @releases end def generate return load_template end def content return load_template_content end private def load_template content = load_template_content return REXML::Document.new(content) end def generate_logo_text if (logo.path) return "\"#{logo.text}\"" else return logo.text end end def generate_menu_groups result = "" menu_groups.each do |menu_group| menu_group_content = <

#{generate_menu_group_content(menu_group)}

CONTENT result += menu_group_content end return result end def generate_menu_group_content(menu_group) if (menu_group.link) return "#{menu_group.title}" else return menu_group.title end end def generate_menu_group_item_content(items) result = '' items.each do |item| item_content = <#{item.title} CONTENT result = result + item_content end return result end def generate_more_item(link) return '' unless link return "
  • More...
  • " end def generate_left_bottom_logo() content = '' logo = left_bottom_logo() if (logo.path) content = <