Skip to content

Commit

Permalink
Add example theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
kennygrant committed May 12, 2017
1 parent 5d62fa0 commit 2116dcd
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 15 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Fragmenta CMS is a user-friendly Content Management System built with Go. For mo
## Usage



## Config


#### Session Name
The *session_name* key is used to set the name used in cookies.

#### Theme
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.


## Requirements

Go 1.8 is now required, as some new features from this release and the 1.7 release are used.
Expand Down
52 changes: 43 additions & 9 deletions src/app/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package app

import (
"fmt"
"os"
"strings"
"time"

"github.com/fragmenta/assets"
Expand Down Expand Up @@ -106,29 +108,61 @@ func SetupAssets() {
}
}

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

}

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

view.Production = config.Production()
err := view.LoadTemplates()

// Start with default source path
paths := []string{"src"}

// Add a theme path if we have one
theme := config.Get("theme")
if theme != "" {
log.Log(log.V{"msg": "loading templates for theme", "theme": theme})
themePath := fmt.Sprintf("themes/%s/src", theme)
paths = append(paths, themePath)
}

err := view.LoadTemplatesAtPaths(paths, helperFuncs())
if err != nil {
// server.Fatalf("Error reading templates %s", err)
log.Fatal(log.V{"msg": "unable to read templates", "error": err})
os.Exit(1)
}

}

// helperFuncs returns a setr of helper functions for view templates
func helperFuncs() map[string]interface{} {

helpers := view.DefaultHelpers()

// Set up helpers which are aware of fingerprinted assets
// These behave differently depending on the compile flag above
// when compile is set to no, they use precompiled assets
// otherwise they serve all files in a group separately
helpers["style"] = appAssets.StyleLink
helpers["script"] = appAssets.ScriptLink

// Get the server config for the root_url
rootURL := config.Get("root_url")

// If running locally use localhost instead
host, err := os.Hostname()
if err == nil && strings.HasSuffix(host, ".local") {
rootURL = "http://localhost:3000"
}

helpers["root_url"] = func() string {
return rootURL
}

return helpers
}

// SetupDatabase sets up the db with query given our server config.
func SetupDatabase() {
defer log.Time(time.Now(), log.V{"msg": "Finished opening database", "db": config.Get("db"), "user": config.Get("db_user")})
Expand Down
8 changes: 2 additions & 6 deletions src/app/views/header.html.got
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
{{ end }}
<nav>
<ul>
<li><a href="http://fragmenta.eu">Fragmenta</a></li>
<li><a href="http://fragmenta.eu/install">Install</a></li>
<li><a href="http://fragmenta.eu/develop">Develop</a></li>
<li><a href="http://fragmenta.eu/docs">Docs</a></li>
<li><a href="http://fragmenta.eu/blog">Blog</a></li>
<li><a href="https://github.com/fragmenta">Github</a></li>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>

Expand Down
15 changes: 15 additions & 0 deletions themes/fragmenta/src/app/views/header.html.got
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ if .currentUser.Admin }}
{{ template "app/views/admin.html.got" . }}
{{ end }}
<nav>
<ul>
<li><a href="http://fragmenta.eu">Fragmenta</a></li>
<li><a href="http://fragmenta.eu/install">Install</a></li>
<li><a href="http://fragmenta.eu/develop">Develop</a></li>
<li><a href="http://fragmenta.eu/docs">Docs</a></li>
<li><a href="http://fragmenta.eu/blog">Blog</a></li>
<li><a href="https://github.com/fragmenta">Github</a></li>
</ul>
</nav>


0 comments on commit 2116dcd

Please sign in to comment.