-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
736a8cf
commit 8a756c6
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/python3 | ||
;---------------------------------------------- | ||
; Template functionality | ||
; | ||
; Utilizing render-template and extend-template | ||
;---------------------------------------------- | ||
(require (hyml.minimal (*))) | ||
(import (hyml.minimal (*))) | ||
|
||
; template dir setter. this could be retrieved OR set | ||
; from other modules too | ||
(def template-dir "templates/") | ||
|
||
; return / chain extended list rather than extending in-place (.extend) | ||
(defn extend [a b] (.extend a b) a) | ||
|
||
; should take previus variables and pass them to the next template | ||
; globals are automaticly added, locals should be added with dictinary | ||
; or (locals) / (vars) | ||
; (setv variable "click") | ||
; (render-template "index.hyml" (locals)) | ||
(defn render-template [tmpl &rest args] | ||
; prefix template with dir | ||
(setv tmpl (+ template-dir tmpl)) | ||
; we want to get a recursive access to render-template function and | ||
; extend-template macro to enable "extend" / blocks functionality in templates | ||
(setv vars (globals)) | ||
; pass variables from arguments | ||
(for [d args] (setv vars (merge-two-dicts d vars))) | ||
; next part is very similar to parse-mnml unquote-splice part | ||
(.join "" (map | ||
(fn [item] (parse-mnml item vars)) | ||
; include will return unquote-splice (~@) so we need to get over them to | ||
; real content with first and second | ||
(eval (second (first (include tmpl))) vars)))) | ||
|
||
; to imitate jinja and mako | ||
; ~(extend-template "layout.hyml" {"var1" "val1" "var2" "val2"}) | ||
(defmacro extend-template [tmpl &rest args] | ||
`(if-not (empty? ~args) | ||
(do (setv args (list-comp (fn [arg] (parse-mnml arg)) (list ~args))) | ||
(apply render-template (extend (extend [~tmpl] ~args) [(globals)]))) | ||
(render-template ~tmpl (globals)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,13 @@ | |
'hyml': ['*.hy'] | ||
}, | ||
|
||
version = 'v0.2.2', | ||
version = 'v0.2.3', | ||
description = 'HyML - XML / (X)HTML generator for Hy', | ||
author = 'Marko Manninen', | ||
author_email = '[email protected]', | ||
|
||
url = 'https://github.com/markomanninen/hyml', | ||
download_url = 'https://github.com/markomanninen/hyml/archive/v0.2.2.tar.gz', | ||
download_url = 'https://github.com/markomanninen/hyml/archive/v0.2.3.tar.gz', | ||
keywords = ['hylang', 'python', 'lisp', 'macros', 'markup language', 'dsl', 'xml', 'html', 'xhtml'], | ||
platforms = ['any'], | ||
|
||
|