Skip to content

Commit

Permalink
feat: add injected devtools for console logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Sep 3, 2024
1 parent c789c78 commit 6e77fe7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions piggy/templates/assignments/5-assignment.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ <h1 class="text-2xl">{{ content.heading }}</h1>
<a href="/">Home</a>
</header>
<main>{{ content.body | safe }}</main>

{% if debug %}
{% include "partials/devtools/_devtools.html" %}
{% endif %}
</body>
4 changes: 4 additions & 0 deletions piggy/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
{% endblock %}
</footer>
</body>

{% if debug %}
{% include "partials/devtools/_devtools.html" %}
{% endif %}
</html>
1 change: 1 addition & 0 deletions piggy/templates/partials/devtools/_devtools.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include "partials/devtools/log_variables.html" %}
54 changes: 54 additions & 0 deletions piggy/templates/partials/devtools/log_variables.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script>
console.log("GLOBAL CONTEXT VARIABLES");
console.log("---");
console.log("media_abspath: " + JSON.stringify({{ media_abspath | string | tojson }}));
console.log("abspath: " + JSON.stringify({{ abspath | string | tojson }}));
console.log("path: " + JSON.stringify({{ path | string | tojson }}));
console.log("ASSIGNMENT_URL_PREFIX: " + JSON.stringify({{ ASSIGNMENT_URL_PREFIX | string | tojson }}));
console.log("MEDIA_URL_PREFIX: " + JSON.stringify({{ MEDIA_URL_PREFIX | string | tojson }}));
console.log("github_pages: " + JSON.stringify({{ github_pages | string | tojson }}));
console.log("AssignmentTemplate: " + JSON.stringify({{ AssignmentTemplate | string | tojson }}));
console.log("debug: " + JSON.stringify({{ debug | string | tojson }}));

{% if level %}
console.log("");
console.log("ASSIGNMENT SPECIFIC VARIABLES");
console.log("---");
console.log("current_language: " + JSON.stringify({{ current_language | string | tojson }}));
console.log("supported_languages: " + JSON.stringify({{ supported_languages | string | tojson }}));
console.log("level: " + JSON.stringify({{ level | string | tojson }}));
console.log("level_name: " + JSON.stringify({{ level_name | string | tojson }}));
console.log("heading: " + JSON.stringify({{ heading | string | tojson }}));
{% endif %}


{% if meta %}
console.log("");
console.log("META VARIABLES (might be page specific)");
console.log("---");
{% for k, v in meta.items() %}
console.log(JSON.stringify("meta." + {{ k | string | tojson }} + ": " + JSON.stringify({{ v | string | tojson }})));
{% endfor %}
{% endif %}

console.log("");
console.log("JINJA Specific variables");
console.log("---");
console.log("request.path: " + JSON.stringify({{ request.path | string | tojson }}));
console.log("request.url: " + JSON.stringify({{ request.url | string | tojson }}));
console.log("request.endpoint: " + JSON.stringify({{ request.endpoint | string | tojson }}));
console.log("request.full_path: " + JSON.stringify({{ request.full_path | string | tojson }}));
console.log("request.url_root: " + JSON.stringify({{ request.url_root | string | tojson }}));
console.log("request.base_url: " + JSON.stringify({{ request.base_url | string | tojson }}));
console.log("request.host_url: " + JSON.stringify({{ request.host_url | string | tojson }}));

console.log("");
console.log("Cluttered variables that take up too much space");
console.log("---");
console.log("piggymap: " + JSON.stringify({{ piggymap | string | tojson }}));
{% if segment %}
{% for k, v in segment.items() %}
console.log(JSON.stringify("segment." + {{ k | string | tojson }} + ": " + JSON.stringify({{ v | string | tojson }})));
{% endfor %}
{% endif %}
</script>

0 comments on commit 6e77fe7

Please sign in to comment.