Scott Torborg - Cart Logic
Provides:
Command line tools:
Include pyramid_frontend, by calling config.include('pyramid_frontend') or adding pyramid_frontend to pyramid.includes.
Configure the following settings:
Register at least one theme, using the config.add_theme(theme) directive. You can also pass a dotted string (e.g. myapp.themes.foo.FooTheme) which will be resolved relative to the calling module.
Other possible mechanisms for theme registration which may be added later are a setuptools entrypoint or a settings key.
class MyTheme(Theme):
template_dir = ...
static_dir = ...
image_filters = {
'detail': ...
'thumb': ...
}
assets = {
'main-js': ('static/js/main.js', 'requirejs'),
'main-less': ('static/css/main.less', 'less'),
}
Configure your application to use a theme, with one of the following methods:
def mobile_theme_strategy(request):
if request.is_mobile and not request.session.get('use_desktop'):
return 'my-mobile-theme'
else:
return 'my-desktop-theme'
Inside your app, specify a .html or .txt renderer. It will be rendered using the currently active theme (or call the theme strategy function to determine which theme to use).
The request object has a few added methods.
When using in production, call pcompile production.ini to generate static assets, or call pyramid_frontend.compile(registry.settings).
Themes can stack on top of another theme by subclassing them.
An inheriting theme’s templates will layer on top of the superclass theme’s templates. The renderer will attempt to resolve templates to the child-most class first, then traverse up the inheritance chain.
Inside a template, you can refer to files with the prefix super: to make the filename resolve in the theme that is being inherited from.
An inheriting theme’s image filters will layer on top of the superclass theme’s image filters. If an image filter of the same name is specified, the child class will override the superclass.
An inheriting theme’s asset entry points will layer on top of the super class theme’s entry points. If an entry point of the same name is specified, the child class will override the superclass.
Each theme has exactly one static file directory. It will be served up at an underscore-prefixed path corresponding to the theme’s key.
The assets dict attribute maps entry point names to a tuple of URL paths and asset type.
In development, simply call request.asset_tag(key) to generate an asset tag.
In production, assets must be compiled before that call. The asset compilation step does the following for each entry point in each theme:
pyramid_frontend has a comprehensive test suite with 100% line and branch coverage, as reported by the excellent coverage module. To run the tests, simply run in the top level of the repo:
$ nosetests
There are no PEP8 or Pyflakes warnings in the codebase. To verify that:
$ pip install pep8 pyflakes
$ pep8 .
$ pyflakes .
Any pull requests must maintain the sanctity of these three pillars.