summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-01-11 11:37:56 -0800
committerSteve Manuel <nilslice@gmail.com>2017-01-11 11:37:56 -0800
commitac82561825ab76f2b5db5c4086541e590fcb70cb (patch)
treea90bc1a4d8f26006916e48d346e4fd384859e1f4
parentbc35db8c462646b8e0ed3bbc94ceca51808a7787 (diff)
extending the "addon" platform within ponzu to register, present and manage addons
-rw-r--r--cmd/ponzu/contentType.tmpl12
-rw-r--r--management/editor/editor.go11
-rw-r--r--system/addon/addon.go6
-rw-r--r--system/addon/manager.go8
-rw-r--r--system/admin/config/config.go12
5 files changed, 26 insertions, 23 deletions
diff --git a/cmd/ponzu/contentType.tmpl b/cmd/ponzu/contentType.tmpl
index 7bf6f06..c16cfd6 100644
--- a/cmd/ponzu/contentType.tmpl
+++ b/cmd/ponzu/contentType.tmpl
@@ -9,14 +9,13 @@ import (
type {{ .Name }} struct {
item.Item
- editor editor.Editor
{{ range .Fields }}{{ .Name }} {{ .TypeName }} `json:"{{ .JSONName }}"`
{{ end }}
}
-// MarshalEditor writes a buffer of html to edit a {{ .Name }}
-// partially implements editor.Editable
+// MarshalEditor writes a buffer of html to edit a {{ .Name }} within the CMS
+// and implements editor.Editable
func ({{ .Initial }} *{{ .Name }}) MarshalEditor() ([]byte, error) {
view, err := editor.Form({{ .Initial }},
// Take note that the first argument to these Input-like functions
@@ -41,9 +40,4 @@ func ({{ .Initial }} *{{ .Name }}) MarshalEditor() ([]byte, error) {
func init() {
item.Types["{{ .Name }}"] = func() interface{} { return new({{ .Name }}) }
-}
-
-// Editor is a buffer of bytes for the Form function to write input views
-// partially implements editor.Editable
-func ({{ .Initial }} *{{ .Name }}) Editor() *editor.Editor { return &{{ .Initial }}.editor }
-
+} \ No newline at end of file
diff --git a/management/editor/editor.go b/management/editor/editor.go
index 511edb2..404e7cd 100644
--- a/management/editor/editor.go
+++ b/management/editor/editor.go
@@ -10,7 +10,6 @@ import (
// Editable ensures data is editable
type Editable interface {
- Editor() *Editor
MarshalEditor() ([]byte, error)
}
@@ -36,7 +35,7 @@ type Field struct {
// Form takes editable content and any number of Field funcs to describe the edit
// page for any content struct added by a user
func Form(post Editable, fields ...Field) ([]byte, error) {
- editor := post.Editor()
+ editor := &Editor{}
editor.ViewBuf = &bytes.Buffer{}
_, err := editor.ViewBuf.WriteString(`<table><tbody class="row"><tr class="col s8"><td>`)
@@ -149,7 +148,8 @@ func Form(post Editable, fields ...Field) ([]byte, error) {
save = form.find('button.save-post'),
del = form.find('button.delete-post'),
external = form.find('.post-controls.external'),
- id = form.find('input[name=id]');
+ id = form.find('input[name=id]'),
+ timestamp = $('.__ponzu.content-only');
// hide if this is a new post, or a non-post editor page
if (id.val() === '-1' || form.attr('action') !== '/admin/edit') {
@@ -162,6 +162,11 @@ func Form(post Editable, fields ...Field) ([]byte, error) {
external.hide();
}
+ // no timestamp on addons
+ if (form.attr('action') === '/admin/addon') {
+ timestamp.hide();
+ }
+
save.on('click', function(e) {
e.preventDefault();
diff --git a/system/addon/addon.go b/system/addon/addon.go
index 22e2114..a423d07 100644
--- a/system/addon/addon.go
+++ b/system/addon/addon.go
@@ -38,9 +38,9 @@ type Addon struct {
Meta
}
-// New constructs a new addon to be registered. Meta is a addon.Meta and fn is a
-// closure returning a pointer to your own addon type
-func New(m Meta, fn func() interface{}) Addon {
+// Register constructs a new addon and registers it with the system. Meta is a
+// addon.Meta and fn is a closure returning a pointer to your own addon type
+func Register(m Meta, fn func() interface{}) Addon {
// get or create the reverse DNS identifier
if m.PonzuAddonReverseDNS == "" {
revDNS, err := reverseDNS(m)
diff --git a/system/addon/manager.go b/system/addon/manager.go
index 3757421..acd779a 100644
--- a/system/addon/manager.go
+++ b/system/addon/manager.go
@@ -15,11 +15,11 @@ const defaultInput = `<input type="hidden" name="%s" value="%s"/>`
const managerHTML = `
<div class="card editor">
<form method="post" action="/admin/addon" enctype="multipart/form-data">
+ <div class="card-content">
+ <div class="card-title">{{ .AddonName }}</div>
+ </div>
{{ .DefaultInputs }}
{{ .Editor }}
- <div class="row">
- <button type="submit" class="btn green waves-effect waves-light right">Save</button>
- </div>
</form>
</div>
`
@@ -27,6 +27,7 @@ const managerHTML = `
type manager struct {
DefaultInputs template.HTML
Editor template.HTML
+ AddonName string
}
// Manage ...
@@ -77,6 +78,7 @@ func Manage(data url.Values, reverseDNS string) ([]byte, error) {
m := manager{
DefaultInputs: template.HTML(inputs.Bytes()),
Editor: template.HTML(v),
+ AddonName: data.Get("addon_name"),
}
// execute html template into buffer for func return val
diff --git a/system/admin/config/config.go b/system/admin/config/config.go
index 2bc80c6..7b57dc0 100644
--- a/system/admin/config/config.go
+++ b/system/admin/config/config.go
@@ -8,7 +8,6 @@ import (
// Config represents the confirgurable options of the system
type Config struct {
item.Item
- editor editor.Editor
Name string `json:"name"`
Domain string `json:"domain"`
@@ -23,9 +22,6 @@ type Config struct {
// String partially implements item.Identifiable and overrides Item's String()
func (c *Config) String() string { return c.Name }
-// Editor partially implements editor.Editable
-func (c *Config) Editor() *editor.Editor { return &c.editor }
-
// MarshalEditor writes a buffer of html to edit a Post and partially implements editor.Editable
func (c *Config) MarshalEditor() ([]byte, error) {
view, err := editor.Form(c,
@@ -90,7 +86,13 @@ func (c *Config) MarshalEditor() ([]byte, error) {
return nil, err
}
- open := []byte(`<div class="card"><form action="/admin/configure" method="post">`)
+ open := []byte(`
+ <div class="card">
+ <div class="card-content">
+ <div class="card-title">System Configuration</div>
+ </div>
+ <form action="/admin/configure" method="post">
+ `)
close := []byte(`</form></div>`)
script := []byte(`
<script>