summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-12-19 12:28:05 -0800
committerSteve Manuel <nilslice@gmail.com>2016-12-19 12:28:05 -0800
commit0b54baee6a3999bb8fb717f913fb370a9fc372a3 (patch)
tree369d5905f2f719faea08ae07324846b34d1b5c54 /addons
parent9c7f9d5c5a0ee41c405d2ebeb0ad00fe20a09b14 (diff)
parent974d3c03e6f8b522b6db88238790497edd299561 (diff)
updating imports to match master
Diffstat (limited to 'addons')
-rw-r--r--addons/github.com/ponzu-cms/addons/reference/LICENSE29
-rw-r--r--addons/github.com/ponzu-cms/addons/reference/README.md3
-rw-r--r--addons/github.com/ponzu-cms/addons/reference/reference.go54
3 files changed, 86 insertions, 0 deletions
diff --git a/addons/github.com/ponzu-cms/addons/reference/LICENSE b/addons/github.com/ponzu-cms/addons/reference/LICENSE
new file mode 100644
index 0000000..720d6cd
--- /dev/null
+++ b/addons/github.com/ponzu-cms/addons/reference/LICENSE
@@ -0,0 +1,29 @@
+BSD 3-Clause License
+
+Copyright (c) 2016 Boss Sauce Creative, LLC.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file
diff --git a/addons/github.com/ponzu-cms/addons/reference/README.md b/addons/github.com/ponzu-cms/addons/reference/README.md
new file mode 100644
index 0000000..57f008c
--- /dev/null
+++ b/addons/github.com/ponzu-cms/addons/reference/README.md
@@ -0,0 +1,3 @@
+# Reference
+
+A Ponzu addon to embed a reference to a content type from within another content type in the CMS.
diff --git a/addons/github.com/ponzu-cms/addons/reference/reference.go b/addons/github.com/ponzu-cms/addons/reference/reference.go
new file mode 100644
index 0000000..f90964c
--- /dev/null
+++ b/addons/github.com/ponzu-cms/addons/reference/reference.go
@@ -0,0 +1,54 @@
+// Package reference is a Ponzu addon to enable content editors to create
+// references to other content types which are stored as query strings within
+// the referencer's content DB
+package reference
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "html/template"
+ "log"
+
+ "github.com/ponzu-cms/ponzu/management/editor"
+ "github.com/ponzu-cms/ponzu/system/addon"
+)
+
+// Select returns the []byte of a <select> HTML element plus internal <options> with a label.
+// IMPORTANT:
+// The `fieldName` argument will cause a panic if it is not exactly the string
+// form of the struct field that this editor input is representing
+func Select(fieldName string, p interface{}, attrs map[string]string, contentType, tmplString string) []byte {
+ // decode all content type from db into options map
+ // options in form of map["?type=<contentType>&id=<id>"]t.String()
+ options := make(map[string]string)
+
+ var all map[string]interface{}
+ j := addon.ContentAll(contentType)
+
+ err := json.Unmarshal(j, &all)
+ if err != nil {
+ return nil
+ }
+
+ // make template for option html display
+ tmpl := template.Must(template.New(contentType).Parse(tmplString))
+
+ // make data something usable to iterate over and assign options
+ data := all["data"].([]interface{})
+
+ for i := range data {
+ item := data[i].(map[string]interface{})
+ k := fmt.Sprintf("?type=%s&id=%.0f", contentType, item["id"].(float64))
+ v := &bytes.Buffer{}
+ err := tmpl.Execute(v, item)
+ if err != nil {
+ log.Println("Error executing template for reference of:", contentType)
+ return nil
+ }
+
+ options[k] = v.String()
+ }
+
+ return editor.Select(fieldName, p, attrs, options)
+}