(loop (print (eval (read))))

;;닭집을 차리기 위한 여정

Jade?

hexo테마

hexo로 블로그를 만들면서 테마때문에 꽤 골치를썩음.
일단 요 테마 strict 는 jade 라는 nodejs템플릿 라이브러리를 쓰고있음
그런데 보면 jade는 일정 형식을 가진 소스코드 -> 컴파일 -> html 의 구조를 갖는 템플릿 엔진이었다.

몇번 굴려보고 느낀점은..
야 이럴거면 그냥 clojure 하지;..

어쩌다보니 그냥 clojure 얘기

클로져 (혹은 다른 lisp, scheme 류) 에서는 이미 저런 시도가 흔하다.

hiccup.core.htmllink
1
2
3
4
5
6
7
8
9
10
11
12
;; user=>
(html [:div#foo.bar.baz "bang"])
;=> "<div id=\"foo\" class=\"bar baz\">bang</div>"
;; user=>
(html [:ul
(for [x (range 1 4)]
[:li x])])
;=> "<ul><li>1</li><li>2</li><li>3</li></ul>"

클로져의 웹프레임워크 라이브러리중 하나인 lib-noir 를 쓰면 defpage 매크로를 써서 url에 즉시 바인딩 시킬 수 있다.

1
2
3
4
5
(defpage "/test" []
(hic/html [:html
[:head]
[:body
[:h1 "Hello"]]]))

지금도 잘 쓰고있는 자바 라이브러리로 stripe 라는게 있다.
앞서 얘기한 재료를 잘 반죽하여 stripe를 구현할 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(defpartial layout [ & {:keys [script
header
content
footer]}]
(html5
[:head
[:title "my-website"]
(include-css "/css/reset.css")
(include-js "/js/main.js")
`(~@script)]
[:body
[:div#header `(~@header)]
[:div#wrapper `(~@content)]
[:div#tail `(~@footer)]]))
(defpage "/foo/page/select" []
(layout
:script
[[:script "my_website.core.alert_hello('hello');"]]
:header
[[:h1 "Hello"]]
:content
[[:table ]]))

결론

물론 php, jsp 등 흔히 server page 라고 부르는 방식으로 만들수고 있고, html을 파싱해다가 원하는 부분만 코드가 개입하도록 할 수도 있다.
요건 개취인듯.
하지만 협업을 포기한다면 (다른데는 모르겠고, 우리나라에서는 반드시 포기해야한다)
clojure의 저 접근이 괜찮은듯.
jade는 몰라.