yenu/src/clj/yenu/layout.clj

47 lines
1.6 KiB
Clojure
Raw Normal View History

(ns yenu.layout
(:require [selmer.parser :as parser]
2017-03-17 00:23:13 +01:00
[selmer.filters :as filter]
[ring.util.http-response :refer [content-type ok]]
[ring.util.anti-forgery :refer [anti-forgery-field]]
2017-03-15 00:28:27 +01:00
[yenu.helpers.images :as image-helper]
2017-03-21 23:35:13 +01:00
[ring.middleware.anti-forgery :refer [*anti-forgery-token*]]
[clj-time.format :as time-format])
(:use [markdown.core]))
2017-03-29 14:39:03 +02:00
(declare ^:dynamic *identity*)
(declare ^:dynamic *app-context*)
(parser/set-resource-path! (clojure.java.io/resource "templates"))
(parser/add-tag! :csrf-field (fn [_ _] (anti-forgery-field)))
2017-03-17 00:23:13 +01:00
(filter/add-filter! :inc inc)
(filter/add-filter! :dec dec)
2017-03-21 23:35:13 +01:00
(filter/add-filter! :markdown-to-html md-to-html-string)
(filter/add-filter! :parse-date time-format/parse)
(defn render
"renders the HTML template located relative to resources/templates"
[template & [params]]
(content-type
2017-03-15 00:28:27 +01:00
(ok
(parser/render-file
template
(assoc params
:page template
:csrf-token *anti-forgery-token*
2017-03-29 14:39:03 +02:00
:servlet-context *app-context*
:identity *identity*
)))
2017-03-15 00:28:27 +01:00
"text/html; charset=utf-8"))
(defn error-page
"error-details should be a map containing the following keys:
:status - error status
:title - error title (optional)
:message - detailed error message (optional)
returns a response map with the error page as the body
and the status specified by the status key"
[error-details]
{:status (:status error-details)
:headers {"Content-Type" "text/html; charset=utf-8"}
:body (parser/render-file "error.html" error-details)})