assembly.lisp 15.7 KB
Newer Older
Dave Cooper's avatar
Dave Cooper committed
1
;;
2
;; Copyright 2002-2011 Genworks International 
Dave Cooper's avatar
Dave Cooper committed
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
;;
;; This source file is part of the General-purpose Declarative
;; Language project (GDL).
;;
;; This source file contains free software: you can redistribute it
;; and/or modify it under the terms of the GNU Affero General Public
;; License as published by the Free Software Foundation, either
;; version 3 of the License, or (at your option) any later version.
;; 
;; This source file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; Affero General Public License for more details.
;; 
;; You should have received a copy of the GNU Affero General Public
;; License along with this source file.  If not, see
;; <http://www.gnu.org/licenses/>.
;;

(in-package :yadd)


(define-object assembly (base-yadd-sheet)

  :documentation
  (:author "Dave Cooper (Genworks)"
   :description "``Yet Another Definition Documenter.'' Generates 
documentation for all the relevant packages in the current Lisp session. Presents a 
standard :write-html-sheet method which can also be crawled with a call to 
<pre>

     (gwl:crawl \"yadd:assembly\")

</pre>

The packages to be documented, and whether the green/red supported 
messages flags show up, can be controlled with optional-inputs.")

  :input-slots
  (("List of keyword symbols. These packages will be ignored. 
This list defaults to standard internal and test packages"
    packages-to-ignore (list :gwl-user :yadd-test :genworks :yadd-sample 
			     :gdl :gwl :yadd :gwl-tree :surf :geom-base))
   
   ("Boolean. This defaults to nil, if it is set to t, only exported symbols will be
            considered for documentation."
    external-only? nil))

  :computed-slots
  ((packages-to-document 
    (sort
     (remove-duplicates
      (set-difference
       (let (list (autoloads (glisp:autoloaded-packages)))
         (do-symbols (sym :keyword list)
           (when (and (not (member sym autoloads)) 
                      (find-package sym)
                      (or (eql sym :gdl) 
                          (member (find-package :gdl) 
                                  (package-use-list 
                                   (find-package sym)))))
             (push sym list))))
       (the :packages-to-ignore))
      :key #'find-package)
     #'string-lessp))


   (relevant-doks (remove-if-not
                   #'(lambda (dok)
                       (or (the-object dok :object-docs :doks)
                           (the-object dok :function-docs :doks)
                           (the-object dok :variable-docs :doks)))
                   (list-elements (the :package-dokumentations))))
   (symbols-for-index (sort
                       (apply #'append (mapcar #'(lambda (package) (the-object package :symbols-for-index))
                                               (the :relevant-doks)))
                       #'string-lessp
                       :key #'second))
   
   (%index-ht (let ((ht (make-hash-table :size (length (the :symbols-for-index)))))
               (dolist (pair (the symbols-for-index) ht)
84 85 86 87
                 (let ((symbol (glisp:intern  (second pair)
					      (if (typep (first pair) 'object-dokumentation-category-message)
						  :keyword
						  (the-object (first pair) package)))))
Dave Cooper's avatar
Dave Cooper committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
                   (pushnew (first pair) (gethash symbol ht))))))

   (index-array (let ((array (make-array (list (hash-table-count (the %index-ht)))))
                      (count -1))
                  (maphash #'(lambda(key val)
                               (setf (aref array (incf count))
                                     (list key val)))
                           (the %index-ht))
                  array))

   (index-ht (let ((ht (make-hash-table :size (the master-index-grouped number-of-elements))))
               (dolist (item (list-elements (the master-index-grouped)) ht)
                 (setf (gethash (the-object item key) ht) item))))
                               
   
   (package-ht (let ((ht (make-hash-table :size (the package-dokumentations number-of-elements))))
                 (dolist (package (list-elements (the package-dokumentations)) ht)
                   (setf (gethash (the-object package package) ht) package))))
   
   (title "GDL Reference Documentation")
   
109 110 111 112
   
   (dom-chapter `((:chapter :title "Gendl Reference")
		  ,@(mapcar #'(lambda(package)
				`((:section :title ,(the-object package strings-for-display-verbose))
113
				  (:p ,@(remove nil (the-object package dom-section)))))
114
			    (list-elements (the package-dokumentations))))))
Dave Cooper's avatar
Dave Cooper committed
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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314


  :trickle-down-slots
  (index-ht)

  :objects
  ((master-index-grouped :type 'index-item
                         :hidden? t
                         :sequence (:size (length (the index-array)))
                         :key (first (aref (the index-array) (the-child index)))
                         :items (second (aref (the index-array) (the-child index))))


   ("package-dokumentation. Quantified, one for each :package-to-document"
    package-dokumentations :type 'package-dokumentation
    :sequence (:size (length (the packages-to-document)))
    :package (nth (the-child :index) (the :packages-to-document))
    :pass-down (:external-only?)
    :show-supported-flag nil)

   
   ("index. Master index of all symbols (objects, functions, parameters, variables, constants)"
    master-index :type 'master-index
    :hidden? t
    :pass-down (:symbols-for-index)))

  :functions
  ((find-object-doc
    (symbol)
    (let* ((package (make-keyword (package-name (symbol-package symbol))))
           (package-doc (when package (gethash package (the package-ht)))))
      (when package-doc (gethash symbol (the-object package-doc object-docs symbol-ht)))))
    

   
   
   (main-sheet-body 
    ()
    (with-cl-who ()
      (when *developing?* (html (:p (the (write-development-links)))))
      (:p
       (:center (:h2 "Reference Documentation")
                (:i "for Genworks" (:sup (:small "&reg;"))
                    " General-purpose Declarative Language, Related Packages, and User packages")))
      (:p
                       
       (:h3 "Documented Packages:")
                       
       (:ul
        (dolist (package (the :relevant-doks))
          (html (:li (the-object package 
                                 (:write-self-link 
                                  :display-string 
                                  (the-object package
                                              strings-for-display-verbose))))))))
      (:p
       (:h3
        (the :master-index
          (:write-self-link :display-string "Master Index"))))
      (:p (str (the :footer)))))))


(define-object master-index (base-yadd-sheet)

  :documentation
  (:author "Dave Cooper (Genworks)"
   :description "Prints bullet list of symbols as links to their documentation pages.")

  :input-slots
  ("List of lists. Each list contains the page object for the symbol's 
   documentation and the symbol's print-name. The list should be sorted 
   based on the symbols' print-names."
   symbols-for-index)

  :computed-slots
  ((use-jquery? t)
   
   
   
   (additional-header-js-content 
    (with-cl-who-string ()
      (str (the additional-header-js))
      ((:script :type "text/javascript")
       "$(document).ready(function () {$('ul li').quicksearch({ attached: 'ul:first',position: 'before', 
labelText: 'Search GDL Documentation:',inputText: 'Enter term...',
loaderImg: '/static/gwl/tasty-unpix/loader.gif',loaderText: 'Narrowing Down...'});});")))
   
   
   (main-sheet-body 
    (with-cl-who-string ()
      (when *developing?* (htm (:p (the (write-development-links)))))
      (:p (:center (:h2 "Index for Relevant GDL Symbols")))
      (:p (str (the (back-link :display-string "Documentation Home"))))
      (:p
       (:ul
        (dolist (symbol (the :symbols-for-index))
          (htm (:li
                (str (the-object (first symbol)
                                 (self-link :display-string
                                            (second symbol))))
                " ("
                (:i (str (the-object (first symbol) :dok-type)) ", "
                    (str
                     (string-downcase
                      (package-name (symbol-package (the-object
                                                     (first symbol)
                                                     :symbol)))))
                    ")"))))))
      (:p (str (the back-link)))
      
      (:p (str (the footer)))
      
      ))))

(define-object package-dokumentation (base-yadd-sheet)

  :documentation
  (:author "Dave Cooper"
   :description "Prepares documentation for all relevant symbols in a given Lisp package.")

  :input-slots
  (("String or keyword symbol. Names the package, or a nickname of the package, to be documented."
    package (the :package-form :package))
   ("boolean. Determines whether to show red/green flag on each message indicating whether it is a 
            supported message."
    show-supported-flag nil)
   ("Boolean. Determines whether to consider all symbols in the package or just the exported ones."
    external-only? (the :package-form :external-only?)))

  :computed-slots
  ((title (with-output-to-string (ss)
            (html-stream ss "The " (:i (:princ (the strings-for-display-verbose)))
                         " Package")))
   (package-key (make-keyword (the :package)))
   
   (strings-for-display (package-name (find-package (the package-key))))
   
   (strings-for-display-verbose 
    (let ((nicknames (package-nicknames (find-package
					 (the :package-key))))
	  (documentation (glisp:package-documentation 
			  (find-package (the package-key)))))
      (format nil "~a ~a~a~{~:(~a~)~^, ~}"
	      (package-name (find-package (the package-key)))
	      (if documentation (format nil "(~a)" documentation) "")
	      (if nicknames " Nicknames: " "")
	      nicknames)))

   (symbols-for-index 
    (append 
     (apply #'append
	    (mapcar #'(lambda(doc) 
			(the-object doc symbols-for-index))
		    (the object-docs doks)))
                       
     (mapcar #'(lambda (function)
		 (list
		  function
		  (string-downcase

		   (format
		    nil
		    "~a"
		    (the-object function :symbol)))))
	     (the :function-docs :doks))
     (mapcar #'(lambda (variable)
		 (list
		  variable
		  (string-downcase

		   (format
		    nil
		    "~a"
		    (the-object variable :symbol)))))
	     (the :variable-docs :doks)))))

  :objects
  (("object-doc. Container for set of all Object documentation sheets."
    object-docs :type 'object-doc
    :return-object self
    :show-supported-flag (the :show-supported-flag)
    :pass-down (:external-only?)
    :package (the :package-key))
   ("function-doc. Container for set of all Function documentation sheets."
    function-docs :type 'function-doc
    :return-object self
    :pass-down (:external-only?)
    :package (the :package-key))
   ("variable-doc. Container for set of all Parameter/Variable/Constant documentation sheets."
    variable-docs :type 'variable-doc
    :return-object self
    :pass-down (:external-only?)
    :package (the :package-key)))

  :hidden-objects
  (("package-form. Allows user to modify toplevel optional-inputs."
    package-form :type 'package-form))

  :functions
  (("Void. Prints to *html-stream* a bulleted list for each of the three categories of docs in the package."
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
    dom-section
    nil
    (mapcar #'(lambda(child)
		(the-object child dom-subsections))
	  (the children))

    #+nil
    (html (:html
	    (:head
	     (the default-header-content)
	     (:title "The " (:princ (the strings-for-display-verbose)) " Package"))
	    (:body
	     (when *developing?* (html (:p (the (write-development-links)))))
	     (:p (the (:write-back-link :display-string "Documentation Home")))
	     (:p
	      (:center (:h2 (:princ (the :title)))
		       (when (package-nicknames (the :package-key))
			 (html (:i
				(format *html-stream* "a.k.a. ~{~:(~a~)~^, ~}"
					(package-nicknames (the :package-key)))))))
	      (mapc #'(lambda (child)
			(the-object child (:write-documentation-links)))
		    (the :children)))
	     (:p (the (:write-back-link :display-string "Documentation Home")))
	     (:p (the :write-footer))))))



   ("Void. Prints to *html-stream* a bulleted list for each of the three categories of docs in the package."
Dave Cooper's avatar
Dave Cooper committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
    write-html-sheet
    nil
    (if (the :package)
        (html (:html
               (:head
                (the default-header-content)
                (:title "The " (:princ (the strings-for-display-verbose)) " Package"))
               (:body
                (when *developing?* (html (:p (the (write-development-links)))))
                (:p (the (:write-back-link :display-string "Documentation Home")))
                (:p
                 (:center (:h2 (:princ (the :title)))
                          (when (package-nicknames (the :package-key))
                            (html (:i
                                   (format *html-stream* "a.k.a. ~{~:(~a~)~^, ~}"
                                           (package-nicknames (the :package-key)))))))
                 (mapc #'(lambda (child)
                           (the-object child (:write-documentation-links)))
                       (the :children)))
                (:p (the (:write-back-link :display-string "Documentation Home")))
                (:p (the :write-footer)))))
      (the :package-form (:write-html-sheet))))))


