REBOL [ Title: "Make recipe web page" Purpose: {Assemble all recipes in the current folder into a single web page and send it to an ftp site.} ] ;; [---------------------------------------------------------------------------] ;; [ The program reads all the recipes in the current directory and makes ] ;; [ a single web page of all of them, and then sends it to a hard-coded ] ;; [ ftp site. Many ISP's give a customer a small amount of space for a ] ;; [ personal web site, and this program was designed around that premise. ] ;; [ The reason one would want one's recipes on a personal web site might ] ;; [ be to cover the situation where one is at the grocery store and decides ] ;; [ at the last minute to make a particular recipe for dinner, and can't ] ;; [ remember the ingredients. With the recipes on a web site, a person ] ;; [ could check the list on a smart phone. ] ;; [---------------------------------------------------------------------------] ;; [---------------------------------------------------------------------------] ;; [ Change the items below for your personal situation. ] ;; [---------------------------------------------------------------------------] WEBSITE-ADDR: "ftp.myisp.com" WEBSITE-USERID: "myemailid@myisp.com" WEBSITE-PASSWORD: "mypassword" OUTPUT-FILE-ID: %recipe-list.html ;; [---------------------------------------------------------------------------] ;; [ These are the data structures that seem to be required to send the ] ;; [ files we want to send. The tenth item in each block is the file ] ;; [ name on the server. ] ;; [---------------------------------------------------------------------------] TOPIC-ADDR: [ scheme: 'ftp host: WEBSITE-ADDR user: WEBSITE-USERID pass: WEBSITE-PASSWORD target: %. ] TOPIC-ADDR/10: OUTPUT-FILE-ID ;; -- Get a list of all text files in the current directory. TEXT-FILE?: func [ FILEID ] [ find [%.txt %.TXT] find/last FILEID "." ] FILE-LIST: read %. while [not tail? FILE-LIST] [ either TEXT-FILE? first FILE-LIST [ FILE-LIST: next FILE-LIST ] [ remove FILE-LIST ] ] FILE-LIST: head FILE-LIST ;; Don't forget to reposition to head. HTML-PAGE: "" HTML-INDEX: "" HTML-INDEX-LINE: { <% RECIPE-NAME %>
} HTML-HEAD: { Recipes

Family favorite recipes

} HTML-TBL-HEAD: { } HTML-TBL-INGREDIENTS: { } HTML-TBL-FOOT: {

<% RECIPE-NAME %>

<% WS-INGREDIENT-LIST %>
<% RECIPE-PROCEDURE %>
<% RECIPE-NOTES %>
} HTML-FOOT: { } RECIPE-NAME: "" RECIPE-SOURCE: "" RECIPE-INGREDIENTS: [] RECIPE-PROCEDURE: "" RECIPE-NOTES: "" CLEAR-RECIPE-DATA: does [ RECIPE-NAME: copy "" RECIPE-SOURCE: copy "" RECIPE-INGREDIENTS: copy [] RECIPE-PROCEDURE: copy "" RECIPE-NOTES: copy "" ] BUILD-INGREDIENT-LIST: does [ WS-INGREDIENT-LIST: copy "" foreach INGREDIENT-BLOCK RECIPE-INGREDIENTS [ foreach [INGREDIENT QUANTITY] INGREDIENT-BLOCK [ append WS-INGREDIENT-LIST rejoin [ INGREDIENT ", " QUANTITY newline ] ] ] ] GLB-BASE-FILENAME: func [ "Returns a file name without the extension" INPUT-STRING [series! file!] "File name" /local FILE-STRING REVERSED-NAME REVERSED-BASE BASE-FILENAME ] [ FILE-STRING: copy "" FILE-STRING: to-string INPUT-STRING REVERSED-NAME: reverse FILE-STRING REVERSED-BASE: copy "" REVERSED-BASE: next find REVERSED-NAME "." BASE-FILENAME: copy "" BASE-FILENAME: reverse REVERSED-BASE return BASE-FILENAME ] foreach FILE FILE-LIST [ CLEAR-RECIPE-DATA do load FILE BUILD-INGREDIENT-LIST HTML-LINK: GLB-BASE-FILENAME second split-path FILE append HTML-INDEX build-markup HTML-INDEX-LINE append HTML-PAGE build-markup HTML-TBL-HEAD append HTML-PAGE build-markup HTML-TBL-INGREDIENTS append HTML-PAGE build-markup HTML-TBL-FOOT ] write OUTPUT-FILE-ID rejoin [ HTML-HEAD HTML-INDEX HTML-PAGE HTML-FOOT ] write/binary TOPIC-ADDR read/binary OUTPUT-FILE-ID browse OUTPUT-FILE-ID