Pitmairen / hamlish-jinja

A haml-ish syntax for jinja2 templates
BSD 3-Clause "New" or "Revised" License
131 stars 11 forks source link

Added doctype strings. #15

Open totkeks opened 11 years ago

totkeks commented 11 years ago

I tried to use !!! as a shortcut (as pointed out in this nice example: https://gist.github.com/2502955) and was a bit disappointed that it didn't work. So I quickly wrote this patch to add the required doctype strings. This is just the basic idea, I guess using a custom node type (e.g. DocType) could be a bit better, since a lot of the whole doctype string is shared between all of them.

Feedback is welcome!

imdonkey commented 11 years ago

It works for me, @Pitmairen would you please put it in the master branch, thx a lot! :)

Pitmairen commented 11 years ago

I'm a little unsure about this.

Usually when using jinja you have a base template that the other templates are extending. So the doctype is needed only once in the base template. And also the html5 doctype is so simple and easy to remember that i think it's a little unnecessary to add a new syntax just for the doctype.

Another way to do this is simply using the existing syntax for variables and add the necessary doctypes to the jinja global variables. It will become something like this:

=html5
%html
  %head
    ...
imdonkey commented 11 years ago

thx a lot! That's works for me. After adding jinja global variables, I changed my doctype like this:

=html5|safe

Pitmairen commented 11 years ago

If you use the jinja2.Markup class when creating the docstring variable you don't need use the safe filter.

jinja_env.globals['html5'] = jinja2.Markup('<!DOCTYPE html>')
imdonkey commented 11 years ago

Thanks for your time on this issue. :)

yajo commented 11 years ago
-macro doctype(content):
    ='<!DOCTYPE ' + content + '>'

=doctype('html')