added view tags namespace. added ifempty tag
This commit is contained in:
parent
cbdd265a0f
commit
55bba64481
|
@ -2,7 +2,8 @@
|
||||||
(:use noir.request)
|
(:use noir.request)
|
||||||
(:require [clabango.parser :as parser]
|
(:require [clabango.parser :as parser]
|
||||||
[noir.session :as session]
|
[noir.session :as session]
|
||||||
[blarg.views.viewfilters]))
|
[blarg.views.viewfilters]
|
||||||
|
[blarg.views.tags]))
|
||||||
|
|
||||||
(def template-path "blarg/views/templates/")
|
(def template-path "blarg/views/templates/")
|
||||||
|
|
||||||
|
|
19
src/blarg/views/tags.clj
Normal file
19
src/blarg/views/tags.clj
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
(ns blarg.views.tags
|
||||||
|
(:use [clabango.tags])
|
||||||
|
(:require [clabango.filters :refer [context-lookup]]))
|
||||||
|
|
||||||
|
(deftemplatetag "ifempty" "endifempty" [[if-node & nodes] context]
|
||||||
|
(let [args (:args if-node)
|
||||||
|
body-nodes (butlast nodes)
|
||||||
|
[flip decision] (cond (= 1 (count args))
|
||||||
|
[empty? (first args)]
|
||||||
|
|
||||||
|
(and (= 2 (count args))
|
||||||
|
(= "not" (first args)))
|
||||||
|
[not-empty (second args)]
|
||||||
|
|
||||||
|
:default (throw (Exception. (str "Syntax error: "
|
||||||
|
if-node))))]
|
||||||
|
{:nodes (if (flip (context-lookup context decision))
|
||||||
|
(take-while #(not= "else" (:tag-name %)) body-nodes)
|
||||||
|
(rest (drop-while #(not= "else" (:tag-name %)) body-nodes)))}))
|
Reference in a new issue