| 
									
										
										
										
											2012-09-22 15:31:21 -04:00
										 |  |  | ! 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
 | 
					
						
							| 
									
										
										
										
											2016-11-26 03:40:54 -05:00
										 |  |  |     [ rest [ string? ] filter ] gather ;
 | 
					
						
							| 
									
										
										
										
											2012-09-22 15:31:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : 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 -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     [ pdf>string ] dip home prepend-path utf8 set-file-contents ;
 | 
					
						
							| 
									
										
										
										
											2012-09-22 15:31:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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 ( -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     "cookbook" "cookbook.pdf" article-pdf ;
 | 
					
						
							| 
									
										
										
										
											2012-09-22 15:31:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : first-program-pdf ( -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     "first-program" "first-program.pdf" article-pdf ;
 | 
					
						
							| 
									
										
										
										
											2012-09-22 15:31:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : handbook-pdf ( -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     "handbook-language-reference" "handbook.pdf" article-pdf ;
 | 
					
						
							| 
									
										
										
										
											2012-09-22 15:31:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : system-pdf ( -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     "handbook-system-reference" "system.pdf" article-pdf ;
 | 
					
						
							| 
									
										
										
										
											2012-09-22 15:31:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : tools-pdf ( -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     "handbook-tools-reference" "tools" article-pdf ;
 | 
					
						
							| 
									
										
										
										
											2012-09-22 15:31:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : index-pdf ( -- )
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         "vocab-index" | 
					
						
							|  |  |  |         "article-index" | 
					
						
							|  |  |  |         "primitive-index" | 
					
						
							|  |  |  |         "error-index" | 
					
						
							|  |  |  |         "class-index" | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     } topics>pdf "index.pdf" write-pdf ;
 | 
					
						
							| 
									
										
										
										
											2012-12-16 20:10:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : furnace-pdf ( -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     "furnace" "furnace.pdf" article-pdf ;
 | 
					
						
							| 
									
										
										
										
											2012-12-16 20:10:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : alien-pdf ( -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     "alien" "alien.pdf" article-pdf ;
 | 
					
						
							| 
									
										
										
										
											2012-12-16 20:10:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : io-pdf ( -- )
 | 
					
						
							| 
									
										
										
										
											2018-03-15 09:43:13 -04:00
										 |  |  |     "io" "io.pdf" article-pdf ;
 |