<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
u"""The Salzburg Python User Group’s website.

This module contains the entire Salzburg Python User Group’s website as a WSGI
application built on Flask.  It works on both Python 2 and Python 3.  Running
it as a standalone script launches the Flask development web server via the
Flask-Script extension.

Usage:
  * salzpug.py runserver [-h <host>] [-p <port>] [-d] [-r]
  * salzpug.py shell
  * salzpug.py --help

Options:
  -h <host>  the hostname to listen on (default: 127.0.0.1)
  -p <port>  the port of the web server (default: 5000)
  -d         use the Werkzeug debugger
  -r         reload the web server if the script changes

This module dependes on the following packages:

* Flask
* Flask-FlatPages
* Flask-Script (if run as a standalone script)

Run ``pip install -r requirements.txt`` to install all dependencies.
"""

from flask import Flask, render_template
from flask_flatpages import FlatPages


# Configuration
# =============

class Config(object):
    u"""The default configuration for the Flask application.

    Only uppercase variables in this class will be stored in the configuration
    object.
    """

    # Flask-FlatPages configuration
    FLATPAGES_AUTO_RELOAD = False
    FLATPAGES_EXTENSION = '.md'


# Application setup
# =================

application = app = Flask(__name__)
app.config.from_object(Config)
pages = FlatPages(app)


# View functions
# ==============

@app.route('/<path:path>/')
def show_page(path):
    u"""Render a static page from the FlatPages collection.

    :param path: the path to the requested page, relative to
                 ``FLATPAGES_ROOT``.
    :raises: :class:`~werkzeug.exceptions.NotFound` if there is no page at the
             given path.
    """
    return render_template('page.xhtml', page=pages.get_or_404(path))
<commit_msg>Allow to embed Jinja within static pages’ markdown<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
u"""The Salzburg Python User Group’s website.

This module contains the entire Salzburg Python User Group’s website as a WSGI
application built on Flask.  It works on both Python 2 and Python 3.  Running
it as a standalone script launches the Flask development web server via the
Flask-Script extension.

Usage:
  * salzpug.py runserver [-h <host>] [-p <port>] [-d] [-r]
  * salzpug.py shell
  * salzpug.py --help

Options:
  -h <host>  the hostname to listen on (default: 127.0.0.1)
  -p <port>  the port of the web server (default: 5000)
  -d         use the Werkzeug debugger
  -r         reload the web server if the script changes

This module dependes on the following packages:

* Flask
* Flask-FlatPages
* Flask-Script (if run as a standalone script)

Run ``pip install -r requirements.txt`` to install all dependencies.
"""

from flask import Flask, render_template, render_template_string
from flask_flatpages import FlatPages, pygmented_markdown
from markupsafe import Markup


# Configuration
# =============

class Config(object):
    u"""The default configuration for the Flask application.

    Only uppercase variables in this class will be stored in the configuration
    object.
    """

    @staticmethod
    def prerender_jinja(text):
        u"""Render Markdown with Jinja directives to HTML.

        Use this function to configure ``FLATPAGES_HTML_RENDERER``, to support
        evaluating Jinja directives embedded within the Markdown document.
        """
        prerendered_body = render_template_string(Markup(text))
        return pygmented_markdown(prerendered_body)

    # Flask-FlatPages configuration
    FLATPAGES_AUTO_RELOAD = False
    FLATPAGES_EXTENSION = '.md'
    FLATPAGES_HTML_RENDERER = prerender_jinja


# Application setup
# =================

application = app = Flask(__name__)
app.config.from_object(Config)
pages = FlatPages(app)


# View functions
# ==============

@app.route('/<path:path>/')
def show_page(path):
    u"""Render a static page from the FlatPages collection.

    :param path: the path to the requested page, relative to
                 ``FLATPAGES_ROOT``.
    :raises: :class:`~werkzeug.exceptions.NotFound` if there is no page at the
             given path.
    """
    return render_template('page.xhtml', page=pages.get_or_404(path))

{'fraction_non_alphanumeric': 0.10786831660051366, 'fraction_numerical': 0.007471398552416531, 'mean_word_length': 3.533333333333333, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4954043', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1266, 'n_words': 461}