djed.static¶
djed.static integrates BowerStatic into the Pyramid Web Framework. BowerStatic is a WSGI component that can serve static resources from front-end packages (JavaScript, CSS) that you install through the Bower package manager.
Contents¶
Getting Started¶
Install the package into your python environment:
$ /path/to/pyvenv/bin/pip install djed.static
Include it in your Pyramid application:
config.include('djed.static')
Set-up the path to the bower_components
directory in your .ini
file:
[app:main]
# ... other settings ...
djed.static.components_path = myapp:static/bower_components
Or use the following statement to add the bower_components
directory:
config.add_bower_components('myapp:static/bower_components')
Include static resources on your HTML page. You can do this in templates or somewhere else in your code:
request.include('jquery')
All additional required resources are automatically resolved and are also included on your HTML page.
Local Components¶
If you develop your own front-end-code (so called “local components”), you can also publish them with BowerStatic.
First of all you have to create a bower_components
directory:
config.add_bower_components('myapp:static/bower_components')
Local components can depend on all available packages in this directory.
If you have created such a local bower_components
directory, you can
add one or more local components:
config.add_bower_component('myapp:static/my_component', version='1.0.0')
Note
You can retrieve the version of your Pyramid application like this:
import pkg_resources
version = pkg_resources.get_distribution('myapp').version
Now you can include the added local components on your HTML page like any other component:
request.include('my_component')
This includes your front-end-code in the HTML page and all dependencies that
are defined in the bower.json
file.
Multiple Component Directories¶
BowerStatic provides the possibility to create more than one
bower_components
directory. Each directory is an “isolated universe” of
components. Components in a bower_components
directory can depend on each
other only – they cannot depend on components in another directory.
To use multiple bower_components
directories, you need to give them
names:
config.add_bower_components('myapp:static/more_components', name='more')
You can use components from this directories as follows:
request.include('jquery', 'more')
To use this bower_components
directory for local components:
config.add_bower_component('myapp:static/my_component', verions='1.0.0',
name='more')
After that, you can include your local components on the HTML page:
request.include('my_component', 'more')
Configuration¶
You can configure djed.static via your ini-file:
[app:myapp]
djed.static.components_name = lib
...
To understand the ini-setting options, let’s take a look at the URL structure that is generated by BowerStatic:
/bowerstatic/components/jquery/2.1.1/dist/jquery.js
The setting options allow you to change the first part of all your
components URLs and configure the name and the path of the default
bower_components
directory:
- djed.static.publisher_signature
The first part of all components URLs.
default:
bowerstatic
- djed.static.components_path
The path or asset specification to the default
bower_components
directory.default:
None
- djed.static.components_name
The name for the default components collection.
default:
components
Support and Development¶
If you’ve got questions, contact the djedproject mailling list.
To report bugs, use the issue tracker.
Check out trunk version via the Github repository:
git clone git@github.com:djedproject/djed.static.git
Changes¶
0.4 (2015-05-24)¶
- Simplified creation of local components
- Added setting option components_path
- Changed to PEP 420 namespace package
0.3 (2015-01-10)¶
- Support multiple bower_components directories
0.2 (2015-01-09)¶
- Added documentation
- Added setting options via ini file
0.1 (2015-01-06)¶
- Initial release