note description: "Class which contains the information relative to an html page." legal: "See notice at end of class." status: "See notice at end of class." date: "$Date$" revision: "$Revision$" class HTML_PAGE inherit ANY redefine out end create make, make_from_template, make_from_templates feature -- Initialization make -- Create an HTML page. do image := "%N" end make_from_template (a_fi_n: STRING) -- Create an HTML page from a template whose path name is -- 'fi'. The template may contains special symbols/words, which -- will allow smart replacing (see feature 'replace'). require path_not_void: a_fi_n /= Void do create image.make (10) image.append ("") fill_with_template (image, a_fi_n) image.append ("") end feature {NONE} -- Initialization make_from_templates (a_templates: ARRAY [STRING]) require a_templates_not_void: a_templates /= Void local i, nb: INTEGER do create image.make (10) image.append ("") from i := a_templates.lower nb := a_templates.upper until i > nb loop fill_with_template (image, a_templates.item (i)) i := i + 1 end image.append ("") end fill_with_template (a_buffer, a_fi_n: STRING) -- Put content of file `a_fi_n' into `a_buffer'. require a_buffer_not_void: a_buffer /= Void a_fi_n_not_void: a_fi_n /= Void local fi: PLAIN_TEXT_FILE retried: BOOLEAN do if not retried then create fi.make_open_read (a_fi_n) fi.read_stream (fi.count) a_buffer.append_string (fi.last_string) fi.close else image := "
Could not read file " + a_fi_n + ".
%N" end ensure image_exists: image /= Void rescue retried := True retry end feature -- Basic Operations replace_marker (a_marker, s: STRING) -- Replace marker 'a_marker' by string 's' -- within the template. -- Do nothing if it does not exist. require not_void: a_marker /= Void and s /= Void do image.replace_substring_all (a_marker,s) end add_html_code (s: STRING) -- Add html code 's'. require code_exists: s/=Void local i: INTEGER s1: STRING do i := image.substring_index ("