<commit_before>(in-package #:tinaa)

(defun document-system (system-kind system-name destination &rest args
                                    &key (show-parts-without-documentation? t)
                                    (write-files? t) (page-writer-class nil))
  "Create TINAA documentation for a system. System-kind should be 'package or 
some other value for which it makes sense (e.g., an 'asdf-system if ASDFis
loaded...). System-name is the identifier of the 
system. Destination is the location in the file system where you want the 
documentation to go. Finally, you can pass in other arguments that are specific
to the kind of system you are documenting.

Note that system-kind will be coerced into a symbol interned in the Tinaa 
package because this makes Tinaa easier to use. If you happen to write your 
own system-kind, it will need to be a class defined in the Tinaa package."
  (when write-files?
    (assert (directory-name-p destination)))
  (remf args :show-parts-without-documentation?)
  (remf args :write-files?)
  ;;
  ;; remove argument if it's null (so that we get the default)
  (unless page-writer-class (remf args :page-writer-class))
  (setf system-kind (intern (string system-kind) :tinaa))
  (let ((*root-part* (apply #'make-part nil system-kind system-name 
                            :document? t 
                            :name-holder :self 
                            args))
        (*packages-to-document* nil)
        (*output-calls* (make-container 'associative-container)))
    (grovel-part *root-part*)
    (map-parts-from-leaves 
     *root-part*
     (lambda (sub-part)
       (setf (url sub-part) (url-for-part sub-part))))
    (format t "~%Writing files")
    (when write-files?
      (build-documentation (page-writer *root-part*) *root-part* destination)) 
    (when show-parts-without-documentation?
      (format t "~%The following parts appear to have no documentation:")
      (iterate-elements
       (parts-with-no-documentation *root-part*)
       (lambda (part)
         (format t "~%  ~A" (part-name part)))))
    *root-part*))

(defun write-css-file (writer destination &rest args &key (if-exists :supersede)
                                   &allow-other-keys)
  (let* ((css-file (css-file-for-writer writer))
	 (output (merge-pathnames 
		  "tinaa.css"
		  (namestring (translate-logical-pathname destination)))))
    (apply #'copy-file 
	   css-file
           output
           :if-exists if-exists args)))

(defmethod css-file-for-writer ((writer basic-page-writer))
  (or
   (css-file writer)
   (setf (css-file writer)
	 (or 
	  *css-file*
	  (pathname-for-system-file 'tinaa "tinaa.css")
	  (error "can't find CSS file")))))

(defmethod build-documentation :around
           ((writer basic-page-writer) (part doclisp-assembly)
            root &key (erase-first? nil))
  (let ((*document-root* (namestring (translate-logical-pathname root)))
        (*root-part* part))
    (when erase-first?
      (delete-directory *document-root*
                        :if-does-not-exist :ignore))
    (ensure-directories-exist *document-root*)
    (call-next-method)))

(defmethod build-documentation ((writer basic-page-writer) (part doclisp-assembly)
                                root &key &allow-other-keys)
  (set-flags part nil)
  (map-parts-from-leaves <commit_msg>make sure *print-readably* is bound to nil<commit_after>(in-package #:tinaa)

(defun document-system (system-kind system-name destination &rest args
                                    &key (show-parts-without-documentation? t)
                                    (write-files? t) (page-writer-class nil))
  "Create TINAA documentation for a system. System-kind should be 'package or 
some other value for which it makes sense (e.g., an 'asdf-system if ASDFis
loaded...). System-name is the identifier of the 
system. Destination is the location in the file system where you want the 
documentation to go. Finally, you can pass in other arguments that are specific
to the kind of system you are documenting.

Note that system-kind will be coerced into a symbol interned in the Tinaa 
package because this makes Tinaa easier to use. If you happen to write your 
own system-kind, it will need to be a class defined in the Tinaa package."
  (when write-files?
    (assert (directory-name-p destination)))
  (remf args :show-parts-without-documentation?)
  (remf args :write-files?)
  ;;
  ;; remove argument if it's null (so that we get the default)
  (unless page-writer-class (remf args :page-writer-class))
  (setf system-kind (intern (string system-kind) :tinaa))
  (let ((*root-part* (apply #'make-part nil system-kind system-name 
                            :document? t 
                            :name-holder :self 
                            args))
        (*packages-to-document* nil)
        (*output-calls* (make-container 'associative-container)))
    (grovel-part *root-part*)
    (map-parts-from-leaves 
     *root-part*
     (lambda (sub-part)
       (setf (url sub-part) (url-for-part sub-part))))
    (when write-files?
      (format t "~%Writing files")
      (build-documentation (page-writer *root-part*) *root-part* destination)) 
    (when show-parts-without-documentation?
      (format t "~%The following parts appear to have no documentation:")
      (iterate-elements
       (parts-with-no-documentation *root-part*)
       (lambda (part)
         (format t "~%  ~A" (part-name part)))))
    *root-part*))

(defun write-css-file (writer destination &rest args &key (if-exists :supersede)
                                   &allow-other-keys)
  (let* ((css-file (css-file-for-writer writer))
	 (output (merge-pathnames 
		  "tinaa.css"
		  (namestring (translate-logical-pathname destination)))))
    (apply #'copy-file 
	   css-file
           output
           :if-exists if-exists args)))

(defmethod css-file-for-writer ((writer basic-page-writer))
  (or
   (css-file writer)
   (setf (css-file writer)
	 (or 
	  *css-file*
	  (pathname-for-system-file 'tinaa "tinaa.css")
	  (error "can't find CSS file")))))

(defmethod build-documentation :around
           ((writer basic-page-writer) (part doclisp-assembly)
            root &key (erase-first? nil))
  (let ((*document-root* (namestring (translate-logical-pathname root)))
        (*root-part* part)
	(*print-readably* nil))
    (when erase-first?
      (delete-directory *document-root*
                        :if-does-not-exist :ignore))
    (ensure-directories-exist *document-root*)
    (call-next-method)))

(defmethod build-documentation ((writer basic-page-writer) (part doclisp-assembly)
                                root &key &allow-other-keys)
  (set-flags part nil)
  (map-parts-from-leaves 
{'fraction_non_alphanumeric': 0.12304948729380294, 'fraction_numerical': 0.0, 'mean_word_length': 2.5346638655462184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1745842', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1994, 'n_words': 616}