Skip to content

Commit 2116dcd

Browse files
committed
Add example theme support
1 parent 5d62fa0 commit 2116dcd

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

Diff for: README.md

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ Fragmenta CMS is a user-friendly Content Management System built with Go. For mo
77
## Usage
88

99

10+
11+
## Config
12+
13+
14+
#### Session Name
15+
The *session_name* key is used to set the name used in cookies.
16+
17+
#### Theme
18+
The *theme* key is used to set the theme. To use a theme, add a key with the name of your theme folder to the fragmenta.json file. Theme templates will then override any templates in the app at the same path.
19+
20+
1021
## Requirements
1122

1223
Go 1.8 is now required, as some new features from this release and the 1.7 release are used.

Diff for: src/app/app.go

+43-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package app
22

33
import (
4+
"fmt"
45
"os"
6+
"strings"
57
"time"
68

79
"github.com/fragmenta/assets"
@@ -106,29 +108,61 @@ func SetupAssets() {
106108
}
107109
}
108110

109-
// Set up helpers which are aware of fingerprinted assets
110-
// These behave differently depending on the compile flag above
111-
// when compile is set to no, they use precompiled assets
112-
// otherwise they serve all files in a group separately
113-
view.Helpers["style"] = appAssets.StyleLink
114-
view.Helpers["script"] = appAssets.ScriptLink
115-
116111
}
117112

118113
// SetupView sets up the view package by loadind templates.
119114
func SetupView() {
120115
defer log.Time(time.Now(), log.V{"msg": "Finished loading templates"})
121116

122117
view.Production = config.Production()
123-
err := view.LoadTemplates()
118+
119+
// Start with default source path
120+
paths := []string{"src"}
121+
122+
// Add a theme path if we have one
123+
theme := config.Get("theme")
124+
if theme != "" {
125+
log.Log(log.V{"msg": "loading templates for theme", "theme": theme})
126+
themePath := fmt.Sprintf("themes/%s/src", theme)
127+
paths = append(paths, themePath)
128+
}
129+
130+
err := view.LoadTemplatesAtPaths(paths, helperFuncs())
124131
if err != nil {
125-
// server.Fatalf("Error reading templates %s", err)
126132
log.Fatal(log.V{"msg": "unable to read templates", "error": err})
127133
os.Exit(1)
128134
}
129135

130136
}
131137

138+
// helperFuncs returns a setr of helper functions for view templates
139+
func helperFuncs() map[string]interface{} {
140+
141+
helpers := view.DefaultHelpers()
142+
143+
// Set up helpers which are aware of fingerprinted assets
144+
// These behave differently depending on the compile flag above
145+
// when compile is set to no, they use precompiled assets
146+
// otherwise they serve all files in a group separately
147+
helpers["style"] = appAssets.StyleLink
148+
helpers["script"] = appAssets.ScriptLink
149+
150+
// Get the server config for the root_url
151+
rootURL := config.Get("root_url")
152+
153+
// If running locally use localhost instead
154+
host, err := os.Hostname()
155+
if err == nil && strings.HasSuffix(host, ".local") {
156+
rootURL = "http://localhost:3000"
157+
}
158+
159+
helpers["root_url"] = func() string {
160+
return rootURL
161+
}
162+
163+
return helpers
164+
}
165+
132166
// SetupDatabase sets up the db with query given our server config.
133167
func SetupDatabase() {
134168
defer log.Time(time.Now(), log.V{"msg": "Finished opening database", "db": config.Get("db"), "user": config.Get("db_user")})

Diff for: src/app/views/header.html.got

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
{{ end }}
44
<nav>
55
<ul>
6-
<li><a href="http://fragmenta.eu">Fragmenta</a></li>
7-
<li><a href="http://fragmenta.eu/install">Install</a></li>
8-
<li><a href="http://fragmenta.eu/develop">Develop</a></li>
9-
<li><a href="http://fragmenta.eu/docs">Docs</a></li>
10-
<li><a href="http://fragmenta.eu/blog">Blog</a></li>
11-
<li><a href="https://github.com/fragmenta">Github</a></li>
6+
<li><a href="/">Home</a></li>
7+
<li><a href="/about">About</a></li>
128
</ul>
139
</nav>
1410

Diff for: themes/fragmenta/src/app/views/header.html.got

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{ if .currentUser.Admin }}
2+
{{ template "app/views/admin.html.got" . }}
3+
{{ end }}
4+
<nav>
5+
<ul>
6+
<li><a href="http://fragmenta.eu">Fragmenta</a></li>
7+
<li><a href="http://fragmenta.eu/install">Install</a></li>
8+
<li><a href="http://fragmenta.eu/develop">Develop</a></li>
9+
<li><a href="http://fragmenta.eu/docs">Docs</a></li>
10+
<li><a href="http://fragmenta.eu/blog">Blog</a></li>
11+
<li><a href="https://github.com/fragmenta">Github</a></li>
12+
</ul>
13+
</nav>
14+
15+

0 commit comments

Comments
 (0)