micawber exposes two Jinja template filters for use in your flask templates:
You can add them to your jinja environment by using the helper function:
from flask import Flask
from micawber.providers import bootstrap_basic
from micawber.contrib.mcflask import add_oembed_filters
app = Flask(__name__)
oembed_providers = bootstrap_basic()
add_oembed_filters(app, oembed_providers)
Now you can use the filters in your templates:
{% block content %}
<p>{{ object.body|oembed(html=False, maxwidth=600, maxheight=600) }}</p>
{% endblock %}
The following filters are exposed via the micawber.contrib.mcflask module:
Parse the given text, rendering URLs as rich media
Usage within a Jinja2 template:
{{ blog_entry.body|oembed(urlize_all=False, maxwidth=600) }}
| Parameters: |
|
|---|---|
| Return type: | parsed text with rich content embedded |
Returns a 2-tuple containing
Note
Not all URLs listed will have matching entries in the dictionary, since there may not be a provider for them.
| Parameters: |
|
|---|---|
| Return type: | 2-tuple containing a list of all urls and a dictionary of url -> metadata |
To actually use these filters they must be made available to the application. Use the following function to do this sometime after initializing your Flask app:
Add the oembed and extract_oembed filters to the jinja environment
| Parameters: |
|
|---|---|
| Return type: | (no return value) |