TITLE HTML report SUMMARY This is a module to help make a "report" that is directed to an html table. It provides services to "open" and "close" the report, and to emit heading and detail lines. The result will be a single html file for viewing on a screen. For a paper copy of the "report," one would print the html page. The module does not provide any page breaks that would make the printed version of this page look good. Controlling printing to physical paper is not part of the mission of html. DOCUMENTATION Load the module into your program with: do %htmlrep.r Before the first call: 1. Put a file name in HTMLREP-FILE-ID. This should be a value with the type of "file." In other words, put a percent sign in front of it. 2. Put a value in HTMLREP-TITLE. 3. Put a program in HTMLREP-PROGRAM-NAME. This will appear in a footer. 4. call HTMLREP-OPEN. Optionally, before "printing" the first detail line, call HTMLREP-EMIT-HEAD in the following manner: HTMLREP-EMIT-HEAD ["literal-1" ... "literal-n"] where literal-1, etc., are strings to be turned into entries. To "print" a line of data, call HTMREP-EMIT-LINE in the following manner: HTMLREP-EMIT-LINE reduce [word-1...word-n] where word-n is the word whose value you want to print. The procedure will generate a entry for each word, in one row of an html table. Historical note: In the first version of this module, we just passed the words in a block and did not reduce the block, and the HTMLREP-EMIT-LINE procedure used the "get" function to get the values of the words. This turned out not to work if the words passed in were in an object, so we moved the "reduction" process up to the level of the caller. Now we pass values to HTMLREP-EMIT-LINE instead of words. At the end: Call HTMLREP-CLOSE. You MUST do this step because all the other procedures just build up an html string in memory. The HTMLREP-CLOSE procedure actually writes the data to disk under the name you loaded into HTMLREP-FILE-ID. SCRIPT REBOL [ Title: "HTML report" ] ;; [---------------------------------------------------------------------------] ;; [ Items set up by the caller. ] ;; [---------------------------------------------------------------------------] HTMLREP-FILE-ID: %htmlrep.html HTMLREP-TITLE: " " HTMLREP-PRE-STRING: " " HTMLREP-POST-STRING: " " HTMLREP-PROGRAM-NAME: " " HTMLREP-CODE-BLOCK: " " ;; [---------------------------------------------------------------------------] ;; [ Internal working items. ] ;; [---------------------------------------------------------------------------] HTMLREP-FILE-OPEN: false ;; [---------------------------------------------------------------------------] ;; [ This is the top of the html page. ] ;; [---------------------------------------------------------------------------] HTMLREP-PAGE-HEAD: { <%HTMLREP-TITLE%>
Company logo

REBOL Reporting Services


Created on: <% now %>


<%HTMLREP-TITLE%>

<% HTMLREP-PRE-STRING %>

} ;; [---------------------------------------------------------------------------] ;; [ This is the end of the html page. ] ;; [---------------------------------------------------------------------------] HTMLREP-PAGE-FOOT: {

<% HTMLREP-POST-STRING %>


The above report was produced by the Information Systems Division. Refer to a program called "<% HTMLREP-PROGRAM-NAME %>."


<% HTMLREP-CODE-BLOCK %>
} ;; [---------------------------------------------------------------------------] ;; [ This is the area where we will build up the html page in memory. ] ;; [---------------------------------------------------------------------------] HTMLREP-PAGE: make string! 5000 ;; [---------------------------------------------------------------------------] ;; [ This is the procedure to "open" the report. ] ;; [ The "build-markup" function will replace the placeholders in the html ] ;; [ with the values resulting from their evaluation. ] ;; [---------------------------------------------------------------------------] HTMLREP-OPEN: does [ HTMLREP-PAGE: copy "" append HTMLREP-PAGE build-markup HTMLREP-PAGE-HEAD append HTMLREP-PAGE newline HTMLREP-FILE-OPEN: true ] ;; [---------------------------------------------------------------------------] ;; [ This is the procedure to "close" the report. ] ;; [ It writes to disk the html page we have built up in memeory. ] ;; [---------------------------------------------------------------------------] HTMLREP-CLOSE: does [ append HTMLREP-PAGE build-markup HTMLREP-PAGE-FOOT append HTMLREP-PAGE newline write HTMLREP-FILE-ID HTMLREP-PAGE HTMLREP-FILE-OPEN: false ] ;; [---------------------------------------------------------------------------] ;; [ This procedure emits a row of an html table containing heading ] ;; [ elements supplied by the caller in a block of strings. ] ;; [---------------------------------------------------------------------------] HTMLREP-EMIT-HEAD: func [ "Emit a heading row with literals supplied in a block" HTMLREP-HEADING-BLOCK [block!] ] [ append HTMLREP-PAGE "" foreach HTMLREP-HEAD-LIT HTMLREP-HEADING-BLOCK [ append HTMLREP-PAGE "" append HTMLREP-PAGE to-string HTMLREP-HEAD-LIT ; to-string just in case append HTMLREP-PAGE "" ; caller supplied words ] append HTMLREP-PAGE "" append HTMLREP-PAGE newline ] ;; [---------------------------------------------------------------------------] ;; [ This procedure emits a row of an html table containing the values of ] ;; [ words supplied by the caller in a block. ] ;; [ Note the requirement that the caller "reduce" the block passed to this ] ;; [ function so that we are getting values and not words. ] ;; [---------------------------------------------------------------------------] HTMLREP-EMIT-LINE: func [ "Emit a detail row with values supplied in a block" HTMLREP-DETAIL-BLOCK [block!] ] [ append HTMLREP-PAGE "" foreach HTMLREP-VALUE HTMLREP-DETAIL-BLOCK [ append HTMLREP-PAGE "" append HTMLREP-PAGE HTMLREP-VALUE append HTMLREP-PAGE "" ] append HTMLREP-PAGE "" append HTMLREP-PAGE newline ]