Skip to content

Instantly share code, notes, and snippets.

@murtaza52
Created June 6, 2012 18:19
Show Gist options
  • Save murtaza52/2883717 to your computer and use it in GitHub Desktop.
Save murtaza52/2883717 to your computer and use it in GitHub Desktop.
enlive to enfocus
;;;Server Side code which retrieves a html fragment from client
(ns faiz.client.transforms
(:require [enfocus.core :as ef])
(:use-macros [enfocus.macros :only [append defsnippet content at set-attr html-content]])
(:require-macros [fetch.macros :as fm])
(:use [faiz.client.utils :only [log]]))
(defn doc [] js/document)
(defn init []
(fm/letrem [n (get-navbar)]
(log "Top Navbar" n)
(at (doc)
["body > header"] (html-content n))))
;;;Client Side code
(ns faiz.views.main
(:use [net.cgrand.enlive-html]
[noir.core :only [defpage]]
[noir.fetch.remotes :only [defremote]]))
(def title "Faiz-ul-Mawaid-il-Burhaniyah - Poona Students")
(def links [{:url "#" :text "Home"} {:url "#" :text "Hisaab"}])
(def templ "faiz/templates/components.html")
(deftemplate index "faiz/views/index.html" [title]
[:title] (content title))
(defsnippet nav-link templ [:top-navbar (attr= :data-navlinks "left") :> first-child]
[{:keys [url text]}]
[:a] (set-attr :href url)
[:a] (content text))
(defsnippet top-navbar templ [:top-navbar]
[links]
[[:ul (attr= :data-navlinks "left")]] (content (map nav-link links)))
(defn to->html [n]
(apply str (emit* n)))
(defremote get-navbar []
(to->html (top-navbar links)))
(defpage "/" []
(index title))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment