diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-12-19 12:28:05 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-12-19 12:28:05 -0800 |
commit | 0b54baee6a3999bb8fb717f913fb370a9fc372a3 (patch) | |
tree | 369d5905f2f719faea08ae07324846b34d1b5c54 | |
parent | 9c7f9d5c5a0ee41c405d2ebeb0ad00fe20a09b14 (diff) | |
parent | 974d3c03e6f8b522b6db88238790497edd299561 (diff) |
updating imports to match master
-rw-r--r-- | addons/github.com/ponzu-cms/addons/reference/LICENSE | 29 | ||||
-rw-r--r-- | addons/github.com/ponzu-cms/addons/reference/README.md | 3 | ||||
-rw-r--r-- | addons/github.com/ponzu-cms/addons/reference/reference.go | 54 | ||||
-rw-r--r-- | cmd/ponzu/contentType.tmpl | 2 | ||||
-rw-r--r-- | cmd/ponzu/options.go | 11 | ||||
-rw-r--r-- | management/manager/manager.go | 1 |
6 files changed, 99 insertions, 1 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) +} diff --git a/cmd/ponzu/contentType.tmpl b/cmd/ponzu/contentType.tmpl index 381de30..1a57950 100644 --- a/cmd/ponzu/contentType.tmpl +++ b/cmd/ponzu/contentType.tmpl @@ -4,7 +4,7 @@ import ( "fmt" "github.com/ponzu-cms/ponzu/management/editor" - "github.com/ponzu-cms/ponzu/system/item" + "github.com/ponzu-cms/ponzu/system/item" ) type {{ .Name }} struct { diff --git a/cmd/ponzu/options.go b/cmd/ponzu/options.go index 27f752a..841af94 100644 --- a/cmd/ponzu/options.go +++ b/cmd/ponzu/options.go @@ -150,6 +150,13 @@ func vendorCorePackages(path string) error { return err } + // // create a user content directory to be vendored + // contentPath := filepath.Join(path, "content") + // err = os.Mkdir(contentPath, os.ModeDir|os.ModePerm) + // if err != nil { + // return err + // } + dirs := []string{"content", "management", "system"} for _, dir := range dirs { err = os.Rename(filepath.Join(path, dir), filepath.Join(vendorPath, dir)) @@ -243,7 +250,11 @@ func buildPonzuServer(args []string) error { // copy all ./content files to internal vendor directory src := "content" +<<<<<<< HEAD dst := filepath.Join("cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "content") +======= + dst := filepath.Join("cmd", "ponzu", "vendor", "github.com", "bosssauce", "ponzu", "content") +>>>>>>> ponzu-dev err = copyFilesWarnConflicts(src, dst, []string{"doc.go"}) if err != nil { return err diff --git a/management/manager/manager.go b/management/manager/manager.go index ece6d02..c54918f 100644 --- a/management/manager/manager.go +++ b/management/manager/manager.go @@ -7,6 +7,7 @@ import ( "github.com/ponzu-cms/ponzu/management/editor" "github.com/ponzu-cms/ponzu/system/item" + uuid "github.com/satori/go.uuid" ) |