Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. (ns hoge
  2. (require [net.cgrand.enlive-html :as en]))
  3.  
  4. (declare layout)
  5.  
  6. (def lookup {"layout" #'layout})
  7.  
  8. (defn parent-template [nodes]
  9. (when-let [id (-> nodes
  10. (en/select [[:meta (en/attr= :name "parent")]])
  11. first :attrs :content)]
  12. (var-get (lookup id))))
  13.  
  14. (defmacro inheriting [source args & forms]
  15. `(let [child# (en/html-resource ~source)
  16. parent# (parent-template child#)
  17. source# (en/at parent#
  18. [:main] (en/substitute (en/select child# [:body :> :*])))]
  19. (comp en/emit* (en/snippet* source# ~args ~@forms))))
  20.  
  21. (def layout (en/html-resource "layout.html"))
  22.  
  23. (def text (inheriting "text.html")
  24. [body]))
Add Comment
Please, Sign In to add comment