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.
Dependencies¶
- python >= 3.3
- pyramid
- bowerstatic
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')
Now, you can use all installed bower packages. To include the desired components, call the following function in a HTML template or somewhere else in your code:
request.include('bootstrap')
This adds the following tags to the end of the HTML <head>
section:
<script type="text/javascript" src="/bowerstatic/components/jquery/2.1.4/dist/jquery.js"></script>
<script type="text/javascript" src="/bowerstatic/components/bootstrap/3.3.5/dist/js/bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="/bowerstatic/components/bootstrap/3.3.5/dist/css/bootstrap.css">
As you can see, all required dependencies are automatically resolved and also included in your HTML document.
Local Components¶
If you develop your own front-end-code (so called “local components”), you can also publish them with BowerStatic.
You can add one or more local components in this way:
config.add_bower_component('myapp:static/myapp')
To use a local components in an application, a bower_components
directory
has to been defined somewhere in the application configuration
(see Getting Started).
Local components can be included on your HTML page like any other component:
request.include('myapp')
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 more than one bower_components
directory, you need to give them
names:
config.add_bower_components('myapp:static/components_dir', name='dir')
You can use components from this directory as follows:
request.include('bootstrap', components_name='dir')
To use this bower_components
directory for local components:
config.add_bower_component('myapp:static/my_component', components_name='dir')
After that, you can include your local components on the HTML page:
request.include('my_component', components_name='dir')
Configuration¶
You can configure djed.static via your ini-file:
[app:myapp]
djed.static.components_path = myapp:static/bower_components
...
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 and second part of your static components URLs:
- djed.static.publisher_signature
The first part of all static components URLs.
default:
bowerstatic
- djed.static.components_name
The name for the components collection (second part of the static URL).
default:
components
- djed.static.components_path
The path or asset specification to the
bower_components
directory.default:
None
API Documentation¶
Support and Development¶
If you’ve got questions, contact the djedproject mailling list.
To report bugs, use the issue tracker.
Check out latest version via the Github repository:
git clone git@github.com:djedproject/djed.static.git
Changes¶
0.6 (unreleased)¶
- No changes yet.
0.5 (2015-10-06)¶
- Support Python 3.5
- It’s now possible to create local components before a
bower_components
directory has been defined. - Backward incompatible change: Remove
version
argument ofconfig.add_bower_component
(version information from thebower.json
file is used instead). - Backward incompatible change: Rename keyword argument identifier
name
ofconfig.add_bower_components
andrequest.include
tocomponents_name
. - Add checks if components directory exists and if local components contain a
bower.json
file.
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