diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-12-19 12:29:23 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-12-19 12:29:23 -0800 |
commit | c6b298731607da050521f38ee3b0e7e0b3775003 (patch) | |
tree | 27dad7bb20ef36b97a09460f7c4f3fab97c834e1 /addons | |
parent | 0b54baee6a3999bb8fb717f913fb370a9fc372a3 (diff) |
replace /reference with full path to import
Diffstat (limited to 'addons')
-rw-r--r-- | addons/reference/reference.go | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/addons/reference/reference.go b/addons/reference/reference.go deleted file mode 100644 index 35b7d3d..0000000 --- a/addons/reference/reference.go +++ /dev/null @@ -1,54 +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" - - "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 - // 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) -} |