I have the following Clojure code with a render function which renders a html page using enlive-html. Depending on the selected language a different html template is used.
As you can see, there is a lot of code duplication and I would like to remove it.
I was thinking of writing some macros but, if I understand correctly, the language (i.e. lang parameter) is not available at macro execution time because it is provided in the request and that is at execution time and not at compilation time.
I also tried to modify enlive in order to add i18n support at some later point but my Clojure skills are not there yet.
So the questions are:
How can I remove the code duplication in the code below?
Is enlive-html the way to go or should I use another library? Is there a library similar to enlive with support for i18n?
Thanks!
See the code here:
(ns myapp.core
(:require [net.cgrand.enlive-html :as e))
(deftemplate not-found-en "en/404.html"
[{path :path}]
[:#path] (e/content path))
(deftemplate not-found-fr "fr/404.html"
[{path :path}]
[:#path] (e/content path))
(defn getTemplate [page lang]
(case lang
:en (case page
:page/not-found not-found-en)
:fr (case page
:page/not-found not-found-fr)))
(defn render [lang [page params]]
(apply (getTemplate page lang) params))