#!/usr/bin/env retro This tool is intended to be used to create an epub version of the standard documentation. An epub is just a .zip file containing a bunch of XHTML files and a few files containing metadata. Our structure will look like: Book Root Directory |-- META-INF directory | `-- container.xml |-- mimetype |-- content.opf |-- toc.ncx |-- stylesheet.css |-- cover.xhtml |-- toc.xhtml |-- chapterAA.xhtml |-- ... `-- chapterZZ.xhtml Begin by defining some helper functions for writing to a file. ~~~ 'FID var :file:s:put [ @FID file:write ] s:for-each ; :file:nl ASCII:CR @FID file:write ; :unix:mkdir 'mkdir_-p_%s s:format unix:system ; ~~~ Create the directories needed. ~~~ 'STEP:_Create_directories s:put nl 'epub unix:mkdir 'epub/META-INF unix:mkdir ~~~ Then create the `mimetype` file. This is supposed to be written without a trailing newline. ~~~ 'STEP:_Generate_`mimetype` s:put nl 'application/epub+zip 'epub/mimetype file:spew ~~~ Then create `META-INF/container.xml`. ~~~ 'STEP:_Generate_`container.xml` s:put nl 'epub/META-INF/container.xml file:open-for-writing !FID ' file:s:put file:nl ' file:s:put file:nl ' file:s:put file:nl ' file:s:put file:nl ' file:s:put file:nl ' file:s:put file:nl @FID file:close ~~~ Create `content.opf`. This will need to lest all of the files that are used in the book. Todo: - verify the required fields and metadata - write this to a file RETRO Forth : User Manual ...bookid... # Generate the Chapters ~~~ 'STEP:_Convert_chapters_to_XHTML s:put nl 'retro_tools/book-chapters-to-xhtml.retro unix:system ~~~ Assemble the pieces ~~~ 'STEP:_Relocate_files s:put nl 'epub unix:chdir '.. unix:chdir ~~~ zip -0Xq /tmp/book.epub mimetype zip -Xr9Dq /tmp/book.epub * Cleanup is the final step. Remove the temporary epub directory ~~~ 'STEP:_Cleanup s:put nl 'rm_-rf_epub unix:system ~~~