(define-object package-form (base-yadd-sheet)

  :documentation
  (:author "Dave Cooper (Genworks)"
   :description "Presents a form to the user to be able to modify the Package, 
supported-flag, and external flag.")

  :computed-slots
  ((package (getf (the :query-plist) :package))
   (show-supported-flag (getf (the :query-plist) :show-supported-flag))
   (external-only? (getf (the :query-plist) :external-only))
   (respondant (the return-object)))

  :functions
  ((write-html-sheet
    nil
    (html (:html
           (:head
            (the default-header-content)
            (:title
             "Please Specify a Common Lisp Package to Product Documentation"))
           (:body (when *developing?* (html (:p (the (write-development-links)))))
                  (with-html-form ()
                    (:table
                     (:tr (:td (:b "Package Name"))
                          (:td
                           ((:input :type :string :name :package :size 40 :value
                                    (or (the :package) "")))))
                     (:tr (:td (:b "Flag Supported Messages?"))
                          (:td
                           ((:input :type :checkbox :name :show-supported-flag :checked
                                    :checked))))
                     (:tr (:td (:b "Suppress Unexported Symbols?"))
                          (:td ((:input :type :checkbox :name :external-only)))))
                   (:p ((:input :type :submit :value " OK " :name :submit)))
                   (:p (the :write-footer)))))))))




(define-object index-item (base-yadd-sheet)
  :input-slots
  (key items)
  
  
  :computed-slots
  ((additional-header-content
    (with-cl-who-string ()
      (the default-header-content)
      (:title (fmt "Matches for ~s" (the key)))))
   
   (main-sheet-body 
    (with-cl-who-string ()
      (when *developing?* (htm (:p (the (write-development-links)))))
      (:p
       (:center
        (:h2 (fmt "Matches for ~s" (the key)))))
      (:p
       (dolist (item (the items))
         (htm (:li
               (the-object item (:write-self-link :display-string 
 						  (the  key)))
                " ("
                (:i (str (the-object item :dok-type)) ", "
                    (str
                     (string-downcase
                      (package-name (symbol-package (the-object
                                                     item
                                                     :symbol)))))")")))))))))