From f9981382689e07e047fd5f69abd953dbe5f5b806 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sat, 22 Sep 2012 12:31:21 -0700 Subject: [PATCH] help.pdf: generate PDF files from help articles. --- extra/help/pdf/authors.txt | 1 + extra/help/pdf/pdf.factor | 65 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 extra/help/pdf/authors.txt create mode 100644 extra/help/pdf/pdf.factor diff --git a/extra/help/pdf/authors.txt b/extra/help/pdf/authors.txt new file mode 100644 index 0000000000..e091bb8164 --- /dev/null +++ b/extra/help/pdf/authors.txt @@ -0,0 +1 @@ +John Benediktsson diff --git a/extra/help/pdf/pdf.factor b/extra/help/pdf/pdf.factor new file mode 100644 index 0000000000..d517213ea0 --- /dev/null +++ b/extra/help/pdf/pdf.factor @@ -0,0 +1,65 @@ +! Copyright (C) 2010 John Benediktsson +! See http://factorcode.org/license.txt for BSD license + +USING: accessors arrays assocs help help.markup help.topics +io.encodings.utf8 io.files io.pathnames kernel pdf pdf.layout +pdf.streams sequences sets strings ; + +IN: help.pdf + +> [ array? ] filter + [ first \ $subsections eq? ] filter + [ rest [ string? ] filter ] map concat members ; + +: topic>pdf ( str -- pdf ) + [ + [ print-topic ] + [ + next-articles [ + [ article-title $heading ] + [ article-content print-content ] bi + ] each + ] bi + ] with-pdf-writer ; + +: topics>pdf ( seq -- pdf ) + [ topic>pdf ] map 1array join ; + +: write-pdf ( pdf name -- ) + [ pdf>string ] dip home prepend-path utf8 set-file-contents ; + +PRIVATE> + +: article-pdf ( str name -- ) + [ + [ [ print-topic ] with-pdf-writer ] + [ next-articles topics>pdf ] bi + [ 1array glue ] unless-empty + ] [ write-pdf ] bi* ; + +: cookbook-pdf ( -- ) + "cookbook" "cookbook.pdf" article-pdf ; + +: first-program-pdf ( -- ) + "first-program" "first-program.pdf" article-pdf ; + +: handbook-pdf ( -- ) + "handbook-language-reference" "handbook.pdf" article-pdf ; + +: system-pdf ( -- ) + "handbook-system-reference" "system.pdf" article-pdf ; + +: tools-pdf ( -- ) + "handbook-tools-reference" "tools" article-pdf ; + +: index-pdf ( -- ) + { + "vocab-index" + "article-index" + "primitive-index" + "error-index" + "class-index" + } topics>pdf "index.pdf" write-pdf ;