]> gitweb.factorcode.org Git - factor.git/commitdiff
help.pdf: generate PDF files from help articles.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 22 Sep 2012 19:31:21 +0000 (12:31 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 22 Sep 2012 19:31:21 +0000 (12:31 -0700)
extra/help/pdf/authors.txt [new file with mode: 0644]
extra/help/pdf/pdf.factor [new file with mode: 0644]

diff --git a/extra/help/pdf/authors.txt b/extra/help/pdf/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/help/pdf/pdf.factor b/extra/help/pdf/pdf.factor
new file mode 100644 (file)
index 0000000..d517213
--- /dev/null
@@ -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
+
+<PRIVATE
+
+: next-articles ( str -- seq )
+    lookup-article content>> [ 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 <pb> 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
+        [ <pb> 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 ;