[ Home Page ] [ Eiffel Archive ] [ Eiffel Classes and Clusters]

Arc de Triomphe clipart (2486 bytes)

eHTML: A HTML formatting library for SmallEiffel

Written by Lyn Headley.

Version 0.1

ehtml_0_1.tar.gz (5,000 bytes) - source code
laheadle@cs.uchicago.edu Lyn Headley (maintainer) mail address.

eHTML: A HTML formatting library for SmallEiffel

I've written the core functionality and inheritance hierarchy for an HTML formatting library (tentatively called eHTML). The basic idea is that there is a class for each HTML entity, plus a few base classes for behavior and implementation.

The (preliminary but working) code can be found here (tested under SE, requires GOBO):

The base class of any HTML element is HT_ELEMENT. This has features dealing with attributes (key=value pairs found in basically all elements) and has a feature which generates a tag, from a (deferred) feature tag_text, so e.g. the <title> tag has tag_text title. HT_ELEMENT also declares the feature to_html, which is the main method clients call to get a stringified version of the markup which encodes the object.

Right beneath HT_ELEMENT is HT_CONTAINER, the base class for elements which contain other elements (including the special case of HT_RAW, which is just a way to type strings as HT_ELEMENTs so they can be put into HT_CONTAINERs). This does all the work of inserting and rendering the contained elements. It also introduces the notion of an end tag, which of course container elements require. HT_CONTAINER also inherits from the gobo class DS_ARRAYED_LIST[HT_ELEMENT].

One step below HT_CONTAINER is HT_RAW_WRAPPER, a base class for things like <title> and <b>, which (usually) simply surround some text. for this common case, HT_RAW_WRAPPER provides the creation function make_with(text: STRING).

Once this infrastructure has been set up, the concrete HTML classes become really simple. Here is HT_TITLE, for instance:

class HT_TITLE

      redefine tag_text


   tag_text: STRING is "title"
end -- class HT_TITLE

here is how you might use the library(simplified version of a real feature in my soon-to-be-released Web app):

   succeeded is
         html: HT_HTML
         bold: HT_B
         br: HT_BR
         link: HT_A
         html.set_title("Referendum: Login Successful") 
         !!bold.make_with("Thank you.  You are now logged in")
         !!bold.make_with("(Assuming your browser supports cookies)")
      end -- succeeded

I find all those temporaries and creation routines a bit jangly. Maybe I'll make a factory class.

Check out the code. I'd appreciate any comments, criticism, or beer.

Lyn Headley: laheadle@cs.uchicago.edu
Lyn's Homepage: http://www.cs.uchicago.edu/~laheadle/
29 September 1999 (Added to Eiffel Forum Archive: 23 December 1999)

[ Home Page ] [ Eiffel Archive ] [ Eiffel Classes and Clusters]