Passed
Push — master ( 66dc83...21b344 )
by Jace
03:48
created

_load_readme()   A

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 3
cp 1
crap 2
rs 9.4285
1 1
import random
2
from pathlib import Path
3 1
4
from flask import Blueprint, Markup, render_template, current_app
5 1
from flask_cachecontrol import cache_for
6
from markdown import markdown
7
8 1
from ._utils import samples
9
10
11 1
blueprint = Blueprint('index-page', __name__)
12
13 1
14 1
@blueprint.route("/")
15 1
@cache_for(days=2)
16
def get():
17
    template_images = list(samples(blank=True))
18
    return render_template(
19
        "index.html",
20
        template_images=template_images,
21
        default_template=random.choice(template_images)['key'],
22
        readme=_load_readme(),
23
        config=current_app.config,
24 1
    )
25
26 1
27 1
def _load_readme():
28 1
    path = Path(current_app.config['ROOT'], 'README.md')
29
    with path.open() as f:
30 1
        text = f.read()
31
        content = text.split('<!--content-->')[-1]
32
        html = markdown(content, extensions=['tables', 'pymdownx.magiclink'])
33
        return Markup(html)
34