diff --git a/clog-element-common.lisp b/clog-element-common.lisp index 6308ef3..9932aae 100644 --- a/clog-element-common.lisp +++ b/clog-element-common.lisp @@ -19,7 +19,7 @@ ;; create-a ;; ;;;;;;;;;;;;;; -(defgeneric create-a (clog-obj &key link content target auto-place) +(defgeneric create-a (clog-obj &key link content target class auto-place) (:documentation "Create a new CLOG-A as child of CLOG-OBJ with :LINK and :CONTENT (default \"\") and :TARGET (\"_self\") and if :AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ. @@ -34,8 +34,12 @@ place-inside-bottom-of CLOG-OBJ. &key (link "") (content "") (target "_self") + (class nil) (auto-place t)) - (create-child obj (format nil "~A" + (create-child obj (format nil "~A" + (if class + (format nil " class='~A'" (escape-string class)) + "") (escape-string target) (escape-string link) (escape-string content)) @@ -105,13 +109,18 @@ line break and if :AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ")) ;; create-button ;; ;;;;;;;;;;;;;;;;;;; -(defgeneric create-button (clog-obj &key content auto-place) +(defgeneric create-button (clog-obj &key content class auto-place) (:documentation "Create a new CLOG-Button as child of CLOG-OBJ with :CONTENT (default \"\") and if :AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ")) -(defmethod create-button ((obj clog-obj) &key (content "") (auto-place t)) - (create-child obj (format nil "" (escape-string content)) +(defmethod create-button ((obj clog-obj) + &key (content "") (class nil) (auto-place t)) + (create-child obj (format nil "" + (if class + (format nil " class='~A'" (escape-string class)) + "") + (escape-string content)) :clog-type 'clog-button :auto-place auto-place)) ;;;;;;;;;;;;;;; @@ -142,13 +151,17 @@ CLOG-OBJ")) ;; create-div ;; ;;;;;;;;;;;;;;;; -(defgeneric create-div (clog-obj &key content auto-place) +(defgeneric create-div (clog-obj &key content class 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 "
~A
" (escape-string content)) +(defmethod create-p ((obj clog-obj) + &key (content "") (class nil) (auto-place t)) + (create-child obj (format nil "~A
" + (if class + (format nil " class='~A'" (escape-string class)) + "") + (escape-string content)) :clog-type 'clog-p :auto-place auto-place)) @@ -448,13 +473,18 @@ CLOG-OBJ")) ;; create-span ;; ;;;;;;;;;;;;;;;;; -(defgeneric create-span (clog-obj &key content auto-place) +(defgeneric create-span (clog-obj &key content class auto-place) (:documentation "Create a new CLOG-Span as child of CLOG-OBJ with CONTENT 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 "~A" (escape-string content)) +(defmethod create-span ((obj clog-obj) + &key (content "") (class nil) (auto-place t)) + (create-child obj (format nil "~A" + (if class + (format nil " class='~A'" (escape-string class)) + "") + (escape-string content)) :clog-type 'clog-span :auto-place auto-place)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -472,15 +502,22 @@ CLOG-OBJ")) :p :pre :section :blockquote :h1 :h2 :h3 :h4 :h5 :h6 :hgroup)) -(defgeneric create-section (clog-obj section &key content auto-place) +(defgeneric create-section (clog-obj section &key content class auto-place) (:documentation "Create a new CLOG-Section of section type as child of CLOG-OBJ with CONTENT and if :AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ")) (defmethod create-section ((obj clog-obj) section - &key (content "") (auto-place t)) - (create-child obj (format nil "<~A>~A~A>" - section (escape-string content) section) + &key (content "") + (class nil) + (auto-place t)) + (create-child obj (format nil "<~A~A>~A~A>" + section + (if class + (format nil " class='~A'" (escape-string class)) + "") + (escape-string content) + section) :clog-type 'clog-section :auto-place auto-place)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -498,15 +535,22 @@ CLOG-OBJ")) :marked :del :ins :s :q :big :small :time :tt :cite :i :b :u :sub :su)) -(defgeneric create-phrase (clog-obj phrase &key content auto-place) +(defgeneric create-phrase (clog-obj phrase &key content class auto-place) (:documentation "Create a new CLOG-Phrase of phrase type as child of CLOG-OBJ with CONTENT and if :AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ")) (defmethod create-phrase ((obj clog-obj) phrase - &key (content "") (auto-place t)) - (create-child obj (format nil "<~A>~A~A>" - phrase (escape-string content) phrase) + &key (content "") + (class nil) + (auto-place t)) + (create-child obj (format nil "<~A~A>~A~A>" + phrase + (if class + (format nil " class='~A'" (escape-string class)) + "") + (escape-string content) + phrase) :clog-type 'clog-phrase :auto-place auto-place)) diff --git a/tutorial/16-tutorial.lisp b/tutorial/16-tutorial.lisp index 8399e53..cc7def6 100644 --- a/tutorial/16-tutorial.lisp +++ b/tutorial/16-tutorial.lisp @@ -11,37 +11,32 @@ (defun on-new-window (body) (load-css (html-document body) "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css") + ;; Bootstrap requires jQuery but there is no need to load it as so does CLOG so already loaded + ;; the generic boot.html (load-script (html-document body) "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js") (load-script (html-document body) "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js") (setf (title (html-document body)) "Hello Boostrap") - (let* ((jumbo (create-div body)) + (let* ((jumbo (create-div body :class "jumbotron text-center")) (tmp (create-section jumbo :h1 :content "My First Bootstrap Page")) (tmp (create-p jumbo :content "Resize this responsive page to see the effect!")) - (container (create-div body)) - (row (create-div container)) + (container (create-div body :class "container")) + (row (create-div container :class "row")) - (col1 (create-div row)) + (col1 (create-div row :class "col-sm-4")) (tmp (create-section col1 :h3 :content "Column 1")) (tmp (create-p col1 :content "Lorem ipsum dolor..")) - (col2 (create-div row)) + (col2 (create-div row :class "col-sm-4")) (tmp (create-section col2 :h3 :content "Column 2")) (tmp (create-p col2 :content "Lorem ipsum dolor..")) - (col3 (create-div row)) + (col3 (create-div row :class "col-sm-4")) (tmp (create-section col3 :h3 :content "Column 3")) - (tmp (create-p col3 :content "Lorem ipsum dolor.."))) + (tmp (create-p col3 :content "Lorem ipsum dolor..")))) - (setf (css-class-name jumbo) "jumbotron text-center") - (setf (css-class-name container) "container") - (setf (css-class-name row) "row") - (setf (css-class-name col1) "col-sm-4") - (setf (css-class-name col2) "col-sm-4") - (setf (css-class-name col3) "col-sm-4")) - (run body)) (defun start-tutorial ()