summaryrefslogtreecommitdiff
path: root/sw/templates
diff options
context:
space:
mode:
authorTom Harley2021-07-30 18:35:08 +0000
committerTom Harley2021-07-30 18:35:08 +0000
commitc77d6a4d4a1d628788be73491aa7fa4e4fdcff05 (patch)
tree90f92c373b085818243835c323fa6e1884854ce9 /sw/templates
parentAdd more inbox/outbox tests (diff)
downloadswap-c77d6a4d4a1d628788be73491aa7fa4e4fdcff05.tar.gz
swap-c77d6a4d4a1d628788be73491aa7fa4e4fdcff05.zip

Add templates

Rather than using jsonify on a dict, the system now uses render_template on json documents. This gives the ability to extend previous files (which might be useful for activitypub features), and also enables using different templates for different filetypes.

Supplied are templates for accessing inboxes and outboxes in JSON-LD and HTML.

The “items” field in get_user_inbox_page.json and get_user_outbox_page.json might be currently borked.

Diffstat (limited to 'sw/templates')
-rw-r--r--sw/templates/base.html20
-rw-r--r--sw/templates/base.json4
-rw-r--r--sw/templates/get_user_inbox.html11
-rw-r--r--sw/templates/get_user_inbox.json11
-rw-r--r--sw/templates/get_user_inbox_page.html13
-rw-r--r--sw/templates/get_user_inbox_page.json16
-rw-r--r--sw/templates/get_user_outbox.html11
-rw-r--r--sw/templates/get_user_outbox.json9
-rw-r--r--sw/templates/get_user_outbox_page.html13
-rw-r--r--sw/templates/get_user_outbox_page.json16
-rw-r--r--sw/templates/index.html9
-rw-r--r--sw/templates/user_info.html13
-rw-r--r--sw/templates/user_info.json11
13 files changed, 157 insertions, 0 deletions
diff --git a/sw/templates/base.html b/sw/templates/base.html
new file mode 100644
index 0000000..4f2acf1
--- /dev/null
+++ b/sw/templates/base.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<title>{% block title %}{% endblock %}</title>
+<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
+<nav>
+ <ul>
+ {% if g.user %}
+ <li><span>{{ g.user['username'] }}</span></li>
+ <li><a href="{{ url_for('auth.logout') }}">Log Out</a></li>
+ {% else %}
+ <li><a href="{{ url_for('auth.register') }}">Register</a></li>
+ <li><a href="{{ url_for('auth.login') }}">Log In</a></li>
+ {% endif %}
+ </ul>
+</nav>
+<section class="content">
+ <header>
+ {% block header %}{% endblock %}
+ </header>
+ {% block content %}{% endblock %}
+</section>
diff --git a/sw/templates/base.json b/sw/templates/base.json
new file mode 100644
index 0000000..e0a0876
--- /dev/null
+++ b/sw/templates/base.json
@@ -0,0 +1,4 @@
+{
+{% block content %}{% endblock %}
+"@context": "https://www.w3.org/ns/activitystreams"
+}
diff --git a/sw/templates/get_user_inbox.html b/sw/templates/get_user_inbox.html
new file mode 100644
index 0000000..7956a21
--- /dev/null
+++ b/sw/templates/get_user_inbox.html
@@ -0,0 +1,11 @@
+{% extends "base.html" %}
+
+{% block header %}
+<h1>{% block title %}{{ user["username"] }}'s Inbox }}{% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+<p>{{ user["inbox_size"] }} items</p>
+<p><a href="{{ url_for('.get_user_inbox_page', username=user['username']) }}">First page</a></p>
+<p><a href="{{ url_for('.get_user_inbox_page', username=user['username'], min_id=1) }}">Last page</a></p>
+{% endblock %}
diff --git a/sw/templates/get_user_inbox.json b/sw/templates/get_user_inbox.json
new file mode 100644
index 0000000..c186fae
--- /dev/null
+++ b/sw/templates/get_user_inbox.json
@@ -0,0 +1,11 @@
+{% extends "base.json" %}
+
+{% block content %}
+"type": "OrderedCollection",
+
+"id": "{{ url_for('.get_user_inbox', username=user['username']) }}",
+
+"totalItems": {{ user['inbox_size'] }},
+"first": "{{ url_for('.get_user_inbox_page', username=user['username']) }}",
+"last": "{{ url_for('.get_user_inbox_page', username=user['username'], min_id=1) }}",
+{% endblock %}
diff --git a/sw/templates/get_user_inbox_page.html b/sw/templates/get_user_inbox_page.html
new file mode 100644
index 0000000..a331049
--- /dev/null
+++ b/sw/templates/get_user_inbox_page.html
@@ -0,0 +1,13 @@
+{% extends "base.html" %}
+
+{% block header %}
+<h1>{% block title %}{{ user["username"] }}'s Inbox {% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+<ul>
+{% for item in items %}
+<li value="{{ items['id'] }}">{{ item }}</li>
+{% endfor %}
+</ul>
+{% endblock %}
diff --git a/sw/templates/get_user_inbox_page.json b/sw/templates/get_user_inbox_page.json
new file mode 100644
index 0000000..50a9f06
--- /dev/null
+++ b/sw/templates/get_user_inbox_page.json
@@ -0,0 +1,16 @@
+{% extends "base.json" %}
+
+{% block content %}
+"type": "OrderedCollectionPage",
+
+"id": "{{ url_for('.get_user_inbox_page', username=user['username'], max_id=max_id) }}",
+
+{% if items %}
+"next": "{{ url_for('.get_user_inbox_page', username=user['username'], max_id=(min_id-1)) }}",
+"prev": "{{ url_for('.get_user_inbox_page', username=user['username'], min_id=(max_id+1)) }}",
+{% endif %}
+"current": "{{ url_for('.get_user_inbox_page', username=user['username']) }}",
+"partOf": "{{ url_for('.get_user_inbox', username=user['username']) }}",
+
+"items": {{ items }},
+{% endblock %}
diff --git a/sw/templates/get_user_outbox.html b/sw/templates/get_user_outbox.html
new file mode 100644
index 0000000..9f4d893
--- /dev/null
+++ b/sw/templates/get_user_outbox.html
@@ -0,0 +1,11 @@
+{% extends "base.html" %}
+
+{% block header %}
+<h1>{% block title %}{{ user["username"] }}'s Outbox }}{% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+<p>{{ user["outbox_size"] }} items</p>
+<p><a href="{{ url_for('.get_user_outbox_page', username=user['username']) }}">First page</a></p>
+<p><a href="{{ url_for('.get_user_outbox_page', username=user['username'], min_id=1) }}">Last page</a></p>
+{% endblock %}
diff --git a/sw/templates/get_user_outbox.json b/sw/templates/get_user_outbox.json
new file mode 100644
index 0000000..ce2fad4
--- /dev/null
+++ b/sw/templates/get_user_outbox.json
@@ -0,0 +1,9 @@
+{% extends "base.json" %}
+
+{% block content %}
+"id": "{{ url_for('.get_user_inbox', username=user['username']) }}",
+"type": "OrderedCollection",
+
+"totalItems": "{{ user['outbox_size'] }}",
+"first": "{{ url_for('.get_user_outbox_page', username=user['username']) }}",
+{% endblock %}
diff --git a/sw/templates/get_user_outbox_page.html b/sw/templates/get_user_outbox_page.html
new file mode 100644
index 0000000..2907604
--- /dev/null
+++ b/sw/templates/get_user_outbox_page.html
@@ -0,0 +1,13 @@
+{% extends "base.html" %}
+
+{% block header %}
+<h1>{% block title %}{{ user["username"] }}'s Outbox {% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+<ul>
+{% for item in items %}
+<li value="{{ item['id'] }}">{{ item }}</li>
+{% endfor %}
+</ul>
+{% endblock %}
diff --git a/sw/templates/get_user_outbox_page.json b/sw/templates/get_user_outbox_page.json
new file mode 100644
index 0000000..b25a5ce
--- /dev/null
+++ b/sw/templates/get_user_outbox_page.json
@@ -0,0 +1,16 @@
+{% extends "base.json" %}
+
+{% block content %}
+"type": "OrderedCollecdtionPage",
+
+"id": "{{ url_for('.get_user_outbox_page', username=user['username'], max_id=max_id) }}",
+
+{% if items %}
+"next": "{{ url_for('.get_user_outbox_page', username=user['username'], max_id=(min_id-1)) }}",
+"prev": "{{ url_for('.get_user_outbox_page', username=user['username'], min_id=(max_id+1)) }}",
+{% endif %}
+"current": "{{ url_for('.get_user_outbox_page', username=user['username']) }}",
+"partOf": "{{ url_for('.get_user_outbox', username=user['username']) }}",
+
+"items": {{ items }},
+{% endblock %}
diff --git a/sw/templates/index.html b/sw/templates/index.html
new file mode 100644
index 0000000..12e9e79
--- /dev/null
+++ b/sw/templates/index.html
@@ -0,0 +1,9 @@
+{% extends "base.html" %}
+
+{% block header %}
+<h1>{% block title %}Register{% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+Hello, World!
+{% endblock %}
diff --git a/sw/templates/user_info.html b/sw/templates/user_info.html
new file mode 100644
index 0000000..96c3d2f
--- /dev/null
+++ b/sw/templates/user_info.html
@@ -0,0 +1,13 @@
+{% extends "base.html" %}
+
+{% block header %}
+<h1>{% block title %}User {{ user["username"] }}{% endblock %}</h1>
+{% endblock %}
+
+{% block content %}
+<p>username: {{ user["username"] }}</p>
+<p>user ID: {{ user["id"] }}</p>
+<p>no. of posts: {{ user["outbox_size"] }}</p>
+<br>
+<p>inbox: <a href="{{ url_for('users.get_user_inbox', username=user["username"]) }}">{{ url_for('users.get_user_inbox', username=user["username"]) }}</a></p>
+{% endblock %}
diff --git a/sw/templates/user_info.json b/sw/templates/user_info.json
new file mode 100644
index 0000000..a14d6bc
--- /dev/null
+++ b/sw/templates/user_info.json
@@ -0,0 +1,11 @@
+{% extends "base.json" %}
+
+{% block content %}
+"type": "Actor",
+
+"name": "{{ user['username'] }}",
+"id": "{{ url_for('users.get_user_info', username=user['username']) }}",
+
+"inbox": "{{ url_for('users.get_user_inbox', username=user['username']) }}",
+"outbox": "{{ url_for('users.get_user_outbox', username=user['username']) }}",
+{% endblock %}