[as2api-dev] as2lib to as2api

David Holroyd dave at badgers-in-foil.co.uk
Sun Sep 11 23:25:15 UTC 2005


On Sat, Aug 27, 2005 at 02:58:27PM +0200, martin heidegger wrote:
> > On Thu, Aug 25, 2005 at 10:15:06PM +0200, martin heidegger wrote:
> > > we from the as2lib are just discussing about changing from visdoc to
> > > as2api because its rather problematic to argue with some developers:
> > > go get a mac to work with us, and there are some questions open:

> > > * How is the current state for a different output template. How
> > > complex is it to write such or template or are you planning to update
> > > your template. We would invest some time for this...

> > Roughly, what changes are you considering?
> 
> Two frame - frameset and a dhtml tree, that is based on xhtml ... 

So, I've been doing some reorganisation of the output-generating code
to make this task a little easier.  I've got things to the point where
it's possible to hack-in some code to replace the existing frameset
stuff *assuming that you are invoking the ruby scripts* rather than
using the stand-alone (exe) versions.

This is far from being a final / stable / proper way of changing the
templates, but should give you an idea of what custom templates would
look like.

Attached is an example customisation which replaces the standard
three-frame layout with a two-frame version; the left hand frame
containing a (non-DHTML) tree of packages and types.  This is simply to
serve as an example, so it's fairly rough.

To make use of this hack (and assuming that you've got the attached file
in the current directory, together with the rest of the as2api files),
the option

  -r frameset_override

must be added to your ruby invocation before the as2api.rb script is
named.  For example:

  ruby -r frameset_override as2api.rb \
       --classpath eg/as2lib_0.9.2/src \
       org.as2lib.*

For a while, you'll be able to see an example of the resulting output
here:

 http://www.badgers-in-foil.co.uk/projects/as2api/tmp/tree-example/frameset.html


hope that helps,
dave

-- 
http://david.holroyd.me.uk/
-------------- next part --------------

require 'output/html/driver'

# reopen the class originally defined in output/html/driver
class PageListBuilder
  # redefine the instance methods of PageListBuilder which control frameset
  # production (will produce warnings -- there's a way to avoid this by
  # deleting the old method definitions first, but I forget the required magic)
  
  def build_toplevel_frameset_pages(list)
    list << TwoFrameFramesetPage.new()
    list << TreeNavFramePage.new(@type_agregator)
  end

  # just replace original definition with no-op method
  def build_package_frameset_pages(list, package); end
end

# simple frameset
class TwoFrameFramesetPage < Page
  def initialize
    super("frameset")
    @doctype_id = :frameset
  end

  def generate_content
    html_frameset("cols"=>"20%,80%") do
      html_frame("src"=>"treenav-frame.html",
			"name"=>"all_packages_frame",
			"title"=>"Navigation")
      html_frame("src"=>"overview-summary.html",
                        "name"=>"type_frame",
                        "title"=>"Package and type descriptions")
      html_noframes do
	html_body do
	  html_a("Non-frameset overview page", {"href"=>"overview-summary.html"})
	end
      end
    end
  end

  def extra_metadata
    # this page isn't interesting
    {
      "robots" => "noindex"
    }
  end
end


# tree navigation for left-hand frame
class TreeNavFramePage < Page

  def initialize(type_agregator)
    super("treenav-frame")
    @type_agregator = type_agregator
    @doctype_id = :transitional
  end

  def generate_content
    hash_tree = build_tree(@type_agregator.types)
    html_body do
      html_h3("All Types")
      gen_tree(hash_tree)
    end
  end

  def extra_metadata
    # this page isn't interesting
    {
      "robots" => "noindex"
    }
  end

  private

  # un-flatten package names into a tree of Hash objects, with types at leaves
  def build_tree(types)
    tree = {}
    types.each do |type|
      # TODO: cope with default package,
      namespace = tree
      type.package_name.split(/\./).each do |bit|
	ns = namespace[bit]
	if ns.nil?
	  ns = {}
	  namespace[bit] = ns
	end
	namespace = ns
      end
      namespace[type.unqualified_name] = type
    end
    tree
  end

  # recursively generate HTML for the nav tree
  def gen_tree(node)
    html_ul do
      node.keys.sort_by{|k| k.downcase}.each do |key|
	html_li do
	  val = node[key]
	  if val.is_a?(Hash)
	    pcdata(key)
	    gen_tree(val)
	  else
	    link_type(val, false, {"target"=>"type_frame"})
	  end
	end
      end
    end
  end
end



# vim:softtabstop=2:shiftwidth=2


More information about the as2api-dev mailing list