Permalink
Browse files

Fix README.md merge conflict.

  • Loading branch information...
davidsantiago committed Jul 19, 2012
2 parents 4770205 + 796da65 commit 595efafa2b502c4a568981bc5eb0a6f317eb5d10
View
@@ -7,3 +7,4 @@ classes
build
/stencil
test/spec
+.lein-*
View
@@ -0,0 +1,7 @@
+language: clojure
+lein: lein2
+script: lein2 all test
+jdk:
+ - openjdk7
+ - openjdk6
+ - oraclejdk7
View
@@ -30,14 +30,15 @@ The easiest way to render a small template is using the function
`render-string`, which takes two arguments, a string containing the text of
the Mustache template and a map of the values referenced in the template.
-The keys of the value map can be either keywords or strings; if a keyword and
-string of the same name are present, the string is preferred. (Why support
-both? Keywords are more convenient to use in Clojure, but not all valid
-Mustache keys can be made into keywords. Rather than force strings, Stencil
-lets you use whichever will work better for you).
+The keys of the value map can be either keywords or strings; if a
+keyword and string of the same name are present, the keyword is
+preferred. (Why support both? Keywords are more convenient to use in
+Clojure, but not all valid Mustache keys can be made into
+keywords. Rather than force strings, Stencil lets you use whichever
+will work better for you).
(render-string "Hi there, {{name}}."
- {"name" "Donald" :name "Dick"})
+ {"name" "Dick" :name "Donald"})
"Hi there, Donald."
For a larger template, holding onto it and passing it in as a string is
@@ -79,26 +80,17 @@ it.
### Manual Cache Management
-By default, the template cache will keep a template in the cache for 5
-seconds before it will decide to reload it. You can set the cache policy
-manually using the function `set-cache-policy`. The argument to
-`set-cache-policy` is a function that returns true if the cached item is still
-valid and false if it should be reloaded. The argument is a cache entry data
-structure; you should check the source of `stencil.loader` for specifics.
-However, there are some cache policy functions that should cover most cases:
-
-* `cache-forever` - This function can be used as a cache policy function that
-will keep templates in the cache forever (or until they are explicitly
-reloaded). This can be useful if you know that templates won't change during
-the life of the program.
-* `cache-never` - This function can be used similarly to never cache a
-template. Could be useful for development, so that changes to templates are
-available immediately.
-* `cache-timeout` - This function cannot be used as a cache policy function
-directly, it's a combinator. It takes an integer argument that will be the
-number of milliseconds to keep an item in the cache, and returns a cache
-policy function that implements that policy. The default cache policy is
-`(cache-timeout 5000)`.
+Stencil uses [core.cache](https://github.com/clojure/core.cache) for
+caching. By default, Stencil uses a simple LRU cache. This is a pretty
+good cache to use in deployed code, where the set of templates being
+rendered is probably not going to change during runtime. However, you
+can control the type of cache used by Stencil to get the most benefit
+out of your specific code's usage patterns. You can set the cache
+manually using the function `set-cache` from the `stencil.loader`
+namespace; pass it some object that implements the `CacheProtocol`
+protocol from core.cache. In particular, during development, you might
+want to use a TTL cache with a very low TTL parameter, so that
+templates are reloaded as soon as you modify them.
You can also work at an even lower-level, manually caching templates using the
`cache` function and the functions related to accessing the cache, then
@@ -132,7 +124,7 @@ In particular, the Mustache spec specifies that the output of lambda tags
should not be cached, and so Stencil does not. Keep that in mind if you decide
to use them in your templates.
-I'd like to thank YourKit for helping me keep Stencil fast.
+I'd like to thank YourKit for helping me keep Stencil fast.
YourKit is kindly supporting open source projects with its full-featured Java Profiler.
YourKit, LLC is the creator of innovative and intelligent tools for profiling
@@ -142,11 +134,11 @@ Java and .NET applications. Take a look at YourKit's leading software products:
## Obtaining
-If you are using Leiningen, you can add
+Simply add
- [stencil "0.2.0"]
+ [stencil "0.3.0"]
-to your project.clj and run `lein deps`.
+to the `:dependencies` key of your project.clj.
## Bugs and Missing Features
@@ -156,10 +148,19 @@ it as soon as possible.
## Recently
-* Released version 0.2.0. Supports Clojure 1.3 and now builds with lein instead of cake. Now uses Slingshot for exceptions instead of clojure.contrib.condition; should not result in any code changes unless you are examining exceptions.
+* Released version 0.3.0.
+ - Performance improvements (Thanks YourKit!).
+ - Keywords are now preferred over strings in contexts.
+ - Change to using core.cache for more flexible and easier to use
+ caching. API is slightly different, but only if you were managing
+ cache policy manually (see above).
+ - Lambdas that have `:stencil/pass-context` true in their metadata will be called with
+ the current context as their second argument.
### Previously...
+* Released version 0.2.0. Supports Clojure 1.3 and now builds with lein instead of cake. Now uses Slingshot for exceptions instead of clojure.contrib.condition; should not result in any code changes unless you are examining exceptions.
+
* Released version 0.1.2, fixing bug in the handling of missing partial templates and adding functions to remove entries from the dynamic template store and cache.
* Released version 0.1.1, fixing bug in the handling of inverted sections.
View
@@ -1,7 +1,19 @@
-(defproject stencil "0.2.0"
+(defproject stencil "0.3.0"
:description "Mustache in Clojure"
- :dependencies [[clojure "1.3.0"]
- [slingshot "0.8.0"]]
- :dev-dependencies [[ritz "0.2.0"]
- [org.clojure/data.json "0.1.1"]]
- :extra-files-to-clean ["test/spec"])
+ :dependencies [[org.clojure/clojure "1.3.0"]
+ [scout "0.1.0"]
+ [quoin "0.1.0"]
+ [slingshot "0.8.0"]
+ [org.clojure/core.cache "0.6.1"]]
+ :profiles {:dev {:dependencies [[org.clojure/data.json "0.1.2"]]}
+ :clj1.2 {:dependencies [[org.clojure/clojure "1.2.1"]]}
+ :clj1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
+ :clj1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
+ :clj1.5 {:dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]]}}
+ :aliases {"all" ["with-profile" "dev:dev,clj1.4:dev,clj1.5"]}
+ :repositories {"sonatype" {:url "http://oss.sonatype.org/content/repositories/releases"
+ :snapshots false
+ :releases {:checksum :fail :update :always}}
+ "sonatype-snapshots" {:url "http://oss.sonatype.org/content/repositories/snapshots"
+ :snapshots true
+ :releases {:checksum :fail :update :always}}})
View
@@ -17,7 +17,7 @@
the existing children, make the new node."))
(defprotocol ASTNode
- (render [this ^StrinbBuilder sb context-stack]
+ (render [this ^StringBuilder sb context-stack]
"Given a StringBuilder and the current context-stack, render this node to
the result string in the StringBuilder."))
@@ -108,8 +108,8 @@
(render [this ^StringBuilder sb context-stack] (.append sb this))
clojure.lang.PersistentVector
(render [this sb context-stack]
- (doseq [node this]
- (render node sb context-stack))))
+ (dotimes [i (count this)]
+ (render (nth this i) sb context-stack))))
;; Implement a Zipper over ASTZippers.
View
@@ -3,7 +3,8 @@
[stencil.loader :as loader])
(:use [stencil.parser :exclude [partial]]
[stencil.ast :rename {render node-render
- partial node-partial}]
+ partial node-partial}]
+ [quoin.text :as qtext]
[clojure.java.io :only [resource]]
stencil.utils))
@@ -32,29 +33,35 @@
(node-render (:contents this) sb (conj context-stack val)))
;; Callable value -> Invoke it with the literal block of src text.
(instance? clojure.lang.Fn ctx-val)
- (let [lambda-return (ctx-val (:content (:attrs this)))]
+ (let [current-context (first context-stack)
+ lambda-return (call-lambda ctx-val (:content (:attrs this))
+ current-context)]
;; We have to manually parse because the spec says lambdas in
;; sections get parsed with the current parser delimiters.
(.append sb (render (parse lambda-return
(select-keys (:attrs this)
[:tag-open :tag-close]))
- (first context-stack))))
+ current-context)))
;; Non-false non-list value -> Display content once.
:else
(node-render (:contents this) sb (conj context-stack ctx-val)))))
stencil.ast.EscapedVariable
(render [this ^StringBuilder sb context-stack]
(if-let [value (context-get context-stack (:name this))]
(if (instance? clojure.lang.Fn value)
- (.append sb (html-escape (render-string (str (value))
- (first context-stack))))
+ (.append sb (qtext/html-escape
+ (render-string (str (call-lambda value
+ (first context-stack)))
+ (first context-stack))))
;; Otherwise, just append its html-escaped value by default.
- (.append sb (html-escape value)))))
+ (.append sb (qtext/html-escape (str value))))))
stencil.ast.UnescapedVariable
(render [this ^StringBuilder sb context-stack]
(if-let [value (context-get context-stack (:name this))]
(if (instance? clojure.lang.Fn value)
- (.append sb (render-string (str (value)) (first context-stack)))
+ (.append sb (render-string (str (call-lambda value
+ (first context-stack)))
+ (first context-stack)))
;; Otherwise, just append its value.
(.append sb value)))))
Oops, something went wrong.

0 comments on commit 595efaf

Please sign in to comment.