küçük refaktör
This commit is contained in:
30
üretim.lisp
30
üretim.lisp
@@ -2,25 +2,29 @@
|
|||||||
|
|
||||||
(defparameter *indent* 0)
|
(defparameter *indent* 0)
|
||||||
(defparameter *indent-increment* 2)
|
(defparameter *indent-increment* 2)
|
||||||
(defparameter *yeni-satır* t)
|
(defparameter *satır-başı* t)
|
||||||
|
|
||||||
(defgeneric node->html (node &optional stream)
|
(defgeneric node->html (node &optional stream)
|
||||||
(:method (node &optional (stream *standard-output*))
|
(:method (node &optional (stream *standard-output*))
|
||||||
(write-string node stream))
|
(write-string node stream))
|
||||||
(:documentation "NODE u STREAM e yazar"))
|
(:documentation "NODE u STREAM e yazar"))
|
||||||
|
|
||||||
(defun tag-yeni-satır? (tag)
|
(defun tag-başı-yeni-satır? (tag)
|
||||||
(case tag
|
(case tag
|
||||||
((:html :head :body :div :ol :ul :link) t)
|
((:html :head :body :div :ol :ul :link) t)
|
||||||
((:title :p :b :i :code :li) nil)))
|
((:title :p :b :i :code :li) nil)))
|
||||||
|
|
||||||
(defun tag-inline? (tag)
|
(defun tag-sonu-yeni-satır? (tag)
|
||||||
(case 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)))
|
((: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*))
|
(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*
|
(loop :for i :from 0 :below *indent*
|
||||||
:do (write-char #\Space stream)))
|
:do (write-char #\Space stream)))
|
||||||
(if (null (props node))
|
(if (null (props node))
|
||||||
@@ -29,10 +33,9 @@
|
|||||||
:for (k v) :on (props node) :by #'cddr
|
:for (k v) :on (props node) :by #'cddr
|
||||||
:do (format stream " ~a=\"~a\"" k v)
|
:do (format stream " ~a=\"~a\"" k v)
|
||||||
:finally (write-char #\> stream)))
|
:finally (write-char #\> stream)))
|
||||||
(setf *yeni-satır* nil)
|
(setf *satır-başı* nil)
|
||||||
(when (tag-yeni-satır? (tag node))
|
(when (tag-başı-yeni-satır? (tag node))
|
||||||
(write-char #\Newline stream)
|
(yeni-satır-yaz stream)))
|
||||||
(setf *yeni-satır* t)))
|
|
||||||
|
|
||||||
(defmethod node->html ((node node) &optional (stream *standard-output*))
|
(defmethod node->html ((node node) &optional (stream *standard-output*))
|
||||||
(if (null (children node))
|
(if (null (children node))
|
||||||
@@ -42,13 +45,12 @@
|
|||||||
:do (node->html child stream)))))
|
:do (node->html child stream)))))
|
||||||
|
|
||||||
(defmethod node->html :after ((node node) &optional (stream *standard-output*))
|
(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*
|
(loop :for i :from 0 :below *indent*
|
||||||
:do (write-char #\Space stream)))
|
:do (write-char #\Space stream)))
|
||||||
(if (tag-inline? (tag node))
|
(format stream "</~a>" (tag node))
|
||||||
(format stream "</~a>" (tag node))
|
(when (tag-sonu-yeni-satır? (tag node))
|
||||||
(progn (format stream "</~a>~%" (tag node))
|
(yeni-satır-yaz stream)))
|
||||||
(setf *yeni-satır* t))))
|
|
||||||
|
|
||||||
|
|
||||||
(defun node->cons (node)
|
(defun node->cons (node)
|
||||||
|
|||||||
Reference in New Issue
Block a user