summaryrefslogtreecommitdiff
path: root/examples/docker/admin/addons/github.com
diff options
context:
space:
mode:
Diffstat (limited to 'examples/docker/admin/addons/github.com')
-rw-r--r--examples/docker/admin/addons/github.com/bosssauce/reference/LICENSE29
-rw-r--r--examples/docker/admin/addons/github.com/bosssauce/reference/README.md3
-rw-r--r--examples/docker/admin/addons/github.com/bosssauce/reference/reference.go150
3 files changed, 0 insertions, 182 deletions
diff --git a/examples/docker/admin/addons/github.com/bosssauce/reference/LICENSE b/examples/docker/admin/addons/github.com/bosssauce/reference/LICENSE
deleted file mode 100644
index 720d6cd..0000000
--- a/examples/docker/admin/addons/github.com/bosssauce/reference/LICENSE
+++ /dev/null
@@ -1,29 +0,0 @@
-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/examples/docker/admin/addons/github.com/bosssauce/reference/README.md b/examples/docker/admin/addons/github.com/bosssauce/reference/README.md
deleted file mode 100644
index 57f008c..0000000
--- a/examples/docker/admin/addons/github.com/bosssauce/reference/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Reference
-
-A Ponzu addon to embed a reference to a content type from within another content type in the CMS.
diff --git a/examples/docker/admin/addons/github.com/bosssauce/reference/reference.go b/examples/docker/admin/addons/github.com/bosssauce/reference/reference.go
deleted file mode 100644
index 753fa41..0000000
--- a/examples/docker/admin/addons/github.com/bosssauce/reference/reference.go
+++ /dev/null
@@ -1,150 +0,0 @@
-// 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"
- "strings"
-
- "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 {
- options, err := encodeDataToOptions(contentType, tmplString)
- if err != nil {
- log.Println("Error encoding data to options for", contentType, err)
- return nil
- }
-
- return editor.Select(fieldName, p, attrs, options)
-}
-
-// SelectRepeater returns the []byte of a <select> HTML element plus internal <options> with a label.
-// It also includes repeat controllers (+ / -) so the element can be
-// dynamically multiplied or reduced.
-// 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 SelectRepeater(fieldName string, p interface{}, attrs map[string]string, contentType, tmplString string) []byte {
- scope := editor.TagNameFromStructField(fieldName, p)
- html := bytes.Buffer{}
- _, err := html.WriteString(`<span class="__ponzu-repeat ` + scope + `">`)
- if err != nil {
- log.Println("Error writing HTML string to SelectRepeater buffer")
- return nil
- }
-
- if _, ok := attrs["class"]; ok {
- attrs["class"] += " browser-default"
- } else {
- attrs["class"] = "browser-default"
- }
-
- // find the field values in p to determine if an option is pre-selected
- fieldVals := editor.ValueFromStructField(fieldName, p)
- vals := strings.Split(fieldVals, "__ponzu")
-
- options, err := encodeDataToOptions(contentType, tmplString)
- if err != nil {
- log.Println("Error encoding data to options for", contentType, err)
- return nil
- }
-
- for _, val := range vals {
- sel := editor.NewElement("select", attrs["label"], fieldName, p, attrs)
- var opts []*editor.Element
-
- // provide a call to action for the select element
- cta := &editor.Element{
- TagName: "option",
- Attrs: map[string]string{"disabled": "true", "selected": "true"},
- Data: "Select an option...",
- ViewBuf: &bytes.Buffer{},
- }
-
- // provide a selection reset (will store empty string in db)
- reset := &editor.Element{
- TagName: "option",
- Attrs: map[string]string{"value": ""},
- Data: "None",
- ViewBuf: &bytes.Buffer{},
- }
-
- opts = append(opts, cta, reset)
-
- for k, v := range options {
- optAttrs := map[string]string{"value": k}
- if k == val {
- optAttrs["selected"] = "true"
- }
- opt := &editor.Element{
- TagName: "option",
- Attrs: optAttrs,
- Data: v,
- ViewBuf: &bytes.Buffer{},
- }
-
- opts = append(opts, opt)
- }
-
- _, err := html.Write(editor.DOMElementWithChildrenSelect(sel, opts))
- if err != nil {
- log.Println("Error writing DOMElementWithChildrenSelect to SelectRepeater buffer")
- return nil
- }
- }
-
- _, err = html.WriteString("</span>")
- if err != nil {
- log.Println("Error writing HTML string to SelectRepeater buffer")
- return nil
- }
-
- return append(html.Bytes(), editor.RepeatController(fieldName, p, "select", ".input-field")...)
-}
-
-func encodeDataToOptions(contentType, tmplString string) (map[string]string, error) {
- // encode all content type from db into options map
- // options in form of map["/api/content?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, err
- }
-
- // 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("/api/content?type=%s&id=%.0f", contentType, item["id"].(float64))
- v := &bytes.Buffer{}
- err := tmpl.Execute(v, item)
- if err != nil {
- return nil, fmt.Errorf(
- "Error executing template for reference of %s: %s",
- contentType, err.Error())
- }
-
- options[k] = v.String()
- }
-
- return options, nil
-}