Kaynağa Gözat

Added the macro subpages

master
Dirk Alders 3 ay önce
ebeveyn
işleme
7f357e9a3a
6 değiştirilmiş dosya ile 58 ekleme ve 35 silme
  1. 1
    1
      mycreole
  2. 0
    27
      pages/creole.py
  3. 6
    1
      pages/help.py
  4. 47
    2
      pages/page.py
  5. 4
    1
      pages/views.py
  6. 0
    3
      piki/settings.py

+ 1
- 1
mycreole

@@ -1 +1 @@
1
-Subproject commit 8a2da2b84379df346d4f24c8fc5c1e6fe62c75e9
1
+Subproject commit 2abea3c4aec4716a2609828faddcd6b6e4c7728e

+ 0
- 27
pages/creole.py Dosyayı Görüntüle

@@ -1,27 +0,0 @@
1
-from django.urls.base import reverse
2
-
3
-# TODO: Add a filter to show all subpages <<piki-subpages>> and add it to settings and help
4
-
5
-
6
-"""
7
-def page_link_filter(text):
8
-    render_txt = ''
9
-    while len(text) > 0:
10
-        try:
11
-            pos = text.index('[[page:')
12
-        except ValueError:
13
-            pos = len(text)
14
-        print(pos)
15
-        render_txt += text[:pos]
16
-        text = text[pos + 7:]
17
-        if len(text):
18
-            pos = text.index(']]')
19
-            try:
20
-                rel_path = int(text[:pos])
21
-            except ValueError:
22
-                render_txt += "[[page:" + text[:pos + 2]
23
-            else:
24
-                render_txt += '[[%s|%s]]' % (reverse('pages-pages', kwargs={'rel_path': rel_path}), rel_path)
25
-            text = text[pos + 2:]
26
-    return render_txt
27
-"""

+ 6
- 1
pages/help.py Dosyayı Görüntüle

@@ -21,7 +21,12 @@ MAIN = mycreole.render_simple(_(
21 21
 CREOLE = mycreole.mycreole_help_pagecontent()
22 22
 CREOLE += mycreole.render_simple("""
23 23
 = Piki Markup
24
-{{{[[rel_path_to_page|Name]]}}} will result in a Link to the given wiki page.
24
+| {{{[[rel_path_to_page|Name]]}}} | will result in a Link to the given wiki page. |
25
+| {{{<<subpages>>}}} | will result in a list of all subpages below the current page. |
26
+| {{{<<subpages=N,startswith>>}}} | will result in a list of subpages below the current page.\
27
+                                    N will reduce the depth of the subpages to N. \
28
+                                    startswith  will reduce the hits to all pages starting with the given string. 
29
+                                    You can give one or both Parameters. |
25 30
 """)
26 31
 
27 32
 ACCESS = mycreole.render_simple(_("""

+ 47
- 2
pages/page.py Dosyayı Görüntüle

@@ -29,9 +29,15 @@ class creol_page(object):
29 29
     def attachment_path(self):
30 30
         return os.path.join(self.content_folder_name, self.FOLDER_ATTACHMENTS)
31 31
 
32
+    def __content_folder_filter__(self, folder):
33
+        return folder.replace('/', '::')
34
+
35
+    def __folder_content_filter__(self, folder):
36
+        return folder.replace('::', '/')
37
+
32 38
     @property
33 39
     def content_folder_name(self):
34
-        return self._rel_path.replace('/', '::')
40
+        return self.__content_folder_filter__(self._rel_path)
35 41
 
36 42
     @property
37 43
     def content_file_name(self):
@@ -54,7 +60,46 @@ class creol_page(object):
54 60
 
55 61
     def render_to_html(self, request):
56 62
         if self.is_available():
57
-            return mycreole.render(request, self.raw_page_src, self.attachment_path, "next_anchor")
63
+            return self.render_text(request, self.raw_page_src)
58 64
         else:
59 65
             messages.unavailable_msg_page(request, self._rel_path)
60 66
             return ""
67
+
68
+    def render_text(self, request, txt):
69
+        macros = {
70
+            "subpages": self.macro_subpages
71
+        }
72
+        return mycreole.render(request, txt, self.attachment_path, "next_anchor", macros=macros)
73
+
74
+    def macro_subpages(self, *args, **kwargs):
75
+        def parse_depth(s: str):
76
+            try:
77
+                return int(s)
78
+            except ValueError:
79
+                pass
80
+
81
+        params = kwargs.get('').split(",")
82
+        depth = parse_depth(params[0])
83
+        if len(params) == 2:
84
+            startname = params[1]
85
+        elif depth is None:
86
+            startname = params[0]
87
+        if depth is None:
88
+            depth = 9999
89
+        #
90
+        rv = ""
91
+        pathlist = fstools.dirlist(settings.PAGES_ROOT, rekursive=False)
92
+        pathlist.sort()
93
+        for path in pathlist:
94
+            dirname = os.path.basename(path)
95
+            contentname = self.__folder_content_filter__(dirname)
96
+            #
97
+            my_dirname = self.__content_folder_filter__(self._rel_path)
98
+            #
99
+            if dirname.startswith(my_dirname) and dirname != my_dirname:
100
+                name = contentname[len(self._rel_path)+1:]
101
+                if name.count('/') <= depth and name.startswith(startname):
102
+                    rv += f'  <li><a href="{contentname}">{name}</a></li>\n'
103
+        if len(rv) > 0:
104
+            rv = "<ul>\n" + rv + "</ul>\n"
105
+        return rv

+ 4
- 1
pages/views.py Dosyayı Görüntüle

@@ -17,6 +17,9 @@ from themes import Context
17 17
 
18 18
 logger = logging.getLogger(__name__)
19 19
 
20
+# TODO: /!\ Deactivate self registration
21
+# TODO: /!\ Remove config and add config_example with data from mm_tmux /!\
22
+
20 23
 
21 24
 def root(request):
22 25
     return HttpResponseRedirect(url_page(request, config.STARTPAGE))
@@ -79,7 +82,7 @@ def edit(request, rel_path):
79 82
                     # TODO: Add translation
80 83
                     title=_("Edit page %s") % repr(p.title),
81 84
                     upload_path=p.attachment_path,
82
-                    page_content=mycreole.render(request, page_txt, p.attachment_path, 'next-anchor')
85
+                    page_content=p.render_text(request, page_txt)
83 86
                 )
84 87
                 return render(request, 'pages/page_form.html', context=context)
85 88
             else:

+ 0
- 3
piki/settings.py Dosyayı Görüntüle

@@ -169,9 +169,6 @@ MYCREOLE_BAR = {
169 169
     'navibar': 'pages.context.navigationbar',
170 170
     'menubar': 'pages.context.menubar',
171 171
 }
172
-MYCREOLE_EXT_FILTERS = [
173
-    # 'pages.creole.page_link_filter',
174
-]
175 172
 # Default primary key field type
176 173
 # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
177 174
 

Loading…
İptal
Kaydet