Permalink
Browse files

Merge branch 'master' of https://github.com/redouane/Flask-FlatPages

  • Loading branch information...
2 parents 2c16519 + c728a4c commit 65398a61266608dd71a03baa250de22a4e9d769c @SimonSapin SimonSapin committed Jul 1, 2012
Showing with 39 additions and 13 deletions.
  1. +21 −9 docs/index.rst
  2. +18 −4 flaskext/flatpages/__init__.py
View
@@ -28,11 +28,23 @@ after configuring the application::
from flask import Flask
from flaskext.flatpages import FlatPages
-
+
app = Flask(__name__)
app.config.from_pyfile('mysettings.cfg')
pages = FlatPages(app)
+you can also pass the Flask application object later, by calling
+:meth:`.FlatPages.init_app`.::
+
+ pages = FlatPages()
+
+ def create_app(config='mysettings.cfg'):
+ app = Flask(__name__)
+ app.config.from_pyfile(config)
+ pages.init_app(app)
+ return app
+
+
Flask-FlatPages accepts the following configuration values. All of them
are optional.
@@ -76,9 +88,9 @@ page body::
title: Hello
published: 2010-12-22
-
+
Hello, *World*!
-
+
Lorem ipsum dolor sit amet, …
The body format defaults to `Markdown`_ with `Pygments`_ baked in if available,
@@ -145,7 +157,7 @@ API
Example usage::
pages = FlatPages(app)
-
+
@app.route('/')
def index():
# Articles are pages with a publication date
@@ -169,13 +181,13 @@ API
# hello.html
title: Hello
published: 2010-12-22
-
+
Hello, *World*!
-
+
Lorem ipsum dolor sit amet, …
-
+
::
-
+
>>> page = pages.get('hello')
>>> page.meta # PyYAML converts YYYY-MM-DD to a date object
{'title': u'Hello', 'published': datetime.date(2010, 12, 22)}
@@ -188,7 +200,7 @@ API
.. automethod:: __getitem__
.. automethod:: __html__
-
+
.. autofunction:: pygmented_markdown
.. autofunction:: pygments_style_defs
@@ -105,16 +105,30 @@ class FlatPages(object):
:param app: your application
:type app: Flask instance
"""
- def __init__(self, app):
+ def __init__(self, app=None):
+
+ #: dict of filename: (page object, mtime when loaded)
+ self._file_cache = {}
+
+ if app:
+ self.init_app(app)
+
+
+ def init_app(self, app):
+ """ Used to initialize an application, useful for
+ passing an app later and app factory patterns.
+
+ :param app: your application
+ :type app: Flask instance
+ """
+
app.config.setdefault('FLATPAGES_ROOT', 'pages')
app.config.setdefault('FLATPAGES_EXTENSION', '.html')
app.config.setdefault('FLATPAGES_ENCODING', 'utf8')
app.config.setdefault('FLATPAGES_HTML_RENDERER', pygmented_markdown)
app.config.setdefault('FLATPAGES_AUTO_RELOAD', 'if debug')
- self.app = app
- #: dict of filename: (page object, mtime when loaded)
- self._file_cache = {}
+ self.app = app
app.before_request(self._conditional_auto_reset)

0 comments on commit 65398a6

Please sign in to comment.