Passed
Push — master ( ee130d...7ca39f )
by Jochen
02:25
created

byceps.blueprints.snippet.views.url_for_snippet()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
"""
2
byceps.blueprints.snippet.views
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2019 Jochen Kupperschmidt
6
:License: Modified BSD, see LICENSE for details.
7
"""
8
9
from flask import abort, g
10
11
from ...services.snippet import mountpoint_service
12
from ...util.framework.blueprint import create_blueprint
13
14
from .templating import (
15
    render_snippet_as_page,
16
    render_snippet_as_partial,
17
    url_for_snippet,
18
)
19
20
21
blueprint = create_blueprint('snippet', __name__)
22
23
blueprint.add_app_template_global(render_snippet_as_partial, 'render_snippet')
24
blueprint.add_app_template_global(url_for_snippet)
25
26
27
def view_current_version_by_name(name):
28
    """Show the current version of the snippet that is mounted with that
29
    name.
30
    """
31
    # Note: endpoint suffix != snippet name
32
    version = mountpoint_service.find_current_snippet_version_for_mountpoint(
33
        g.site_id, name
34
    )
35
36
    if version is None:
37
        abort(404)
38
39
    return render_snippet_as_page(version)
40