Skip to content

Instantly share code, notes, and snippets.

@cgrand
Created October 10, 2009 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrand/206792 to your computer and use it in GitHub Desktop.
Save cgrand/206792 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta name="parent" content="layout"/>
</head>
<body>
<col1><div>ccol1</div></col1>
<col2><div>ccol2</div></col2>
<col3><div>ccol3</div></col3>
</body>
<html>
(declare layout)
(def lookup {"layout" #'layout})
(defn parent-template [nodes]
(when-let [id (-> nodes
(select [[:meta (attr= :name "parent")]])
first :attrs :content)]
(lookup id)))
(defmacro inheriting [source args & forms]
`(let [source# (html-resource ~source)
parent# (parent-template source#)]
(comp (or parent# emit*) (snippet* source# ~args ~@forms))))
(def layout (inheriting "layout.html" [child]
[:col1] (substitute (select child [:col1 :> :*]))
[:col2] (substitute (select child [:col2 :> :*]))
[:col3] (substitute (select child [:col3 :> :*]))))
(def child (inheriting "child.html" [msg]
[:col2 :div] (content msg)))
(println (apply str (child "hello")))
(comment
<html>
<head></head>
<body>
<header></header>
<main>
<div>ccol1</div>
<div>hello</div>
<div>ccol3</div>
</main>
<footer></footer>
</body>
</html>
)
<html>
<head />
<body>
<header />
<main>
<col1 />
<col2 />
<col3 />
</main>
<footer />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment