{
"info": {
"author": "Steve Troxel",
"author_email": "troxel@perlworks.com",
"bugtrack_url": null,
"classifiers": [
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Markup :: HTML"
],
"description": "TemplateRex\n===========\n\nTemplateRex is a pure template engine that has no embedded logic and is \nwritten in Python - small and fast. \n\nPhilosophy\n----------\n\nFirst order is KISS - keep it simple. Second is to strive to keep logic \ntogether in the logic domain handled by a first class scripting language \nand content/presentation (html,xml) in the presentation domain. \n\nInvariably template engines that embed logic/code within html continue \nto add functionality to the point where they themselves become a complex \nprogramming environment which is less functional but more complex and \ncryptic than the underlying python language itself - violating the KISS\nprinciple and raising the learning curve. \n\nTemplateRex templates are fully viewable in a browser or WYSIWYG \neditor. This facilitates divsion of labor by allowing front-end \ndesigners and back-end developers to work seperately - and not introduce \nsecurity issues. \n\nThis approach often results in dry'er code due to seperation of domains.\nFor example a common core code base could serve up completely different\nlook and feel presentations and data scope by using diifferent templates\nsets without a single for-loop or if-clause repeated.\n\nThere are other benefits refer to the paper \"Enforcing Strict Model-View Separation in\nTemplate Engines\" by Terence Parr University of San Francisco \n\n\nSynopsis\n--------\n\nHere is a small hello world example.\n\nPython Code::\n\n # --- Python Code ----\n from templaterex import TemplateRex\n\n trex = TemplateRex(fname='t-mytemplate.html')\n\n row = [ {'cellId:'A123','volt':1.21}, {'cellId:'B321','volt':1.52} ]\n\n for row in row_data:\n trex.render_sec('row', row )\n \n trex.render_sec('tbl',{'category':'List of Usernames'})\n\n rendered_str = trex.render()\n\n # ---------------------\n\nTemplate text::\n\n # --- Template t-mytemplate.html --------\n \n \n \n
...\n \n \n
\n
Cell ID
Voltage
\n \n
$cellId
$volt
\n \n
\n \n \n # ---------------------\n\nAs shown text blocks are bracketed with BEGIN=name/END=name delimiters \nplaced inside html comments. Note the END delimiter is named which helps\nwith fast comprehension of complex templates. \n\nText in these blocks (or sections) are rendered via a call to \nrender_sec(block_name,context). The overall or base template\nis rendered with a call to render(). These blocks can be hierarchically\nspecified for example.\n\nPython code::\n\n # --- Python Code ----\n from templaterex import TemplateRex\n\n trex = TemplateRex(fname='t-mytemplate.html')\n\n row = [ {'username:'Mary'},{'username':'Sam'} ]\n \n bat_lo_cell = [{ 'cellId':321,'volt':1.5}, { 'cellId':101,'volt':1.7}] }\n bat_hi_cell = [{ 'cellId':102,'volt':2.5}, { 'cellId':141,'volt':2.7}] }\n\n for row in bat_lo_cell:\n trex.render_sec('row', row )\n\n trex.render_sec('tbl', {'caption': 'Low Cells' } )\n\n for row in bat_hi_cell:\n trex.render_sec('row', row )\n\n trex.render_sec('tbl', {'caption': 'High Cells' } )\n\n rendered_str = trex.render()\n\n # ---------------------\n\nTemplate text::\n\n # --- Template t-mytemplate.html --------\n \n ... surrounding html ... \n \n \n
\n
$caption
\n
Cell ID
Voltage
\n \n
$cellId
$volt
\n \n
\n \n\n ... surrounding html ... \n\n # ---------------------\n\nThis will render two tables one following the other with the unique caption \nand data. Of course this could be done with a nested for-loop but given \nas is for clarity. \n\n\nTemplate Inheritance\n~~~~~~~~~~~~~~~~~~~~\n\nYou can specify a base or layout template. If the first line in a template \ncall contains a BASE specifier such as \n\n\n\nThe template algorithm will search the path for the base \ntemplate as specified and parses this template first. \n\n \nCalled Template text::\n\n # --- Template t-mytemplate.html --------\n \n\n \n
\n \n ... content here ...\n \n
\n \n\n ... surrounding html ... \n\n # ---------------------\n\n\nBase Template text::\n\n # --- Template t-layout.html --------\n \n \n ...\n \n \n \n ...heading stuff... \n \n $content\n \n \n \n \n\nPython Code::\n\n # --- Python Code ----\n from templaterex import TemplateRex\n\n trex = TemplateRex(fname='t-mytemplate.html')\n\n ....\n trex.render_sec('content', context_dict)\n ....\n\n rendered_str = trex.render()\n\n # ---------------------\n \n\nTemplate Includes\n~~~~~~~~~~~~~~~~~\n\nAnother basic capability is to include snippets within a templates. If\nduring processing an include statement is encountered such as \n \n \n \nThe contents of that template are included in the calling template \n \nFunction/Filters\n~~~~~~~~~~~~~~~~~~~~\n\nFunctions (sometimes called filters in other template engines) calls can\nbe specified within the template text with the following syntax::\n\n &function_to_be called($args1,'arg2',kwarg1=True,kwarg2='test')\n\nThe function name (behind the &) has to be either one of the builtin functions\nor a custom registered function call. If a function does not have args the \nfollwing matching parenthesis are required. \n\nThe args can either be string literals identified with quotes, True or False\nbooleans, integer or floating point numbers or a context variable. Context \nvariables are identified with either a leading $ or just bare word - using the \n$ delimiter is faster and encouraged for clarity. If a context variable is \nnot found in the context the function call is silent. \n\nFunctions can be easily registered in two ways. The easiest is to specify\ncustom functions during object creation the func_reg keyword. \n\nFor example:: \n\n func_custom_dict = {'format':format, 'myfunc':myfunc}\n trex = TemplateRex(fname=fspec_template, func_reg=func_custom_dict)\n\nWhich is equivalent to::\n\n func_custom_dict = {'format':format, 'myfunc':myfunc}\n\n trex = TemplateRex()\n trex.functions.update( func_custom_dict )\n trex.get_template(fspec_template)\n\nwould register the python format function and your own custom myfunc function.\nThen you could use the following in your template: \n\n Voltage is: &format($voltage,'.1f')\n\nWhere voltage is a context variable and needs to be passed in the context\ndictionary of the render call (either render_sec() or render() ) where the \nfunction is exists. \n\nBuiltin Function/Filters\n~~~~~~~~~~~~~~~~~~~~\nTBD - look in functions.py for code\n\nOptions: Comment Character(s)\n~~~~~~~~~~~~~~~~~~~~\n\nHTML comment characters for specifying section blocks are the default . However these are selectable. For example,\nhere is an object creation with different comment prefix and postfix characters options:: \n\n trex = TemplateRex(fname='dhcpcd-template.conf',cmnt_prefix='##-',cmnt_postfix='-##')\n \nThis will parse the template looking for section blocks delimited as::\n\n ##- BEGIN=static_section -##\n ... section block ... \n ##- END=static_section -##\n\nOptions: Development or Verbose Mode\n~~~~~~~~~~~~~~~~~~~~\n\nSometimes it is convienent to see what the file source of the templates used in rendered template outputs. This mode can be selected with a dev_mode argument. For example::\n\n trex = TemplateRex(fname='/etc/dhcpcd-template.conf',cmnt_prefix='##-',cmnt_postfix='-##',dev_mode=True)\n\nWhen the template is rendered on this object there will be commented hints about the location and section of templates used such as:: \n\n ##- Template:/etc/dhcpcd-template.conf Section:static_section Below -##\n interface eth0\n static ip_address=10.10.80.202/24\n static routers=10.10.80.1\n static domain_name_servers=192.168.101.210\n ##- Template:/etc/dhcpcd-template.conf Section:static_section Above -##",
"description_content_type": "",
"docs_url": null,
"download_url": "",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/troxel/TemplateRex-Python",
"keywords": "template web html text logicless",
"license": "MIT",
"maintainer": "",
"maintainer_email": "",
"name": "TemplateRex",
"package_url": "https://pypi.org/project/TemplateRex/",
"platform": "",
"project_url": "https://pypi.org/project/TemplateRex/",
"project_urls": {
"Homepage": "https://github.com/troxel/TemplateRex-Python"
},
"release_url": "https://pypi.org/project/TemplateRex/1.2/",
"requires_dist": null,
"requires_python": "",
"summary": "KISS Pure Logicless Template Engine",
"version": "1.2"
},
"last_serial": 4500830,
"releases": {
"1.2": [
{
"comment_text": "",
"digests": {
"md5": "28b44e2bbc699d570cfcad5912414bda",
"sha256": "068bab584349d3244e9d80b87e821fc871a9a163bb9042ce376664a4cc35ecc6"
},
"downloads": -1,
"filename": "TemplateRex-1.2.tar.gz",
"has_sig": false,
"md5_digest": "28b44e2bbc699d570cfcad5912414bda",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 14047,
"upload_time": "2018-11-18T22:14:42",
"url": "https://files.pythonhosted.org/packages/d6/ac/72db1b6a3cba4e4f3094e2a31aa012566db130598e6f083e26757b086cd4/TemplateRex-1.2.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "28b44e2bbc699d570cfcad5912414bda",
"sha256": "068bab584349d3244e9d80b87e821fc871a9a163bb9042ce376664a4cc35ecc6"
},
"downloads": -1,
"filename": "TemplateRex-1.2.tar.gz",
"has_sig": false,
"md5_digest": "28b44e2bbc699d570cfcad5912414bda",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 14047,
"upload_time": "2018-11-18T22:14:42",
"url": "https://files.pythonhosted.org/packages/d6/ac/72db1b6a3cba4e4f3094e2a31aa012566db130598e6f083e26757b086cd4/TemplateRex-1.2.tar.gz"
}
]
}