我在 enlive 中有一些转变:
(html/deftemplate tranforma-numero-template "public/index.html" [m]
[:#portugues :.conteudo] (html/content (:portugues m))
[:#ingles :.conteudo] (html/content (:ingles m))
[:#espanhol :.conteudo] (html/content (:espanhol m)))
它遵循一个模式。所以我想以某种方式抽象出这种模式。我想如果这样的事情是可能的:
(html/deftemplate tranforma-numero-template "public/index.html" [m]
[(html/pred (fn [node]
(when (seq formatos)
(-> node :attrs :id (set formatos)))))] (html/content ((keyword (-> node :attrs :id)) m)))
我知道对于这样一个简单的例子来说这有点过分了,但你明白了这个概念。