Browse Source

More docstrings for blueprints.

pull/262/head
Armin Ronacher 14 years ago
parent
commit
86175054d6
  1. 9
      docs/api.rst
  2. 4
      docs/patterns/appfactories.rst
  3. 3
      docs/quickstart.rst
  4. 35
      flask/blueprints.py

9
docs/api.rst

@ -18,10 +18,10 @@ Application Object
:inherited-members: :inherited-members:
Module Objects Blueprint Objects
-------------- -----------------
.. autoclass:: Module .. autoclass:: Blueprint
:members: :members:
:inherited-members: :inherited-members:
@ -350,6 +350,9 @@ Useful Internals
if ctx is not None: if ctx is not None:
return ctx.session return ctx.session
.. autoclass:: flask.blueprints.BlueprintSetupState
:members:
Signals Signals
------- -------

4
docs/patterns/appfactories.rst

@ -3,8 +3,8 @@
Application Factories Application Factories
===================== =====================
If you are already using packages and modules for your application If you are already using packages and blueprints for your application
(:ref:`packages`) there are a couple of really nice ways to further improve (:ref:`blueprints`) there are a couple of really nice ways to further improve
the experience. A common pattern is creating the application object when the experience. A common pattern is creating the application object when
the module is imported. But if you move the creation of this object, the module is imported. But if you move the creation of this object,
into a function, you can then create multiple instances of this and later. into a function, you can then create multiple instances of this and later.

3
docs/quickstart.rst

@ -381,8 +381,7 @@ package it's actually inside your package:
/hello.html /hello.html
For templates you can use the full power of Jinja2 templates. Head over For templates you can use the full power of Jinja2 templates. Head over
to the :ref:`templating` section of the documentation or the official to the the official `Jinja2 Template Documentation
`Jinja2 Template Documentation
<http://jinja.pocoo.org/2/documentation/templates>`_ for more information. <http://jinja.pocoo.org/2/documentation/templates>`_ for more information.
Here is an example template: Here is an example template:

35
flask/blueprints.py

@ -16,25 +16,46 @@ from .helpers import _PackageBoundObject, _endpoint_from_view_func
class BlueprintSetupState(object): class BlueprintSetupState(object):
"""Temporary holder object for registering a blueprint with the """Temporary holder object for registering a blueprint with the
application. application. An instance of this class is created by the
:meth:`~flask.Blueprint.make_setup_state` method and later passed
to all register callback functions.
""" """
def __init__(self, blueprint, app, options, first_registration): def __init__(self, blueprint, app, options, first_registration):
#: a reference to the current application
self.app = app self.app = app
#: a reference to the blurprint that created this setup state.
self.blueprint = blueprint self.blueprint = blueprint
#: a dictionary with all options that were passed to the
#: :meth:`~flask.Flask.register_blueprint` method.
self.options = options self.options = options
#: as blueprints can be registered multiple times with the
#: application and not everything wants to be registered
#: multiple times on it, this attribute can be used to figure
#: out if the blueprint was registered in the past already.
self.first_registration = first_registration self.first_registration = first_registration
subdomain = self.options.get('subdomain') subdomain = self.options.get('subdomain')
if subdomain is None: if subdomain is None:
subdomain = self.blueprint.subdomain subdomain = self.blueprint.subdomain
#: The subdomain that the blueprint should be active for, `None`
#: otherwise.
self.subdomain = subdomain self.subdomain = subdomain
url_prefix = self.options.get('url_prefix') url_prefix = self.options.get('url_prefix')
if url_prefix is None: if url_prefix is None:
url_prefix = self.blueprint.url_prefix url_prefix = self.blueprint.url_prefix
#: The prefix that should be used for all URLs defined on the
#: blueprint.
self.url_prefix = url_prefix self.url_prefix = url_prefix
#: A dictionary with URL defaults that is added to each and every
#: URL that was defined with the blueprint.
self.url_defaults = dict(self.blueprint.url_defaults) self.url_defaults = dict(self.blueprint.url_defaults)
self.url_defaults.update(self.options.get('url_defaults', ())) self.url_defaults.update(self.options.get('url_defaults', ()))
@ -56,7 +77,11 @@ class BlueprintSetupState(object):
class Blueprint(_PackageBoundObject): class Blueprint(_PackageBoundObject):
"""Represents a blueprint. """Represents a blueprint. A blueprint is an object that records
functions that will be called with the
:class:`~flask.blueprint.BlueprintSetupState` later to register functions
or other things on the main application. See :ref:`blueprints` for more
information.
.. versionadded:: 0.7 .. versionadded:: 0.7
""" """
@ -104,6 +129,10 @@ class Blueprint(_PackageBoundObject):
return self.record(update_wrapper(wrapper, func)) return self.record(update_wrapper(wrapper, func))
def make_setup_state(self, app, options, first_registration=False): def make_setup_state(self, app, options, first_registration=False):
"""Creates an instance of :meth:`~flask.blueprints.BlueprintSetupState`
object that is later passed to the register callback functions.
Subclasses can override this to return a subclass of the setup state.
"""
return BlueprintSetupState(self, app, options, first_registration) return BlueprintSetupState(self, app, options, first_registration)
def register(self, app, options, first_registration=False): def register(self, app, options, first_registration=False):
@ -254,8 +283,6 @@ class Blueprint(_PackageBoundObject):
Otherwise works as the :meth:`~flask.Flask.errorhandler` decorator Otherwise works as the :meth:`~flask.Flask.errorhandler` decorator
of the :class:`~flask.Flask` object. of the :class:`~flask.Flask` object.
.. versionadded:: 0.7
""" """
def decorator(f): def decorator(f):
self.record_once(lambda s: s.app._register_error_handler( self.record_once(lambda s: s.app._register_error_handler(

Loading…
Cancel
Save