initial commit
This commit is contained in:
commit
6c14fd9a14
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
.DS_Store
|
||||||
|
/target
|
||||||
|
/classes
|
||||||
|
/checkouts
|
||||||
|
pom.xml
|
||||||
|
pom.xml.asc
|
||||||
|
*.jar
|
||||||
|
*.class
|
||||||
|
/.lein-*
|
||||||
|
/.nrepl-port
|
||||||
|
.settings/
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
28
LICENSE
Normal file
28
LICENSE
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
Copyright (c) 2014, Gered King All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
README.md
Normal file
14
README.md
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# clj-pebble
|
||||||
|
|
||||||
|
A wrapper for the [Pebble Java Templating Engine](http://www.mitchellbosecke.com/pebble) to make usage in Clojure
|
||||||
|
applications simple.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Distributed under the BSD 3-Clause License (the same as Pebble).
|
||||||
|
|
||||||
|
See `LICENSE` for full details.
|
10
project.clj
Normal file
10
project.clj
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
(defproject clj-pebble "0.1.0-SNAPSHOT"
|
||||||
|
:description "Clojure wrapper for the Pebble Java templating engine."
|
||||||
|
:url "https://github.com/gered/clj-pebble"
|
||||||
|
:license {:name "BSD 3-Clause License"
|
||||||
|
:url "http://opensource.org/licenses/BSD-3-Clause"}
|
||||||
|
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||||
|
[com.mitchellbosecke/pebble "1.0.0"]]
|
||||||
|
:profiles {:dev {:dependencies [[pjstadig/humane-test-output "0.6.0"]]
|
||||||
|
:injections [(require 'pjstadig.humane-test-output)
|
||||||
|
(pjstadig.humane-test-output/activate!)]}})
|
35
src/clj_pebble/core.clj
Normal file
35
src/clj_pebble/core.clj
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
(ns clj-pebble.core
|
||||||
|
(:import (java.io StringWriter)
|
||||||
|
(com.mitchellbosecke.pebble PebbleEngine)
|
||||||
|
(com.mitchellbosecke.pebble.loader DelegatingLoader ClasspathLoader FileLoader StringLoader)
|
||||||
|
(com.mitchellbosecke.pebble.template PebbleTemplate))
|
||||||
|
(:require [clojure.walk :refer [stringify-keys]]))
|
||||||
|
|
||||||
|
(defonce file-loader
|
||||||
|
(DelegatingLoader.
|
||||||
|
[(ClasspathLoader.)
|
||||||
|
(FileLoader.)]))
|
||||||
|
|
||||||
|
(defonce string-loader
|
||||||
|
(StringLoader.))
|
||||||
|
|
||||||
|
(defn- make-pebble-engine []
|
||||||
|
(PebbleEngine. file-loader))
|
||||||
|
|
||||||
|
(defonce engine (atom (make-pebble-engine)))
|
||||||
|
|
||||||
|
(defn create-engine! []
|
||||||
|
(reset! engine (make-pebble-engine)))
|
||||||
|
|
||||||
|
(defn prepare-context-map [context]
|
||||||
|
(if context
|
||||||
|
(stringify-keys context)
|
||||||
|
{}))
|
||||||
|
|
||||||
|
(defn render [^String template-source & [context]]
|
||||||
|
(.setLoader @engine string-loader)
|
||||||
|
(if-let [^PebbleTemplate compiled-template (.getTemplate @engine template-source)]
|
||||||
|
(let [writer (StringWriter.)
|
||||||
|
context (prepare-context-map context)]
|
||||||
|
(.evaluate compiled-template writer context)
|
||||||
|
(.toString writer))))
|
7
test/clj_pebble/core_test.clj
Normal file
7
test/clj_pebble/core_test.clj
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
(ns clj-pebble.core-test
|
||||||
|
(:require [clojure.test :refer :all]
|
||||||
|
[clj-pebble.core :refer :all]))
|
||||||
|
|
||||||
|
(deftest a-test
|
||||||
|
(testing "FIXME, I fail."
|
||||||
|
(is (= 0 1))))
|
Loading…
Reference in a new issue