changeset 10:8b5615a1bf3d

articles, input: use new embedding mechanism in articles + new macros to build forms and inputs
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 01:07:28 +0200
parents 7a1626e78d53
children 6f13b25f1ecf
files default/blog/articles.html default/input/comment.html default/input/comments.html default/input/field.html default/input/form.html
diffstat 5 files changed, 54 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/default/blog/articles.html	Thu Apr 27 01:05:16 2017 +0200
+++ b/default/blog/articles.html	Thu Apr 27 01:07:28 2017 +0200
@@ -1,22 +1,26 @@
-{% extends 'base/base.html' %}
-{% import 'input/comments.html' as comments %}
-
+{% if not embedded %}{% extends 'base/base.html' %}{% endif %}
+{% import 'input/comment.html' as comment %}
 
 {% macro show_items(items) %}
     {# show items and comments items if present after each item,
        then post form if allow_commenting is set #}
     {% for item in items %}
         {% include 'blog/item.html' %}
+
         {% for comments_items in item.comments_items_list %}
+
             {% if allow_commenting %}
                 <div id="comment_post">
-                    {{ comments.comment(service=comments_items.service, node=comments_items.node) }}
+                    {{ comment.comment(service=comments_items.service, node=comments_items.node) }}
                 </div>
             {% endif %}
+
             <div class="comments">
                 {{show_items(comments_items)}}
             </div>
+
         {% endfor %}
+
     {% endfor %}
 {% endmacro %}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/default/input/comment.html	Thu Apr 27 01:07:28 2017 +0200
@@ -0,0 +1,24 @@
+{% import 'input/form.html' as form %}
+
+{% macro head(service, node) %}
+    {# include data needed to identify the node to use for commenting #}
+    <input type="hidden" name="type" value="comment">
+    <input type="hidden" name="service" value="{{service}}">
+    <input type="hidden" name="node" value="{{node}}">
+{% endmacro %}
+
+{% macro body(rows=10, cols=50) %}
+    <textarea name="body" rows="{{rows}}" cols="{{cols}}"></textarea>
+{% endmacro %}
+
+{% macro submit() %}
+    <input type="submit" value="Send">
+{% endmacro %}
+
+{% macro comment(service, node, action='') %}
+{% call form.form(action=action) %}
+    {{ head(service, node) }}
+    {{ body() }}
+    {{ submit() }}
+{% endcall %}
+{% endmacro %}
--- a/default/input/comments.html	Thu Apr 27 01:05:16 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-{% macro comment(service, node, action='') %}
-<form method="post" action="{{action}}">
-    <input type="hidden" name="service" value="{{service}}">
-    <input type="hidden" name="node" value="{{node}}">
-    <textarea name="body" rows="10" cols="50"></textarea>
-    <input type="submit" value="Send">
-</form>
-{% endmacro %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/default/input/field.html	Thu Apr 27 01:07:28 2017 +0200
@@ -0,0 +1,17 @@
+{% macro choices(name, choices_list, checked=none) %}
+    {% for choice in choices_list %}
+        <label><input type="radio" name="{{name}}" value="{{choice}}"{{"checked" if checked==choice}}>{{choice}}</label>
+    {% endfor %}
+{% endmacro %}
+
+{% macro int(name, label="", init=0) %}
+    <label><input type="number" name="{{name}}" value="{{init}}" step="1" min="0">{{label}}</label>
+{% endmacro %}
+
+{% macro meta(name, value) %}
+    <input type="hidden" name="{{name}}" value="{{value}}">
+{% endmacro %}
+
+{% macro submit() %}
+    <input type="submit" value="Send">
+{% endmacro %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/default/input/form.html	Thu Apr 27 01:07:28 2017 +0200
@@ -0,0 +1,5 @@
+{% macro form(action='') %}
+<form method="post" action="{{action}}">
+    {{ caller() }}
+</form>
+{% endmacro %}