Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement application.haml layout

  • Loading branch information...
commit 8fa212c2e25f4d5b236f240145ff721e4fbda433 1 parent 0bf35cf
@mmikulicic authored
View
6 README.md
@@ -15,3 +15,9 @@ you can change the directory where the templates are searched with:
haml is compiled to clojure code, you need to reload your module from REPL to see your changes in HAML.
+you can put layouts in the views/layouts directory, by default it will be loaded a views/layouts/application.haml.
+It should behave like the normal ruby haml layouts, using "yield":
+
+ %html
+ %body
+ = yield
View
19 src/haml_macro/core.clj
@@ -84,11 +84,26 @@
(def *templates-dir* (atom "views"))
+(defn haml-file-name [file]
+ (str @*templates-dir* "/" file))
+
(defn haml-file [file]
(haml-str (slurp (str @*templates-dir* "/" file))))
-(defn haml-file-name [file]
- (str *templates-dir* "/" file))
+(defn layout-path []
+ (str "layouts/" "application.haml"))
+
+(defn build-layout [l]
+ (list 'fn ['yield] (apply list 'list l)))
+
+(defn load-layout []
+ (let [lp (layout-path)]
+ (build-layout (if (.exists (java.io.File. (str @*templates-dir* "/" lp)))
+ (haml-file lp)
+ 'yield))))
+
+(defn haml-file-with-layout [file]
+ ((eval (load-layout)) (haml-file file)))
(defn eval-haml-file [file]
(eval (apply list compojure/html (haml-file file))))
View
3  views/layouts/application.haml
@@ -0,0 +1,3 @@
+%html
+ %body
+ = yield
Please sign in to comment.
Something went wrong with that request. Please try again.