danilobellini

PyJade example for friends =)

May 9th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Created on Fri May  9 18:02:31 2014
  4. # @author: Danilo de Jesus da Silva Bellini
  5. """ PyJade example for friends =) """
  6.  
  7. import jinja2, sys, math
  8.  
  9. debug = sys.argv[1:] and sys.argv[1] == "debug"
  10.  
  11. templ = """
  12. !!!5
  13. html
  14.  body
  15.    - with blah = 3 * cos(pi / 6)
  16.      .centralize
  17.        h3
  18.          | PyJade FTW!
  19.      - if blah > 3
  20.        | Blah is greater 3
  21.      - elif blah > 2
  22.        | Blah is in the (2; 3] interval
  23.      - else
  24.        | What is "blah" anyway?
  25.      .another-div.two-classes#withID
  26.        | Three times cosine of pi / 6 is
  27.        = " " + blah
  28. """
  29. env = jinja2.Environment(extensions=["jinja2.ext.WithExtension",
  30.                                      "pyjade.ext.jinja.PyJadeExtension"])
  31.  
  32. # Last extension from https://github.com/mitsuhiko/jinja2-htmlcompress
  33. # Just save the raw jinja2htmlcompress.py file from that GitHub repository in
  34. # the directory from which this script would be called
  35. if not debug: # Call the script with a "debug" argument to avoid this
  36.   env.add_extension("jinja2htmlcompress.HTMLCompress")
  37.  
  38. template = env.from_string(templ)
  39. print template.render(pi=math.pi, cos=math.cos)
Advertisement
Add Comment
Please, Sign In to add comment