Skip to content

Commit

Permalink
rename to player
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Nov 7, 2012
1 parent 2d509af commit 4a4b9f1
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 185 deletions.
24 changes: 12 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pyramid_layer
=============
player
======

.. image :: https://secure.travis-ci.org/fafhrd91/pyramid_layer.png
:target: https://secure.travis-ci.org/fafhrd91/pyramid_layer
.. image :: https://secure.travis-ci.org/fafhrd91/player.png
:target: https://secure.travis-ci.org/fafhrd91/player
pyramid_layer allows to address templates with two parameters,
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 `pyramid_layer` searches templates
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`::

Expand Down Expand Up @@ -34,7 +34,7 @@ Layer can to be defined with `add_layer` config directive:
.. code-block:: python
>> config = Configurator()
.. config.include('pyramid_layer')
.. config.include('player')
..
.. config.add_layer('form', path='./path_to_form_dirctory/form/')
Expand Down Expand Up @@ -64,7 +64,7 @@ or :
It is possible to run python code before rendering template.
There are `add_tmpl_filter` directive and `pyramid_layer.tmpl_filter`
There are `add_tmpl_filter` directive and `player.tmpl_filter`
decorator:

.. code-block:: python
Expand All @@ -78,9 +78,9 @@ or:

.. code-block:: python
>> import pyramid_layer
>> import player
>> @pyramid_layer.tmpl_filter('form:actions', name='custom')
>> @player.tmpl_filter('form:actions', name='custom')
.. def form_actions(context, request):
.. return {'url': ...}
Expand Down Expand Up @@ -122,7 +122,7 @@ and ::
Request method
--------------

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

.. ${structure: request.render_tmpl('form:actions')
Expand All @@ -139,4 +139,4 @@ player
License
-------

pyramid_layer is offered under the BSD license.
player is offered under the BSD license.
32 changes: 16 additions & 16 deletions pyramid_layer/__init__.py → player/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# pyramid_layer public api
# player public api

__all__ = ['tmpl_filter', 'wrap_layout', 'add_message',
'render', 'RendererNotFound', 'includeme']

from pyramid_layer.layer import tmpl_filter
from pyramid_layer.layout import wrap_layout
from pyramid_layer.renderer import render
from pyramid_layer.renderer import RendererNotFound
from pyramid_layer.message import add_message
from player.layer import tmpl_filter
from player.layout import wrap_layout
from player.renderer import render
from player.renderer import RendererNotFound
from player.message import add_message


def includeme(cfg):
Expand All @@ -16,10 +16,10 @@ def includeme(cfg):
from pyramid.settings import aslist
from pyramid.exceptions import ConfigurationError

from pyramid_layer.renderer import lt_renderer_factory
from pyramid_layer.layer import add_layer, add_layers, change_layers_order
from pyramid_layer.layer import add_tmpl_filter
from pyramid_layer.layout import add_layout, set_layout_data
from player.renderer import lt_renderer_factory
from player.layer import add_layer, add_layers, change_layers_order
from player.layer import add_tmpl_filter
from player.layout import add_layout, set_layout_data

# config directives
cfg.add_directive('add_layer', add_layer)
Expand Down Expand Up @@ -47,7 +47,7 @@ def includeme(cfg):

if order:
cfg.action(
'pyramid_layer.order',
'player.order',
change_layers_order, (cfg, order), order=999999+1)

# global custom layer
Expand All @@ -60,21 +60,21 @@ def includeme(cfg):
"Directory is required for layer.custom setting: %s"%custom)

cfg.action(
'pyramid_layer.custom',
'player.custom',
add_layers, (cfg, 'layer_custom', custom), order=999999+2)

# formatters
from pyramid_layer import formatter
from player import formatter
cfg.add_directive('add_formatter', formatter.add_formatter)
cfg.add_request_method(formatter.formatters, 'fmt', True, True)

# messages layer and request helpers
from pyramid_layer.message import render_messages
from player.message import render_messages

cfg.add_layer('message', path='pyramid_layer:templates/message/')
cfg.add_layer('message', path='player:templates/message/')

cfg.add_request_method(add_message, 'add_message')
cfg.add_request_method(render_messages, 'render_messages')

# scan
cfg.scan('pyramid_layer')
cfg.scan('player')
2 changes: 1 addition & 1 deletion pyramid_layer/formatter.py → player/formatter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" formatters """
from pyramid.registry import Introspectable

ID_FORMATTER = 'pyramid_layer:formatter'
ID_FORMATTER = 'player:formatter'


def add_formatter(cfg, name, callable):
Expand Down
6 changes: 3 additions & 3 deletions pyramid_layer/layer.py → player/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from pyramid.interfaces import IViewMapperFactory
from pyramid.config.views import DefaultViewMapper

log = logging.getLogger('pyramid_layer')
log = logging.getLogger('player')

ID_LAYER = 'pyramid_layer:layer'
ID_LAYER = 'player:layer'


def add_layer(cfg, layer, name='', path='', description=''):
Expand Down Expand Up @@ -98,7 +98,7 @@ def callback(context, name, ob):
add_tmpl_filter(
cfg, self.template, ob, self.name, self.description)

info = venusian.attach(wrapped, callback, category='pyramid_layer')
info = venusian.attach(wrapped, callback, category='player')

return wrapped

Expand Down
16 changes: 8 additions & 8 deletions pyramid_layer/layout.py → player/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from ordereddict import OrderedDict


log = logging.getLogger('pyramid_layer')
log = logging.getLogger('player')

LAYOUT_ID = 'pyramid_layer:layout'
LAYOUT_ID = 'player:layout'

LayoutInfo = namedtuple(
'LayoutInfo', 'name layout view original renderer intr')
Expand Down Expand Up @@ -114,19 +114,19 @@ class PageLayout(object):
config.add_layout('page', parent='page', renderer='my_package:template/page.pt')
To use layout with pyramid view use ``wrapper=pyramid_layer.wrap_layout()``
To use layout with pyramid view use ``wrapper=player.wrap_layout()``
Example:
.. code-block:: python
config.add_view('
index.html',
wrapper=pyramid_layer.wrap_layout(),
wrapper=player.wrap_layout(),
renderer = '...')
in this example '' layout is beeing used. You can specify specific layout
name for pyramid view ``pyramid_layer.wrap_layout('page')``
name for pyramid view ``player.wrap_layout('page')``
"""
(scope, module,
Expand All @@ -137,7 +137,7 @@ class PageLayout(object):

discr = (LAYOUT_ID, name, context, route_name)

intr = Introspectable(LAYOUT_ID, discr, name, 'pyramid_layer_layout')
intr = Introspectable(LAYOUT_ID, discr, name, 'player_layout')

intr['name'] = name
intr['context'] = context
Expand Down Expand Up @@ -296,13 +296,13 @@ def wrap_layout(layout=''):
.. code-block:: python
config = Configurator()
config.include('pyramid_layer')
config.include('player')
config.add_layout('page')
config.add_view(
'index.html',
wrapper=pyramid_layer.wrap_layout())
wrapper=player.wrap_layout())
"""
lname = '#layout-{0}'.format(layout)
Expand Down
2 changes: 1 addition & 1 deletion pyramid_layer/message.py → player/message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" simple messages """
from pyramid.compat import escape
from pyramid_layer import render, tmpl_filter
from player import render, tmpl_filter


def add_message(request, msg, type='info'):
Expand Down
2 changes: 1 addition & 1 deletion pyramid_layer/renderer.py → player/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .layer import ID_LAYER

ID_TEMPLATE = 'pyramid_layer:template'
ID_TEMPLATE = 'player:template'


class RendererNotFound(ValueError):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 12 additions & 19 deletions pyramid_layer/tests/base.py → player/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,32 @@ def setUp(self):

def make_request(self, registry=None,
environ=None, request_iface=IRequest, **kwargs):
if registry is None:
registry = self.registry
if environ is None:
environ=self._environ
request = testing.DummyRequest(environ=dict(environ), **kwargs)
request.request_iface = IRequest
if registry is None:
registry = self.registry
if registry is not None:
request.registry = registry
request._set_extensions(registry.getUtility(IRequestExtensions))

request.registry = registry
request._set_extensions(registry.getUtility(IRequestExtensions))
return request

def init_extensions(self):
def init_extensions(self, registry):
from pyramid.config.factories import _RequestExtensions

exts = self.registry.queryUtility(IRequestExtensions)
exts = registry.queryUtility(IRequestExtensions)
if exts is None:
exts = _RequestExtensions()
self.registry.registerUtility(exts, IRequestExtensions)
registry.registerUtility(exts, IRequestExtensions)

def init_pyramid(self):
self.request = request = self.make_request()
self.config = testing.setUp(
request=request,
settings=self._settings,
autocommit=self._auto_include)
settings=self._settings, autocommit=self._auto_include)
self.init_extensions(self.config.registry)
self.config.get_routes_mapper()
self.registry = self.config.registry
self.init_extensions()

self.request.registry = self.registry
self.request._set_extensions(
self.registry.getUtility(IRequestExtensions))

if self._include:
self.config.include('pyramid_layer')
self.config.include('player')

self.request = self.make_request()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pyramid.exceptions import ConfigurationError
from pyramid_layer.layer import ID_LAYER
from player.layer import ID_LAYER

from base import BaseTestCase

Expand All @@ -11,17 +11,17 @@ class TestSettingsError(BaseTestCase):

def test_custom(self):
self.assertRaises(
ConfigurationError, self.config.include, 'pyramid_layer')
ConfigurationError, self.config.include, 'player')


class TestSettingsCustom(BaseTestCase):

_auto_include = False
_settings = {'layer.custom': 'pyramid_layer:tests/bundle/'}
_settings = {'layer.custom': 'player:tests/bundle/'}

def test_custom_dir(self):
self.config.add_layer(
'dir1', path='pyramid_layer:tests/dir1/')
'dir1', path='player:tests/dir1/')
self.config.commit()

storage = self.registry.get(ID_LAYER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ def simple(request, v):

self.config.add_formatter('simple', simple)

request = self.make_request()

simple = request.fmt['simple']
self.assertIs(simple, request.fmt['simple'])
self.assertIs(request.fmt['simple'], request.fmt.simple)
simple = self.request.fmt['simple']
self.assertIs(simple, self.request.fmt['simple'])
self.assertIs(self.request.fmt['simple'], self.request.fmt.simple)

request = self.make_request()
self.assertIsNot(simple, request.fmt.simple)
Expand All @@ -47,7 +45,7 @@ def simple2(v):
""" """

config = Configurator()
config.include('ptahform')
config.include('player')

config.add_formatter('test', simple1)
config.add_formatter('test', simple2)
Expand All @@ -60,7 +58,7 @@ def simple(v):

self.config.add_formatter('simple', simple)

from pyramid_layer.formatter import ID_FORMATTER
from player.formatter import ID_FORMATTER

discr = (ID_FORMATTER, 'simple')
intr = self.config.introspector.get(ID_FORMATTER, discr)
Expand Down
Loading

0 comments on commit 4a4b9f1

Please sign in to comment.