: 요청에 서버 이름 반환 :Clojure의, enlive, 멀티 사이트 내용에 따라 특정 템플릿을로드 할
(ns rosay.views.common
(:use noir.core)
(:require [noir.request :as req]
[clojure.string :as string]
[net.cgrand.enlive-html :as html]))
(defn get-server-name
"Pulls servername for template definition"
[]
(or (:server-name (req/ring-request)) "localhost"))
(defn get-template
"Grabs template name for current server"
[tmpl]
(string/join "" (concat [(get-server-name) tmpl])))
(html/deftemplate base (get-template "/base.html")
[]
[:p] (html/content (get-template "/base.html")))
그것은 반환 localhost를 작동/집은/usr/rosay/자원/localhost/base.html하지만 다른 호스트에 대해 테스트 할 때 "hostname2"라고 말하면 get-template은 /home/usr/rosay/resources/hostname2/base.html을보고 있지만 브라우저에서 렌더링 할 때 항상 표시됩니다. ../resources/localhost/base.html을 다시 가리 킵니다.
이 유스 케이스를 처리하기위한 매크로 또는 다른 방법이 있습니까?
문제는 deftemplate이 매크로이므로 컴파일시 평가됩니다. 그 시점에서 (: servername (req/ring-request)) nil이므로 "localhost"는보기를 위해 생성 된 클래스 파일에 하드 코드됩니다. –
irc에서 누군가와 이야기하면서 그들은 'at'를 사용할 가능성에 대해 언급했지만, 각 요청에 대해 템플릿을 다시 컴파일해야하기 때문에 성능에 대한 고려 사항이 있습니다 – battlemidget