Skip to content

emanon-was/enlive-cljhtml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

enlive-cljhtml

Template engin for Clojure that uses [enlive]

Installation

Add following dependency to your project.clj

[enlive-cljhtml "0.0.2"]

Usage

Require

(require '[enlive.cljhtml :as template])

Root Directory

Set root directory for template in src (default: nil)

(template/cljhtml-root "template") ;; -> "src/template"

Mode

Set mode (default: :development)

:production (use template-cache)

(template/cljhtml-mode :production)

:development (read templates every time)

(template/cljhtml-mode :development)

Views

HTML src/template/test.html

<div>abcdefg</div>

:partial

(template/views :partial "test.html")
;; -> parse "<div>abcdefg</div>"

:render (append tag. html,head,body,etc...)

(template/views :render "test.html")
;; -> parse "<html><head></head><body><div>abcdefg</div></body></html>"

<clojure> Tag

HTML src/template/app.html

<html>
    <head></head>
    <body>
        <clojure>(template/html [:h1 "Title"])</clojure>
        <clojure>(template/views :partial "test.html")</clojure>
    </body>
</html>

Render

defrender macro

(defrender test [data]
    ;; base template
    (template/views :render "app.html")
    ;; selector & command
    [:h1] (template/prepend "Enlive")
    [:div] (template/append "hijklmn") 
    [:div] (template/append
               (template/html [:span (:content data)]))))

render macro

(def test
    (template/render [data]
        ;; base template
        (template/views :render "app.html")
        ;; selector & command
        [:h1] (template/prepend "Enlive")
        [:div] (template/append "hijklmn") 
        [:div] (template/append
                   (template/html [:span (:content data)]))))

use

(test {:content "opqrstu"})

output

<html>
    <head></head>
    <body>
        <h1>EnliveTitle</h1>
        <div>
            abcdefghijklmn
            <span>opqrstu</span>
        </div>
    </body>
</html>

Reload Cache

When template file is added

(template/cljhtml-cache)

License

Copyright © 2014 Daigo Kawasaki (@emanon_was)

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published