An open API service indexing awesome lists of open source software.

https://github.com/jasonrbriggs/proton

Proton is a simple, "code-less" engine for xml/xhtml templates. Code-less, because it uses 3 types of ID (attribute) in a template file, rather than snippets of code — this moves the complexity out of the template and into the application.
https://github.com/jasonrbriggs/proton

haskell java nim python

Last synced: 3 months ago
JSON representation

Proton is a simple, "code-less" engine for xml/xhtml templates. Code-less, because it uses 3 types of ID (attribute) in a template file, rather than snippets of code — this moves the complexity out of the template and into the application.

Awesome Lists containing this project

README

          

proton
======

Proton is a simple, "code-less" engine for xml/xhtml templates. Code-less, because it uses 3 types of ID (attribute) in a template file, rather than snippets of code — this moves the complexity out of the template and into the application.

A simple Proton template looks like this:



PAGE TITLE


PAGE TITLE

LINK ITEM


  • LIST ITEMS



And to render this template in Python, you might do something like this:

from proton import template
tmp = template.get_template('test.xhtml')

tmp.set_value('title', 'An Xhtml Page', '*')
tmp.set_value('link', 'This is a link to Google')
tmp.set_attribute('link', 'href', 'http://www.google.com')

tmp.repeat('list-item', 5)
for x in range(0, 5):
tmp.set_value('list-item', 'test%s' % x, x)

print(str(tmp))

Resulting in the following output:



An Xhtml Page


An Xhtml Page

This is a link to Google


  • test0

  • test1

  • test2

  • test3

  • test4



Similarly in Haskell, you could do the following:

tmps <- loadTemplates "templates"
tmp <- getTemplate tmps "templates/test.xhtml"
tmp <- setElementValue tmp "title" "An Xhtml Page" 0
tmp <- setElementValue tmp "link" "This is a link to Google" 0
tmp <- setAttributeValue tmp "link" "href" "http://www.google.com" 0
tmp <- setElementValues tmp "list-item" (map (\x -> "test" ++ (show x)) [0..4])

s <- renderTemplate tmp