Start of commone HTML elements for CLOG

This commit is contained in:
David Botton 2021-01-07 21:09:41 -05:00
parent 4e201cdec5
commit d5eac402f3
5 changed files with 176 additions and 29 deletions

110
clog-element-common.lisp Normal file
View file

@ -0,0 +1,110 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; CLOG - The Common Lisp Omnificent GUI ;;;;
;;;; (c) 2020-2021 David Botton ;;;;
;;;; License BSD 3 Clause ;;;;
;;;; ;;;;
;;;; clog-element-commont.lisp ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(cl:in-package :clog)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation - clog-br
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass clog-br (clog-element)()
(:documentation "CLOG BR Objects for line breaks."))
;;;;;;;;;;;;;;;
;; create-br ;;
;;;;;;;;;;;;;;;
(defgeneric create-br (clog-obj &key content auto-place)
(:documentation "Create a new CLOG-BR as child of CLOG-OBJ that creates a
line break and if :AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ"))
(defmethod create-br ((obj clog-obj) &key (content "") (auto-place t))
(create-child obj (format nil "<br />" (escape-string content))
:clog-type 'clog-br))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation - clog-div
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass clog-div (clog-element)()
(:documentation "CLOG Div Objects."))
;;;;;;;;;;;;;;;;
;; create-div ;;
;;;;;;;;;;;;;;;;
(defgeneric create-div (clog-obj &key content auto-place)
(:documentation "Create a new CLOG-Div as child of CLOG-OBJ with :CONTENT
(default \"\") and if :AUTO-PLACE (default t) place-inside-bottom-of
CLOG-OBJ"))
(defmethod create-div ((obj clog-obj) &key (content "") (auto-place t))
(create-child obj (format nil "<div>~A</div>" (escape-string content))
:clog-type 'clog-div))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation - clog-hr
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass clog-hr (clog-element)()
(:documentation "CLOG HR Objects for horizontal rules."))
;;;;;;;;;;;;;;;
;; create-hr ;;
;;;;;;;;;;;;;;;
(defgeneric create-hr (clog-obj &key content auto-place)
(:documentation "Create a new CLOG-HR as child of CLOG-OBJ that creates a
horizontal rule (line) and if :AUTO-PLACE (default t) place-inside-bottom-of
CLOG-OBJ"))
(defmethod create-hr ((obj clog-obj) &key (content "") (auto-place t))
(create-child obj (format nil "<hr />" (escape-string content))
:clog-type 'clog-hr))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation - clog-p
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass clog-p (clog-element)()
(:documentation "CLOG P Objects."))
;;;;;;;;;;;;;;
;; create-p ;;
;;;;;;;;;;;;;;
(defgeneric create-p (clog-obj &key content auto-place)
(:documentation "Create a new CLOG-P as child of CLOG-OBJ with :CONTENT
(default \"\") and if :AUTO-PLACE (default t) place-inside-bottom-of
CLOG-OBJ"))
(defmethod create-p ((obj clog-obj) &key (content "") (auto-place t))
(create-child obj (format nil "<p>~A</p>" (escape-string content))
:clog-type 'clog-p))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation - clog-span
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass clog-span (clog-element)()
(:documentation "CLOG Span Objects."))
;;;;;;;;;;;;;;;;;
;; create-span ;;
;;;;;;;;;;;;;;;;;
(defgeneric create-span (clog-obj &key content auto-place)
(:documentation "Create a new CLOG-Span as child of CLOG-OBJ with :CONTENT
(default \"\") and if :AUTO-PLACE (default t) place-inside-bottom-of
CLOG-OBJ"))
(defmethod create-span ((obj clog-obj) &key (content "") (auto-place t))
(create-child obj (format nil "<span>~A</span>" (escape-string content))
:clog-type 'clog-span))

View file

@ -21,15 +21,15 @@ element objects."))
;; make-clog-element ;;
;;;;;;;;;;;;;;;;;;;;;;;
(defun make-clog-element (connection-id html-id)
"Construct a new clog-element. (Private)"
(make-instance 'clog-element :connection-id connection-id :html-id html-id))
(defun make-clog-element (connection-id html-id &key (clog-type 'clog-element))
"Construct a new clog-element or sub-element of CLOG-TYPE. (Private)"
(make-instance clog-type :connection-id connection-id :html-id html-id))
;;;;;;;;;;;;;;;;;;;;;;
;; create-with-html ;;
;;;;;;;;;;;;;;;;;;;;;;
(defun create-with-html (connection-id html)
(defun create-with-html (connection-id html &key (clog-type 'clog-element))
"Create a new clog-element and attach it to HTML on CONNECTION-ID. There must be
a single outer block that will be set to an internal id. The returned CLOG-Element
requires placement or will not be visible, ie. place-after, etc. as it exists in
@ -39,11 +39,7 @@ the javascript clog[] but is not in the DOM. (private)"
connection-id
(format nil "clog['~A']=$(\"~A\"); clog['~A'].first().prop('id','~A')"
web-id html web-id web-id))
(make-clog-element connection-id web-id)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Low Level - clog-element
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(make-clog-element connection-id web-id :clog-type clog-type)))
;;;;;;;;;;;;
;; attach ;;
@ -55,16 +51,21 @@ CONNECTION-ID to it and then return it. The HTML-ID must be unique. (private)"
(cc:execute connection-id (format nil "clog['~A']=$('#~A')" html-id html-id))
(make-clog-element connection-id html-id))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Low Level - clog-element
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;; create-child ;;
;;;;;;;;;;;;;;;;;;
(defgeneric create-child (clog-obj html &key auto-place)
(:documentation "Create a new CLOG-Element from HTML as child of CLOG-OBJ
and if :AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ"))
(defgeneric create-child (clog-obj html &key auto-place clog-type)
(:documentation "Create a new CLOG-Element or sub-type of CLOG-TYPE from HTML
as child of CLOG-OBJ and if :AUTO-PLACE (default t) place-inside-bottom-of
CLOG-OBJ"))
(defmethod create-child ((obj clog-obj) html &key (auto-place t))
(let ((child (create-with-html (connection-id obj) html)))
(defmethod create-child ((obj clog-obj) html &key (auto-place t) (clog-type 'clog-element))
(let ((child (create-with-html (connection-id obj) html :clog-type clog-type)))
(if auto-place
(place-inside-bottom-of obj child)
child)))
@ -73,13 +74,15 @@ and if :AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ"))
;; attach-as-child ;;
;;;;;;;;;;;;;;;;;;;;;
(defgeneric attach-as-child (clog-obj html-id)
(:documentation "Create a new CLOG-Element and attach an existing element with HTML-ID. The
HTML-ID must be unique."))
(defgeneric attach-as-child (clog-obj html-id &key clog-type)
(:documentation "Create a new CLOG-Element or sub-type of CLOG-TYPE and attach
an existing element with HTML-ID. The HTML-ID must be unique."))
(defmethod attach-as-child ((obj clog-obj) html-id)
(cc:execute (connection-id obj) (format nil "clog['~A']=$('#~A')" html-id html-id))
(make-clog-element (connection-id obj) html-id))
(defmethod attach-as-child ((obj clog-obj) html-id
&key (clog-type 'clog-element))
(cc:execute (connection-id obj)
(format nil "clog['~A']=$('#~A')" html-id html-id))
(make-clog-element (connection-id obj) html-id :clog-type clog-type))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; General Properties - clog-element

View file

@ -17,6 +17,7 @@
(:file "clog-utilities")
(:file "clog-base")
(:file "clog-element")
(:file "clog-element-common")
(:file "clog-window")
(:file "clog-document")
(:file "clog-location")

View file

@ -31,6 +31,7 @@ application."
(@clog-utilities section)
(@clog-obj section)
(@clog-element section)
(@clog-element-common section)
(@clog-body section)
(@clog-window section)
(@clog-document section)
@ -231,6 +232,28 @@ application."
(first-child generic-function)
(next-sibling generic-function))
(defsection @clog-element (:title "Common CLOG Elements")
"CLOG-BR - Class for CLOG Line Breaks"
(clog-br class)
(create-br generic-function)
"CLOG-Div - Class for CLOG Divs"
(clog-div class)
(create-div generic-function)
"CLOG-HR - Class for CLOG Hortizontal Rules"
(clog-HR class)
(create-HR generic-function)
"CLOG-P - Class for CLOG Paragraphs"
(clog-p class)
(create-p generic-function)
"CLOG-Span - Class for CLOG Spans"
(clog-span class)
(create-span generic-function)
)
(defsection @clog-body (:title "CLOG Body Objects")
"CLOG-Body - CLOG Body Objects"
(clog-body class)
@ -340,6 +363,8 @@ application."
(defun make-markup ()
(load "clog.lisp")
(load "clog-base.lisp")
(load "clog-element.lisp")
(load "clog-element-common.lisp")
(load "clog-window.lisp")
(load "clog-navigator.lisp")
(load "clog-document.lisp")
@ -353,6 +378,8 @@ application."
(defun make-html ()
(load "clog.lisp")
(load "clog-base.lisp")
(load "clog-element.lisp")
(load "clog-element-common.lisp")
(load "clog-window.lisp")
(load "clog-navigator.lisp")
(load "clog-document.lisp")

View file

@ -44,6 +44,12 @@
(set-on-character win
(lambda (obj data)
(print data)))
(create-div win :content "Hello World! p")
(create-div win :content "Hello World! div")
(create-br win)
(create-span win :content "Hello World! span")
(create-hr win)
(setf (title (html-document win)) "CLOG Test App")
(print (title (html-document win)))
))