From 180b64c6ca95deafd2a34ca9d1919545246755cb Mon Sep 17 00:00:00 2001 From: David Botton Date: Mon, 22 Jul 2024 02:38:36 -0400 Subject: [PATCH] only remove clog data attributes --- clog.asd | 2 +- tools/clog-builder-panels.lisp | 20 ++----- tools/clog-builder-render.lisp | 59 ++++++++++++++++----- tools/clog-builder.lisp | 2 +- tools/panel-sys-browser.clog | 2 +- tools/panel-sys-browser.lisp | 95 +++++++++++++++++++++++++++------- tutorial/README.md | 9 ++++ 7 files changed, 138 insertions(+), 51 deletions(-) diff --git a/clog.asd b/clog.asd index 0ada6f3..bb8ae58 100644 --- a/clog.asd +++ b/clog.asd @@ -72,7 +72,7 @@ (asdf:defsystem #:clog/tools :depends-on (#:clog #:clog-ace #:clog-terminal #:s-base64 #:cl-indentify - #:definitions #:parenscript #:trivial-main-thread #:swank) + #:definitions #:parenscript #:trivial-main-thread #:plump #:swank) :pathname "tools/" :components (;; clog-db-admin app (:file "clog-db-admin") diff --git a/tools/clog-builder-panels.lisp b/tools/clog-builder-panels.lisp index fcfb17d..dd3d90d 100644 --- a/tools/clog-builder-panels.lisp +++ b/tools/clog-builder-panels.lisp @@ -46,7 +46,7 @@ if($(this).attr('data-clog-composite-control') == 't'){$(this).text('')}~ if($(this).attr('id') !== undefined && ~ $(this).attr('id').substring(0,5)=='CLOGB'){$(this).removeAttr('id')}});~ - html_beautify (z.html(),{'wrap_line_length':'80'})" + z.html();" (jquery content)))) (destroy data)) (maphash @@ -143,7 +143,7 @@ (let* ((control-record (control-info (value (select-tool app)))) (control-type-name (getf control-record :create-type))) (cond ((eq control-type-name :custom-query) - (input-dialog win "Enter html (must have an outer element):" + (input-dialog win "Enter html (must have one outer element):" (lambda (custom-query) (when custom-query (when (do-drop-new-control @@ -174,7 +174,7 @@ :title "Custom Control" :default-value (getf control-record :create-content))) ((eq control-type-name :custom-block) - (input-dialog win "Enter html to create control:" + (input-dialog win "Enter inner html of block:" (lambda (custom-query) (when custom-query (when (do-drop-new-control @@ -1014,19 +1014,7 @@ not a temporarily attached one when using select-control." (place-inside-bottom-of (bottom-panel box) (get-placer control))) (get-control-list app panel-id)) - (setf result (js-query content - (format nil - "var z=~a.clone();~ - z.find('*').each(function(){~ - var m=$(this).attr('data-clog-name'); - if($(this).attr('data-clog-composite-control') == 't'){$(this).text('')}~ - if($(this).attr('data-clog-composite-control') == 'b'){$(this).html($(this).attr('data-original-html'))}~ - for(n in $(this).get(0).dataset){delete $(this).get(0).dataset[n]}~ - if(m){$(this).attr('data-clog-name', m);}~ - });~ - html_beautify (z.html(),{'wrap_line_length': '80', - 'extra_liners': 'div,form,input,button,select,textarea,ol,ul,table,style,datalist'})" - (jquery content)))) + (setf result (pprint-as-html content)) (maphash (lambda (html-id control) (declare (ignore html-id)) diff --git a/tools/clog-builder-render.lisp b/tools/clog-builder-render.lisp index 5dac465..1d7946e 100644 --- a/tools/clog-builder-render.lisp +++ b/tools/clog-builder-render.lisp @@ -2,6 +2,50 @@ ;; Code rendering utlities +(defun pprint-as-html (content) + (js-query content (format nil "html_beautify ('~A',{'wrap_line_length':'80',~ + 'extra_liners':'div,form,input,button,select,textarea,ol,ul,table,style,datalist'})" + (escape-string (remove-clog-attributes (inner-html content)))))) + +(defun remove-clog-attributes (html) + (let ((root (plump:parse html))) + (html-remove-attributes root '("data-clog-type" + "data-original-html" + "data-clog-composite-control" + "data-clog-custom-create")) + (with-output-to-string (str) + (plump:serialize root str)))) + +(defun html-remove-attributes (root attrs) + (let ((v (plump:child-elements root))) + (dotimes (n (length v)) + (if (equalp (plump:tag-name (aref v n)) "data") + (plump:remove-child (aref v n)) + (progn + (when (plump:child-elements (aref v n)) + (let ((composite (plump:attribute (aref v n) "data-clog-composite-control"))) + (if composite + (progn + (if (equalp composite "b") + (let* ((new-html (plump:parse (plump:attribute (aref v n) "data-original-html"))) + (new-children (plump:child-elements new-html))) + (plump:clear (aref v n)) + (dotimes (cn (length new-children)) + (plump:append-child (aref v n) (aref new-children cn)))) + (plump:clear (aref v n)))) + (html-remove-attributes (aref v n) attrs)))) + (maphash (lambda (k v) + (declare (ignore v)) + (unless (ppcre:scan "^data-clog-name" k) + (when (ppcre:scan "^data-clog-" k) + (pushnew k attrs :test 'equalp))) + (when (ppcre:scan "^data-on-" k) + (pushnew k attrs :test 'equalp))) + (plump:attributes (aref v n))) + (mapcar (lambda (attr) + (plump:remove-attribute (aref v n) attr)) + attrs)))))) + (defun render-clog-code (content hide-loc) "Render panel to clog code and add to window" (let* ((app (connection-data-item content "builder-app-data")) @@ -100,19 +144,8 @@ cmembers cname ;;defun (ppcre:regex-replace-all "\"" - (js-query content - (format nil - "var z=~a.clone();~ - z.find('*').each(function(){~ - var m=$(this).attr('data-clog-name'); - if($(this).attr('data-clog-composite-control') == 't'){$(this).text('')}~ - if($(this).attr('data-clog-composite-control') == 'b'){$(this).html($(this).attr('data-original-html'))}~ - for(n in $(this).get(0).dataset){delete $(this).get(0).dataset[n]}~ - if(m){$(this).attr('data-clog-name', m);}~ - });~ - html_beautify (z.html(),{'wrap_line_length': '80'})" - (jquery content))) - "\\\"") + (pprint-as-html content) + "\\\"") cname vars (reverse creates) ; Insure that on-setup/on-create follow order in tree diff --git a/tools/clog-builder.lisp b/tools/clog-builder.lisp index e2d8685..36e9e0a 100644 --- a/tools/clog-builder.lisp +++ b/tools/clog-builder.lisp @@ -443,7 +443,7 @@ clog-builder window.") (on-new-builder-panel-ext obj) (on-new-builder-panel obj)))) (create-gui-menu-item file :content "New CLOG Panel Popup Editor" :on-click 'on-new-builder-page) - (create-gui-menu-item file :content "New HTML Panel Popup Editor" :on-click 'on-new-builder-basic-page) + (create-gui-menu-item file :content "New No-CSS Panel External Editor" :on-click 'on-new-builder-basic-page) (create-gui-menu-item file :content "New Custom Boot Panel External Editor" :on-click 'on-new-builder-custom-page) (create-gui-menu-item file :content "New CLOG Builder Window" :on-click (lambda (obj) diff --git a/tools/panel-sys-browser.clog b/tools/panel-sys-browser.clog index 49e601e..8910648 100644 --- a/tools/panel-sys-browser.clog +++ b/tools/panel-sys-browser.clog @@ -1 +1 @@ -
status
\ No newline at end of file +
status
\ No newline at end of file diff --git a/tools/panel-sys-browser.lisp b/tools/panel-sys-browser.lisp index 4f2d256..76b8c6c 100644 --- a/tools/panel-sys-browser.lisp +++ b/tools/panel-sys-browser.lisp @@ -15,58 +15,115 @@ (search-js :accessor search-js :initform nil) (fname :accessor fname) (state :accessor state :initform t))) (defun create-sys-browser - (clog-obj &key (hidden nil) (class nil) (html-id nil) (auto-place t)) + (clog-obj &key hidden class style html-id (auto-place t)) (let ((panel (change-class (clog:create-div clog-obj :content - "
status
" - :hidden hidden :class class :html-id html-id - :auto-place auto-place) + " + + + + + + + + + + + + + +
+ + + + + + + + + + + +
status
" + :hidden hidden :class class :style style :html-id + html-id :auto-place auto-place) 'sys-browser))) (setf (slot-value panel 'status-box) - (attach-as-child clog-obj "CLOGB3921165402" :clog-type + (attach-as-child clog-obj "CLOGB3930618998" :clog-type 'clog:clog-div :new-id t)) (setf (slot-value panel 'save-button) - (attach-as-child clog-obj "CLOGB3921165401" :clog-type + (attach-as-child clog-obj "CLOGB3930618997" :clog-type 'clog:clog-form-element :new-id t)) (setf (slot-value panel 'eval-button) - (attach-as-child clog-obj "CLOGB3921165400" :clog-type + (attach-as-child clog-obj "CLOGB3930618996" :clog-type 'clog:clog-form-element :new-id t)) (setf (slot-value panel 'eval-sel-button) - (attach-as-child clog-obj "CLOGB3921165399" :clog-type + (attach-as-child clog-obj "CLOGB3930618995" :clog-type 'clog:clog-form-element :new-id t)) (setf (slot-value panel 'eval-form-button) - (attach-as-child clog-obj "CLOGB3921165398" :clog-type + (attach-as-child clog-obj "CLOGB3930618994" :clog-type 'clog:clog-form-element :new-id t)) (setf (slot-value panel 'file-name) - (attach-as-child clog-obj "CLOGB3921165397" :clog-type + (attach-as-child clog-obj "CLOGB3930618993" :clog-type 'clog:clog-form-element :new-id t)) (setf (slot-value panel 'src-box) - (attach-as-child clog-obj "CLOGB3921165396" :clog-type + (attach-as-child clog-obj "CLOGB3930618992" :clog-type 'clog-ace:clog-ace-element :new-id t)) (setf (slot-value panel 'pac-box) - (attach-as-child clog-obj "CLOGB3921165395" :clog-type + (attach-as-child clog-obj "CLOGB3930618991" :clog-type 'clog:clog-form-element :new-id t)) (setf (slot-value panel 'doc-box) - (attach-as-child clog-obj "CLOGB3921165394" :clog-type + (attach-as-child clog-obj "CLOGB3930618990" :clog-type 'clog:clog-text-area :new-id t)) (setf (slot-value panel 'class-box) - (attach-as-child clog-obj "CLOGB3921165393" :clog-type + (attach-as-child clog-obj "CLOGB3930618989" :clog-type 'clog:clog-select :new-id t)) (setf (slot-value panel 'search-box) - (attach-as-child clog-obj "CLOGB3921165392" :clog-type + (attach-as-child clog-obj "CLOGB3930618988" :clog-type 'clog:clog-form-element :new-id t)) (setf (slot-value panel 'class-only) - (attach-as-child clog-obj "CLOGB3921165391" :clog-type + (attach-as-child clog-obj "CLOGB3930618987" :clog-type 'clog:clog-form-element :new-id t)) (setf (slot-value panel 'label-class-only) - (attach-as-child clog-obj "CLOGB3921165390" :clog-type + (attach-as-child clog-obj "CLOGB3930618986" :clog-type 'clog:clog-label :new-id t)) (setf (slot-value panel 'package-box) - (attach-as-child clog-obj "CLOGB3921165389" :clog-type + (attach-as-child clog-obj "CLOGB3930618985" :clog-type 'clog:clog-select :new-id t)) (setf (slot-value panel 'type-box) - (attach-as-child clog-obj "CLOGB3921165388" :clog-type + (attach-as-child clog-obj "CLOGB3930618984" :clog-type 'clog:clog-select :new-id t)) (let ((target (type-box panel))) (declare (ignorable target)) diff --git a/tutorial/README.md b/tutorial/README.md index f68c0a7..8c36fc6 100644 --- a/tutorial/README.md +++ b/tutorial/README.md @@ -1,5 +1,14 @@ To run a tutorial load clog: +If using the builder open a CLOG Builder REPL and type: + +``` +> (clog:run-tutorial 1) +``` + +If using another REPL load CLOG: + + ``` CL-USER> (ql:quickload :clog) To load "clog":