plywood

Software Screenshot:
plywood
Software Details:
Version: 1.6.3
Upload Date: 20 Feb 15
Distribution Type: Freeware
Downloads: 14

Rating: 4.0/5 (Total Votes: 1)

plywood is a template language grammar that looks, feels, and works like Python

load('url')
load('compress')
doctype('html')
html:
 head:
 meta(charset="utf-8")
 meta(name="viewport", content="width=device-width; initial-scale=1.0")
 title:
 if title:
 # docstrings *are* stripped of preceding whitespace (they must be
 # indented), and the first and last newline is removed.
 """
 {title} |
 """ # string intepolation is a little more heavy-duty than `.format()`, but more similar than different.
 'Welcome' # string literals require quotes :-/ I *might* add another way to do this...
 compress('css'):
 link(rel='stylesheet', type='text/css', href=static('css/reset.css'))
 link(rel='stylesheet', type='text/css', href=static('css/welcome.css'))
 script(src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", type="text/javascript")
 compress('js'):
 script(src=static("js/underscore.js"), type="text/javascript")
 script(src=static("js/backbone.js"), type="text/javascript")
 ieif 'lt IE 9':
 script(src="//html5shiv.googlecode.com/svn/trunk/html5.js", type="text/javascript")
 link(rel='stylesheet', type='text/css', href=static('css/ie.css'))
 block('extra_head') # blocks, and block inheritance? of course!
 body:
 div(class="wrapper", id="wrapper") # no shorthand for class and id (yet)
 header:
 block('header'):
 p(class="logo"):
 block('header_title'):
 if user:
 'Welcome, '{user.name}'
 else:
 'Welcome'
 if current_member:
 p(class="login"):
 "Welcome, {current_member.preferred_name}"
 a(href=url("logout")): 'Log Out'
 nav:
 ul:
 block('nav'):
 li: a(href=url("login")): 'Login'

 section class="breadcrumb":
 block('breadcrumb')

 section(class="main"):
 block('messages'):
 if messages:
 ul(class="messages"):
 for message in messages:
 li(class=message.tags): '{message}'
 script:
 # code literals, so that savvy editors can color the source code
 ```javascript
 $(document).ready(function(){
 $("ul.messages").addClass("animate");

 var fade_out = _(function() {
 this.addClass("fade-out")
 }).bind($("ul.messages"))

 setTimeout(fade_out, 5000);
 $("ul.messages").bind("click", fade_out);
 });
 ```
 block('content')

 footer:
 # p:
 # 'These are comments.'
 # span: '|'
 # '©2012 CrossFit'


INSTALLATION

 pip install plywood
 ply < in.ply > out.html


SYNTAX

Each line starts with a statement, which can either be a function (div, block) a literal (', '''), or a control statement (if, else, for).

Functions get called with the arguments and a "block":

# arguments are ((), {}), block is Block()
p
# arguments are ((), {'class': 'divvy'}), block is Block()
div(class="divvy")
# arguments are (('autofocus'), {'id': 'bio'}), block is Block(Literal('This is my bio'),)
textarea(autofocus, id="bio"): 'This is my bio'

Even if there is no "block", you'll get at the least at empty block object that you can call block.render on. It will be "falsey", though, so you can check for the existence of a block. The minimum "truthy" block is an empty string. That means div '' will give you a "truthy" block, but div will be a "falsey" block.

You can extend the crap out of plywood, because div, if, block, the whole lot, are all written as plywood extensions. Without the builtin extensions, the language couldn't actually do anything, because it is at its core just a language grammar.

WHY!?!?

I think there is room for another templating language.

Haml? Coffekup? Jade? They don't seem pythonic to me.

Plain-Jane HTML? Sure, if you want. That is, I think, the best alternative to plywood.

Even the great django template language is HTML made nastier by inserting additional markup. I looked at Jade and Haml as "yeah, you're getting there", but they didn't nail it.

I'm unapologettically a DIY-er. I think that sometimes wheels just need re-inventing! Plus, this gave me a chance to play with language grammars, which I think are fun. I'm using Modgrammar

Requirements:

  • Python

Similar Software

LLRP Toolkit
LLRP Toolkit

2 Jun 15

Pybtex
Pybtex

14 Apr 15

sphinxjp.themes.s6
sphinxjp.themes.s6

20 Feb 15

GeSHi
GeSHi

20 Feb 15

Other Software of Developer Colin Thomas-Arnold

StrangeCase
StrangeCase

20 Feb 15

chomsky
chomsky

20 Feb 15

punt
punt

20 Feb 15

Comments to plywood

Comments not found
Add Comment
Turn on images!