-
Notifications
You must be signed in to change notification settings - Fork 0
/
pages.lisp
163 lines (152 loc) · 7.33 KB
/
pages.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: LW-DOC; Base: 10 -*-
;;; $Header: /usr/local/cvsrep/lw-doc/pages.lisp,v 1.11 2012-05-04 20:56:45 edi Exp $
;;; Copyright (c) 2005-2012, Dr. Edmund Weitz. All rights reserved.
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; * Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; * Redistributions in binary form must reproduce the above
;;; copyright notice, this list of conditions and the following
;;; disclaimer in the documentation and/or other materials
;;; provided with the distribution.
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(in-package :lw-doc)
(defun make-link (shortcut link)
"Creates a HTML link for the saved link LINK and the shortcut
SHORTCUT. Depends on the value of *LINK-PREFIX*."
(format nil "~A~A~A"
(case *link-prefix*
((nil) "../")
((t) *lw-link-prefix*)
(otherwise *link-prefix*))
(regex-replace-all "\\\\"
(directory-namestring (second (assoc shortcut *index-pages* :test #'string=)))
"/")
link))
(defun create-char-list ()
"Creates a list of links for the characters which appear in the
permuted index."
(with-html-output (*html-stream*)
(:p
(dotimes (i 26)
(let ((char (code-char (+ #.(char-code #\a) i))))
(when (gethash char *sorted-table*)
(htm
(:a :href (file-namestring (make-file-name char))
(str (string-upcase char)))
" "))))
(when (gethash #\* *sorted-table*)
(htm
(:a :href (file-namestring (make-file-name #\*))
"Non-Alphabetic"))))))
(defun create-table (char)
"Creates the HTML table with the permuted index for the
character CHAR."
(with-html-output (*html-stream*)
(loop for (symbol index type link-info) in (gethash char *sorted-table*)
for left = (escape-and-fill-spaces symbol 0 index)
for right = (escape-and-fill-spaces symbol index) do
(labels ((write-part (string)
(ecase type
(bold
(htm (:b (str string))))
(code
(htm (:code (str string))))))
(write-link (string)
(cond ((null (cdr link-info))
(destructuring-bind (shortcut page-number link)
(first link-info)
(htm
(:a :href (make-link shortcut link)
:title (format nil "~A-~A" shortcut page-number)
(write-part string)))))
(t (write-part string)))))
(htm
(:tr
(:td :align "right"
(write-link left))
(:td :align "left"
(write-link right)
(when (cdr link-info)
(htm " ["
(loop for (shortcut page-number link) in (sort (copy-list link-info)
(lambda (link-entry-1 link-entry-2)
(or (string< (first link-entry-1)
(first link-entry-2))
(and (string= (first link-entry-1)
(first link-entry-2))
(< (second link-entry-1)
(second link-entry-2))))))
for spaces = "" then " " do
(htm
(str spaces)
(:a :href (make-link shortcut link)
(:em (fmt "~A-~A" shortcut page-number)))))
"]")))))))))
(defun create-page (&optional char)
"Creates the index page for the character CHAR or the start
page if CHAR is NIL."
(with-open-file (*html-stream* (make-file-name char)
:direction :output
:if-exists :supersede)
(with-html-output (*html-stream*)
(flet ((make-title ()
(htm
(fmt "Permuted Index for ~A ~A Docs~@[ - ~A~]"
(lisp-implementation-type)
(lisp-implementation-version)
(case char
((nil) nil)
(#\* "Non-Alphabetic")
(otherwise (char-upcase char)))))))
(htm
(:html
(:head
(:title (make-title))
(:meta :name "author" :content "Dr. Edmund Weitz, Hamburg, Germany")
(:meta :name "copyright" :content "Dr. Edmund Weitz, Hamburg, Germany")
(:style :type "text/css"
"* { font-size: 10pt; font-weight: bold; font-family: Verdana, Arial, Helvetica, Geneva, sans-serif; }
code { font-family: Courier; }
em { font-size: 8pt; font-weight: medium; }
h2 { font-size: 12pt; } "))
(:body
(:h2 (make-title))
(create-char-list)
(when char
(htm
(:p
(:table :border 0 :cellspacing 0 :cellpadding 0
(create-table char)))
(create-char-list))))))))))
(defun create-permuted-index (&key ((:link-prefix *link-prefix*) nil)
((:target-dir *target-dir*) *docs-base-path*))
"Creates a directory called `permuted-index' which contains a
file `index.html' and several other files linked from there which
together comprise a permuted index for \(parts of) the LispWorks
documentation. By default the directory is created in the same
directory where the LW browsable documentation can be found but
this can be changed by providing the TARGET-DIR keyword
parameter. By default the links are created relative to the
afore-mentioned default directory but you can provide an
arbitrary prefix string through the keyword parameter
LINK-PREFIX. If this parameter is T the index entries are linked
to the documentation found at the LispWorks website."
(parse-files)
(clrhash *sorted-table*)
(fill-sorted-table)
(sort-sorted-table-rows)
(loop for char being the hash-keys of *sorted-table* do
(create-page char))
(create-page))