]> gitweb.factorcode.org Git - factor.git/blob - extra/help/pdf/pdf.factor
factor: trim more using lists.
[factor.git] / extra / help / pdf / pdf.factor
1 ! Copyright (C) 2010 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: accessors arrays help help.markup help.topics
5 io.encodings.utf8 io.files io.pathnames kernel namespaces
6 pdf.canvas pdf.layout pdf.streams sequences sets strings ;
7
8 IN: help.pdf
9
10 <PRIVATE
11
12 : next-articles ( str -- seq )
13     lookup-article content>> [ array? ] filter
14     [ first \ $subsections eq? ] filter
15     [ rest [ string? ] filter ] gather ;
16
17 : topic>pdf ( str -- pdf )
18     [
19         [ print-topic ]
20         [
21             next-articles [
22                 [ article-title $heading ]
23                 [ article-content print-content ] bi
24             ] each
25         ] bi
26     ] with-pdf-writer ;
27
28 : topics>pdf ( seq -- pdf )
29     [ topic>pdf ] map <pb> 1array join ;
30
31 : write-pdf ( pdf name -- )
32     [ pdf>string ] dip home prepend-path utf8 set-file-contents ;
33
34 PRIVATE>
35
36 : article-pdf ( str name -- )
37     1.25 +line-height+ [
38         [
39             [ [ print-topic ] with-pdf-writer ]
40             [ next-articles topics>pdf ] bi
41             [ <pb> 1array glue ] unless-empty
42         ] [ write-pdf ] bi*
43     ] with-variable ;
44
45 : cookbook-pdf ( -- )
46     "cookbook" "cookbook.pdf" article-pdf ;
47
48 : first-program-pdf ( -- )
49     "first-program" "first-program.pdf" article-pdf ;
50
51 : handbook-pdf ( -- )
52     "handbook-language-reference" "handbook.pdf" article-pdf ;
53
54 : system-pdf ( -- )
55     "handbook-system-reference" "system.pdf" article-pdf ;
56
57 : tools-pdf ( -- )
58     "handbook-tools-reference" "tools" article-pdf ;
59
60 : index-pdf ( -- )
61     {
62         "vocab-index"
63         "article-index"
64         "primitive-index"
65         "error-index"
66         "class-index"
67     } topics>pdf "index.pdf" write-pdf ;
68
69 : furnace-pdf ( -- )
70     "furnace" "furnace.pdf" article-pdf ;
71
72 : alien-pdf ( -- )
73     "alien" "alien.pdf" article-pdf ;
74
75 : io-pdf ( -- )
76     "io" "io.pdf" article-pdf ;