<commit_before>;;;; drawer.lisp
;;;;
;;;; This file is part of the restas-colorize library, released under Lisp-LGPL.
;;;; See file COPYING for details.
;;;;
;;;; Author: <NAME> <<EMAIL>>

(in-package #:restas.colorize)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; generic interface
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defgeneric finalize-page (drawer data)
  (:documentation "Finalize page"))

(defgeneric render-route-data (drawer data route )
  (:documentation "Render page for specific route"))

(defgeneric colorize (drawer code lang)
  (:documentation "Make highlight html from code")
  (:method (drawer code lang)
    (colorize::html-colorization lang code)))

(defgeneric colorize-langs (drawer)
  (:documentation "List of supported languages")
  (:method (drawer)
    (iter (for (id . title) in (colorize:coloring-types))
          (collect (list :id (symbol-name id)
                         :title title)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; default implementation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defclass drawer () ())

(defmethod finalize-page ((drawer drawer) data)
  (restas.colorize.view:finalize-page data))


(defmethod restas:render-object ((drawer drawer) (data list))
  (let ((content (render-route-data drawer
                                    data
                                    (restas:route-symbol restas:*route*)))
        (menu (restas.colorize.view:main-menu
               (list :href-all  (restas:genurl 'list-notes)
                     :href-create (restas:genurl 'create-note)))))
    (finalize-page drawer
                   (list :content content
                         :menu menu
                         :title (getf data :title)))))


(defmethod render-route-data ((drawer drawer) (data list) route)
  (funcall (find-symbol (symbol-name route)
                        '#:restas.colorize.view)
           data))

(defmethod render-route-data ((drawer drawer) (data list) (route (eql 'view-note)))
  (call-next-method drawer
                    (list* :code (colorize drawer
                                           (getf data :code)
                                           (getf data :lang))
                           data)
                    route))

(defmethod render-route-data ((drawer drawer) (data list) (route (eql 'create-note)))
  (call-next-method drawer
                    (list* :langs (colorize-langs drawer)
                           data)
                    route))

(defmethod render-route-data ((drawer drawer) (data list) (route (eql 'preview-note)))
  (call-next-method drawer
                    (list* :langs (colorize-langs drawer)
                           :preview (colorize drawer
                                              (getf data :code)
                                              (getf data :lang))
                           data)
                    route))

(setf *default-render-method* (make-instance 'drawer))
<commit_msg>fix bug<commit_after>;;;; drawer.lisp
;;;;
;;;; This file is part of the restas-colorize library, released under Lisp-LGPL.
;;;; See file COPYING for details.
;;;;
;;;; Author: <NAME> <<EMAIL>>

(in-package #:restas.colorize)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; generic interface
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defgeneric finalize-page (drawer data)
  (:documentation "Finalize page"))

(defgeneric render-route-data (drawer data route )
  (:documentation "Render page for specific route"))

(defgeneric colorize (drawer code lang)
  (:documentation "Make highlight html from code")
  (:method (drawer code lang)
    (colorize::html-colorization (intern lang :keyword) code)))

(defgeneric colorize-langs (drawer)
  (:documentation "List of supported languages")
  (:method (drawer)
    (iter (for (id . title) in (colorize:coloring-types))
          (collect (list :id (symbol-name id)
                         :title title)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; default implementation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defclass drawer () ())

(defmethod finalize-page ((drawer drawer) data)
  (restas.colorize.view:finalize-page data))


(defmethod restas:render-object ((drawer drawer) (data list))
  (let ((content (render-route-data drawer
                                    data
                                    (restas:route-symbol restas:*route*)))
        (menu (restas.colorize.view:main-menu
               (list :href-all  (restas:genurl 'list-notes)
                     :href-create (restas:genurl 'create-note)))))
    (finalize-page drawer
                   (list :content content
                         :menu menu
                         :title (getf data :title)))))


(defmethod render-route-data ((drawer drawer) (data list) route)
  (funcall (find-symbol (symbol-name route)
                        '#:restas.colorize.view)
           data))

(defmethod render-route-data ((drawer drawer) (data list) (route (eql 'view-note)))
  (call-next-method drawer
                    (list* :code (colorize drawer
                                           (getf data :code)
                                           (getf data :lang))
                           data)
                    route))

(defmethod render-route-data ((drawer drawer) (data list) (route (eql 'create-note)))
  (call-next-method drawer
                    (list* :langs (colorize-langs drawer)
                           data)
                    route))

(defmethod render-route-data ((drawer drawer) (data list) (route (eql 'preview-note)))
  (call-next-method drawer
                    (list* :langs (colorize-langs drawer)
                           :preview (colorize drawer
                                              (getf data :code)
                                              (getf data :lang))
                           data)
                    route))

(setf *default-render-method* (make-instance 'drawer))

{'fraction_non_alphanumeric': 0.2310215557638238, 'fraction_numerical': 0.0, 'mean_word_length': 2.2015, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3462927', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1682, 'n_words': 425}