Skip to content

Commit

Permalink
macro macro added to the template module
Browse files Browse the repository at this point in the history
version bump to 2.5 pre-release
  • Loading branch information
markomanninen committed Apr 5, 2017
1 parent 144a0f5 commit 4da01d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions hyml/template.hy
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,28 @@
; pass variables and functions dictionaries to render-template function
(apply render-template (extend (extend [~tmpl] ~args) [(globals)])))
(render-template ~tmpl (globals))))

; beside render-template and extend-template, macro can be used
; to pass expression and variables directly to the parse-mnml
; functionality instead of using file to read the expression
; usage: (macro `(p ~var) {"var" 1}) -> <p>1</p>
; - one must quasiquote (`) the expression.
; - expression must have a single root node
; - dictionary of variables is optional and can be provided
; as the first or the second argument to the macro
; - one argument is mandatory
; - if the only argument is empty string or dictionary None will be returned
(defmacro macro [p1 &optional p2]
; detect if the first or the second is the dictionary or the expression
(setv variables {})
(if (isinstance p1 hy.HyDict)
(do (setv variables p1) (setv args p2))
(do (setv args p1)
(if (isinstance p2 hy.HyDict)
(setv variables p2))))
(if args
; merge dictionaries (local, global and variables-and-functions)
`(do (setv variables (merge-two-dicts ~variables variables-and-functions))
(setv variables (merge-two-dicts variables (globals)))
; quote before eval and parse evaluated expression
(parse-mnml (eval (quote ~args) ~variables) ~variables))))
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
'hyml': ['*.hy']
},

version = 'v0.2.4',
version = 'v0.2.5',
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.4.tar.gz',
download_url = 'https://github.com/markomanninen/hyml/archive/v0.2.5.tar.gz',
keywords = ['hylang', 'python', 'lisp', 'macros', 'markup language', 'dsl', 'xml', 'html', 'xhtml'],
platforms = ['any'],

Expand Down

0 comments on commit 4da01d8

Please sign in to comment.