aiohttp_themes¶
Scott Torborg - Cart Logic
aiohttp_themes
provides:
- Theme / template handling.
- Theme switching based on the
request
. - Theme configuration.
- Asset handling and compilation.
- Uses Mako, require.js, and sass.
Contents¶
Quick Start¶
Integrate with an aiohttp App¶
from aiohttp_themes.theme import Theme
from aiohttp_themes.asset import SASSAsset
class ExampleTheme(Theme):
key = 'example'
assets = {
'hello.css': SASSAsset('scss/main.scss'),
'alt.css': SASSAsset('scss/alt/different.scss'),
}
aiohttp_themes.setup(app,
themes=[ExampleTheme],
debug=True,
theme_strategy='example',
compiled_asset_dir='/tmp/compiled/')
Dynamically Switch Themes¶
The theme_strategy
argument can be a callable that returns a theme key:
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'
aiohttp_themes.setup(app,
...,
theme_strategy=mobile_theme_strategy)
Compile Assets¶
After configuring your app, call:
aiohttp_themes.compile(app, compiled_asset_dir=dir)
Contributing¶
Patches and suggestions are strongly encouraged! GitHub pull requests are preferred, but other mechanisms of feedback are welcome.
Aiohttp_themes attempts to have a comprehensive test suite, as reported by the
excellent coverage
module. To run the tests, simply run in the top level of
the repo:
$ tox
This will also ensure that the Sphinx documentation builds correctly, and that there are no PEP8 or Pyflakes warnings in the codebase.
Any pull requests should preserve all of these things.