GitXplorerGitXplorer
f

player

public
3 stars
1 forks
1 issues

Commits

List of commits on branch master.
Unverified
b1de33452650429fc4f8e0d44a623af5ce23dea9

Merge pull request #2 from strobelm/master

ffafhrd91 committed 11 years ago
Unverified
07dc69b00c8e217689a43d795e0a0df0356b2573

update tests

ssidloki committed 11 years ago
Unverified
21a950302e99f30a505c973b9aa8f6bbe6af7327

update tests

ssidloki committed 11 years ago
Unverified
4557b003ad1baf304c05fbf7a635afff5653edc5

fix bootstrap3 error message

ssidloki committed 11 years ago
Unverified
755d0bacc9a62e5a93228f6ec5b18e5a98a5bab7

prepare release

ffafhrd91 committed 12 years ago
Unverified
d765faf75c05f540463b1494ee173a82830acb98

py2.6 comatibility

ffafhrd91 committed 12 years ago

README

The README file for this repository.

player

.. image :: https://travis-ci.org/fafhrd91/player.png :target: https://travis-ci.org/fafhrd91/player

player allows to address templates with two parameters, category and name. Also it is possible to use set of directories for each layer, in that case player searches templates in each directory. It allows to override templates without changing code. For example form library can define layer field::

 >> ls ./fields/
 .. bool.pt
 .. file.pt
 ...
 .. textarea.pt

In your application you can override any of this template by defining new layer for field category::

 >> ls ./myproject/fields/
 .. bool.pt

Usually top level directory is a category and file in directory is template. For example 'form:view.lt'::

`form` - layer category
`view` - template name
`.lt`  - custom pyramid renderer factory

Layer can to be defined with add_layer config directive:

.. code-block:: python

>> config = Configurator()
.. config.include('player')
..
.. config.add_layer('form', path='./path_to_form_dirctory/form/')

form directory can contain any template:

.. code-block:: python

>> ./form/
..   view.pt
..   actions.jinja2

It is possible to use any of this templates as pyramid renderer path:

.. code-block:: python

>> config.add_view(
..     name='view.html', 
..     renderer='form:view.lt')

or :

.. code-block:: python

>> config.add_view(
..     name='actions.html', 
..     renderer='form:actions.lt')

It is possible to run python code before rendering template. There are add_tmpl_filter directive and player.tmpl_filter decorator:

.. code-block:: python

>> def form_actions(context, request):
..     return {'url': ...}

>> config.add_tmpl_filter('form:actions', form_action, name='custom')

or:

.. code-block:: python

>> import player

>> @player.tmpl_filter('form:actions', name='custom')
.. def form_actions(context, request):
..     return {'url': ...}

form_actions function gets call just before rendering template. Layer has to be defined with add_layer directve before registering template filter function.

Customization

Any number of layer categories can be registered and any number of layers can be registered in each category. It doesnt require to override all templates from category. For example it is possible to override just view.pt template::

>> config.add_layer('form', 'custom', path='path_to_form_directory_2/form')

and content of this new directory::

>> ./another_path/form/
..   view.jinja2

Now view view.html uses view.jinja2 template. But actions.html stil uses original template.

Another example, if you want customize bool field from ptah.form package all you need is to create some folder, add it as 'fields' layer, and put bool.pt template to this folder, something like that::

config.add_layer('fields', 'custom', 'mypackage:fields')

and ::

.mypackage/fields/ .. bool.pt

Request method

player also provides request method render_tmpl. It acccepts path::

.. ${structure: request.render_tmpl('form:actions')

.lt extension is optional in this case.

player

...

License

player is offered under the BSD license.