diff options
author | riton <riton@riton.home> | 2025-03-26 00:00:29 +0300 |
---|---|---|
committer | riton <riton@riton.home> | 2025-03-26 00:00:29 +0300 |
commit | 85b2910290f762533dfc7f507e9293424e379c81 (patch) | |
tree | 7ff66764f1e6bf197bb055531bb76812af37db94 | |
parent | 030b33e8506be54f1faf9d0391a3b80ac129e13b (diff) |
küçük refaktör
-rw-r--r-- | üretim.lisp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/üretim.lisp b/üretim.lisp index 3f8c8cc..51d75e0 100644 --- a/üretim.lisp +++ b/üretim.lisp @@ -2,25 +2,29 @@ (defparameter *indent* 0) (defparameter *indent-increment* 2) -(defparameter *yeni-satır* t) +(defparameter *satır-başı* t) (defgeneric node->html (node &optional stream) (:method (node &optional (stream *standard-output*)) (write-string node stream)) (:documentation "NODE u STREAM e yazar")) -(defun tag-yeni-satır? (tag) +(defun tag-başı-yeni-satır? (tag) (case tag ((:html :head :body :div :ol :ul :link) t) ((:title :p :b :i :code :li) nil))) -(defun tag-inline? (tag) +(defun tag-sonu-yeni-satır? (tag) (case tag - ((:html :head :body :div :ol :ul :li :p :title) nil) + ((:html :head :body :div :ol :ul :li :p :title :pre) nil) ((:b :i :code) t))) +(defun yeni-satır-yaz (stream) + (write-char #\Newline stream) + (setf *satır-başı* t)) + (defmethod node->html :before ((node node) &optional (stream *standard-output*)) - (unless (not *yeni-satır*) + (unless (not *satır-başı*) (loop :for i :from 0 :below *indent* :do (write-char #\Space stream))) (if (null (props node)) @@ -29,10 +33,9 @@ :for (k v) :on (props node) :by #'cddr :do (format stream " ~a=\"~a\"" k v) :finally (write-char #\> stream))) - (setf *yeni-satır* nil) - (when (tag-yeni-satır? (tag node)) - (write-char #\Newline stream) - (setf *yeni-satır* t))) + (setf *satır-başı* nil) + (when (tag-başı-yeni-satır? (tag node)) + (yeni-satır-yaz stream))) (defmethod node->html ((node node) &optional (stream *standard-output*)) (if (null (children node)) @@ -42,13 +45,12 @@ :do (node->html child stream))))) (defmethod node->html :after ((node node) &optional (stream *standard-output*)) - (unless (not *yeni-satır*) + (unless (not *satır-başı*) (loop :for i :from 0 :below *indent* :do (write-char #\Space stream))) - (if (tag-inline? (tag node)) - (format stream "</~a>" (tag node)) - (progn (format stream "</~a>~%" (tag node)) - (setf *yeni-satır* t)))) + (format stream "</~a>" (tag node)) + (when (tag-sonu-yeni-satır? (tag node)) + (yeni-satır-yaz stream))) (defun node->cons (node) |