Skip to content

Commit

Permalink
Merge pull request #54 from camptocamp/more-information
Browse files Browse the repository at this point in the history
Add some information from the spec YAML
  • Loading branch information
sbrunner authored Oct 5, 2023
2 parents 9bf9136 + 633ada9 commit f53081a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
Binary file modified acceptance_tests/tests/collections-dark.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified acceptance_tests/tests/collections-light.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified acceptance_tests/tests/conformance-dark.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified acceptance_tests/tests/conformance-light.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions acceptance_tests/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def test_api(test_app, accept, f_param, expected):
"path,width,height,expected",
[
("", 500, 500, "ogcapi"),
("conformance", 800, 150, "conformance"),
("collections", 550, 700, "collections"),
("conformance", 800, 300, "conformance"),
("collections", 550, 750, "collections"),
],
)
@pytest.mark.parametrize("prefers_color_scheme", ["light", "dark"])
Expand Down
3 changes: 3 additions & 0 deletions pyramid_ogcapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def resolve_ref(obj: Any, spec: dict[str, Any], path) -> None:
resolve_ref(spec["paths"], spec, [])

helps: list[str] = []
view_path = config.registry.settings.setdefault("pyramid_ogcapi", {}).setdefault("view_path", {})
for pattern, path_config in spec.get("paths", {}).items():
route_name = path2route_name_prefix(pattern, route_prefix)

Expand All @@ -242,6 +243,7 @@ def resolve_ref(obj: Any, spec: dict[str, Any], path) -> None:
renderer=path_template.get(pattern, "pyramid_ogcapi:templates/default.mako"),
openapi=True,
)
view_path[f"{route_name}_html"] = path_config
config.add_route(
f"{route_name}_json",
pattern,
Expand All @@ -254,6 +256,7 @@ def resolve_ref(obj: Any, spec: dict[str, Any], path) -> None:
renderer=json_renderer,
openapi=True,
)
view_path[f"{route_name}_json"] = path_config

method_route_name = f"{route_name}_{method}" if method != "get" else route_name

Expand Down
31 changes: 23 additions & 8 deletions pyramid_ogcapi/templates/default.mako
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<%
import logging
_LOGGER = logging.getLogger(__name__)
path_spec = request.registry.settings.get("pyramid_ogcapi", {}).get("view_path", {}).get(request.matched_route.name)
path_spec_get = path_spec.get('get', {})
title_ = context['title'] if "title" in context.keys() else ''
if not title_ and 'summary' in path_spec_get:
title_ = path_spec_get['summary']
description_ = context['description'] if "description" in context.keys() else ''
if not description_ and 'description' in path_spec_get:
description_ = path_spec_get['description']
%>
<!DOCTYPE html>
<html>
<head>
Expand All @@ -24,11 +39,11 @@
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
%if "title" in context.keys():
<title>${ title }</title>
%if title_:
<title>${ title_ }</title>
%endif
%if "description" in context.keys():
<meta name="description" content="${ description }">
%if description_:
<meta name="description" content="${ description_ }">
%endif
<style>
th {
Expand All @@ -51,11 +66,11 @@
})()
</script>
<div class="container-fluid">
%if "title" in context.keys():
<h1>${ title }</h1>
%if title_:
<h1>${ title_ }</h1>
%endif
%if "description" in context.keys():
<p>${ description }</p>
%if description_:
<p>${ description_ }</p>
%endif

<%
Expand Down

0 comments on commit f53081a

Please sign in to comment.