[cl-who-devel] Generating html tree with dynamic structure
Dmitry V'yal
akamaus at gmail.com
Mon Nov 23 16:37:04 UTC 2009
Hello anyone,
I have a simple problem, but I can't find an elegant solution.
Basically I have a message and two flags, the first one signals message
should be rendered in <strong> tag and the second - in <italic>. So
there are four possibilities.
Here is the actual code:
(defmethod p-render-html ((s-tree tree) (p text-piece) s)
(with-html-output (s nil :prologue nil)
(let ((style (style-of p))
(txt (text-of p)))
(if style
(if (tree-find-prop s-tree style #'bold)
(htm (:strong (if (tree-find-prop s-tree style #'italic)
(htm (:italic (str txt)))
(str txt))))
(if (tree-find-prop s-tree style #'italic)
(htm (:italic (str txt)))
(str txt)))
(str txt)))))
I had to test for each case and it resulted in code duplication. Can it
be avoided? What if I had 5 flags or so?
More information about the Cl-who-devel
mailing list