aboutsummaryrefslogtreecommitdiff
path: root/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'context.go')
-rw-r--r--context.go97
1 files changed, 0 insertions, 97 deletions
diff --git a/context.go b/context.go
deleted file mode 100644
index 27a8c4a..0000000
--- a/context.go
+++ /dev/null
@@ -1,97 +0,0 @@
1/*
2
3 This file is part of FoldaWeb <https://github.com/Pacien/FoldaWeb>
4
5 FoldaWeb is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Affero General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 FoldaWeb is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with FoldaWeb. If not, see <http://www.gnu.org/licenses/>.
17
18*/
19
20package main
21
22import (
23 "github.com/Pacien/fcmd"
24 "path"
25 "strings"
26)
27
28type page struct {
29 Title string
30 Path string
31}
32
33type context struct {
34 filePath string
35 Path string
36 IsCurrent func(params []string, data string) string
37 IsParent func(params []string, data string) string
38}
39
40// Methods accessible in templates
41
42func (c context) Title() string {
43 _, t := path.Split(strings.TrimRight(c.Path, "/"))
44 return t
45}
46
47func (c context) SubPages() (subPages []page) {
48 dirs, _ := fcmd.Ls(c.filePath)
49 for _, dir := range dirs {
50 var page page
51 page.Title = dir
52 page.Path = path.Join(c.Path, dir)
53 subPages = append(subPages, page)
54 }
55 return
56}
57
58func (c context) IsRoot() bool {
59 if c.Path == "/" {
60 return true
61 }
62 return false
63}
64
65func (c context) isCurrent(pageTitle string) bool {
66 if c.Title() == pageTitle {
67 return true
68 }
69 return false
70}
71
72func (c context) isParent(pageTitle string) bool {
73 for _, parent := range strings.Split(c.Path, "/") {
74 if parent == pageTitle {
75 return true
76 }
77 }
78 return false
79}
80
81func makeContext(pagePath, sourceDir string, exts []string) (c context) {
82 c.Path = path.Clean("/" + pagePath)
83 c.filePath = path.Join(sourceDir, c.Path)
84 c.IsCurrent = func(params []string, data string) string {
85 if c.isCurrent(strings.Join(params, " ")) {
86 return data
87 }
88 return ""
89 }
90 c.IsParent = func(params []string, data string) string {
91 if c.isParent(strings.Join(params, " ")) {
92 return data
93 }
94 return ""
95 }
96 return
97}