From 993d8ec69bd0784b650c7c48041e93f725548a60 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 28 Nov 2021 20:56:25 +0000 Subject: [PATCH] comments and pygments fix --- flaskpages/__init__.py | 2 ++ flaskpages/pages.py | 19 +++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/flaskpages/__init__.py b/flaskpages/__init__.py index 85eb9c2..7e8d6a0 100644 --- a/flaskpages/__init__.py +++ b/flaskpages/__init__.py @@ -3,6 +3,7 @@ import os from flask import Flask from flaskpages import pages import logging +from flask_flatpages import pygments_style_defs def create_app(test_config=None): """Create and configure an instance of the Flask application.""" app = Flask(__name__, instance_relative_config=True) @@ -24,6 +25,7 @@ def create_app(test_config=None): os.makedirs(app.instance_path) except OSError: pass + if app.config["DEBUG"]: app.logger.setLevel(logging.DEBUG) @app.route("/hello") diff --git a/flaskpages/pages.py b/flaskpages/pages.py index d744d63..e0834e7 100644 --- a/flaskpages/pages.py +++ b/flaskpages/pages.py @@ -4,19 +4,19 @@ from flatpages_index import FlatPagesIndex import flatpages_index import os def create_bp(app): - - flatpages = FlatPagesIndex(app) - flatpages_index.Links.endpoint="pages.page" - flatpages_index.Links.url=(lambda s,x: url_for(s.endpoint, name=x)) + """Create Blueprint to register with Flask""" + flatpages = FlatPagesIndex(app) # Init with the Flask App as argument + flatpages_index.Links.endpoint="pages.page" #set the name of the endpoint for Links to pages + flatpages_index.Links.url=(lambda s,x: url_for(s.endpoint, name=x)) # shorthand expects a function that creates urls for pages #flatpages_index.Links.image_url=(lambda s,x: url_for('stuff.page', name=x)) - flatpages_index.Links.file_url=(lambda s,x: url_for('pages.page', name=x)) - flatpages_index.Links.thumb_url=(lambda s,x: url_for('pages.thumb', size=128,name=x)) + flatpages_index.Links.file_url=(lambda s,x: url_for('pages.page', name=x)) # shorthand to create a link to a file + flatpages_index.Links.thumb_url=(lambda s,x: url_for('pages.thumb', size=128,name=x)) # shorthand for thumbnails that may be used with pictures - flatpages.get('index') + flatpages.get('index') # this ensures, that the pages are loaded app.logger.debug('flatpages loaded %d pages' % len(flatpages._pages)) app.logger.debug("Data directory is: %s" % flatpages.root) - page_blueprint = Blueprint('pages', __name__) + page_blueprint = Blueprint('pages', __name__) @page_blueprint.route('/thumb//') def thumb(size=64,name=''): pass @@ -24,6 +24,7 @@ def create_bp(app): @page_blueprint.route('//') @page_blueprint.route('/') def page(name='index'): + """This is the main endpoint of the application for all flatpages""" page = flatpages.get(name) if page: @@ -38,8 +39,6 @@ def create_bp(app): return send_from_directory('static',name) - - @page_blueprint.route('/.json',strict_slashes=False) def pagejson(name='index'): page = flatpages.get(name)