Coder Social home page Coder Social logo

clj-jade's Introduction

clj-jade

A thin wrapper around jade4j to promote use with the Clojure community.

Artifacts

[clj-jade "0.1.5"]

Example

index.jade

!!! 5
html
  head
    title= pageName
  body
    ol.guitars
      for guitar in guitars
        li #{guitar.maker} #{guitar.model} 
(require '[clj-jade.core :as jade])

(jade/render "index.jade" {"pageName" "My Guitars"
                           "guitars" [{"model" "Hummingbird" "maker" "Gibson"} 
                                      {"model" "Telecaster" "maker" "Fender"}]})
                                      
;; or

(jade/render "index.jade" {:pageName "My Guitars"
                           :guitars [{:model "Hummingbird" :maker "Gibson"} 
                                     {:model "Telecaster"  :maker "Fender"}]})

Produces:

<!DOCTYPE html>
<html>
  <head>
    <title>My Guitars</title>
  </head>
  <body>
    <ol class="guitars">
      <li>Gibson Hummingbird</li>
      <li>Fender Telecaster</li>
    </ol>
  </body>
</html>

Configuration

The default clj-jade configuration can be configured as follows.

(require '[clj-jade.core :as jade])

(jade/configure {:template-dir "examples/templates/"
                 :pretty-print true
                 :cache? true})

(jade/render "index.jade" {"pageName" "My Guitars"
                           "guitars" [{"model" "Hummingbird" "maker" "Gibson"} 
                                      {"model" "Telecaster" "maker" "Fender"}]})

Layouts and Includes

Please refer to the examples in the source to see how templates can be managed using layouts and includes.

Helpers

Helpers provide a mechanism to register custom view related functions that can be called directly from templates. For example, it might be useful to define helpers for date formatting, rounding etc.

Defining a helper

(ns clj-jade.example-helper.math
  (:gen-class
   :methods [[round [double] int]]))

(defn -round
  [this double]
  (Math/round double))

Configuring your helper

(jade/configure {:helpers {"math" (clj_jade.example_helper.math.)}})

Helper invocation from with templates

!!! 5
html
  body
    h1 #(helpers.math.round(number))
(jade/render "index.jade" {:number 2.6})

Produces:

<!DOCTYPE html>
<html>
  <body>
    <h1>3</h1>
  </body>
</html>

Note that as helper implementations use :gen-class you will need to ensure that you apply AOT compiling for all helper classes. This can be specified using the :aot lein option.

Acknowledgements

Thanks to the authors of jade4j for bringing jade to the JVM.

License

Copyright © 2013

Distributed under the Eclipse Public License, the same as Clojure.

clj-jade's People

Contributors

d0rc avatar lucagrulla avatar propan avatar ryangreenhall avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.