summaryrefslogtreecommitdiff
path: root/examples/docker/admin
diff options
context:
space:
mode:
Diffstat (limited to 'examples/docker/admin')
-rw-r--r--examples/docker/admin/.dockerignore7
-rw-r--r--examples/docker/admin/.gitignore3
-rw-r--r--examples/docker/admin/Dockerfile15
-rw-r--r--examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/LICENSE29
-rw-r--r--examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/README.md3
-rw-r--r--examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/reference.go150
-rw-r--r--examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/.hold0
-rw-r--r--examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/doc.go6
-rwxr-xr-x[-rw-r--r--]examples/docker/admin/start_admin.sh19
9 files changed, 220 insertions, 12 deletions
diff --git a/examples/docker/admin/.dockerignore b/examples/docker/admin/.dockerignore
index 00c2f38..771d49f 100644
--- a/examples/docker/admin/.dockerignore
+++ b/examples/docker/admin/.dockerignore
@@ -1,7 +1,8 @@
# These directories should not be copied over from the local machine
uploads
search
-
-# These are the databases which persist and should not copy over
system.db
-analytics.db \ No newline at end of file
+analytics.db
+
+# ponzu-server should be built from each startup
+ponzu-server \ No newline at end of file
diff --git a/examples/docker/admin/.gitignore b/examples/docker/admin/.gitignore
index bfccccb..bcc10dc 100644
--- a/examples/docker/admin/.gitignore
+++ b/examples/docker/admin/.gitignore
@@ -1,4 +1,5 @@
search
uploads
analytics.db
-system.db \ No newline at end of file
+system.db
+ponzu-server \ No newline at end of file
diff --git a/examples/docker/admin/Dockerfile b/examples/docker/admin/Dockerfile
new file mode 100644
index 0000000..e9a449a
--- /dev/null
+++ b/examples/docker/admin/Dockerfile
@@ -0,0 +1,15 @@
+FROM ponzu-dev
+
+ENV PONZU_SHARE /ponzu-share
+
+# This is where you want to mount your project:
+ENV PROJECT_FOLDER /go/src/project
+
+VOLUME $PONZU_SHARE
+RUN mkdir $PROJECT_FOLDER
+
+WORKDIR $PROJECT_FOLDER
+EXPOSE 8080
+
+# its better to run this in compose
+# CMD [ "bash" , "/go/src/project/start_admin.sh start" ] \ No newline at end of file
diff --git a/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/LICENSE b/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/LICENSE
new file mode 100644
index 0000000..720d6cd
--- /dev/null
+++ b/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/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/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/README.md b/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/README.md
new file mode 100644
index 0000000..57f008c
--- /dev/null
+++ b/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/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/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/reference.go b/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/reference.go
new file mode 100644
index 0000000..753fa41
--- /dev/null
+++ b/examples/docker/admin/cmd/ponzu/vendor/github.com/bosssauce/reference/reference.go
@@ -0,0 +1,150 @@
+// 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
+}
diff --git a/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/.hold b/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/.hold
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/.hold
diff --git a/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/doc.go b/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/doc.go
deleted file mode 100644
index 8ae4c06..0000000
--- a/examples/docker/admin/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/doc.go
+++ /dev/null
@@ -1,6 +0,0 @@
-// Package content contains all user-supplied content which the system is to
-// manage. Generate content types by using the Ponzu command line tool 'ponzu'
-// by running `$ ponzu generate <contentName> <fieldName:type...>`
-// Note: doc.go file is required to build the Ponzu command since some packages
-// import content package to a blank identifier.
-package content
diff --git a/examples/docker/admin/start_admin.sh b/examples/docker/admin/start_admin.sh
index 6afc02f..986963d 100644..100755
--- a/examples/docker/admin/start_admin.sh
+++ b/examples/docker/admin/start_admin.sh
@@ -1,11 +1,26 @@
+echo "creating the volume assets"
mkdir -p $PONZU_SHARE/uploads
mkdir -p $PONZU_SHARE/search
touch $PONZU_SHARE/system.db
touch $PONZU_SHARE/analytics.db
+
+echo "linking the volume assets"
ln -sf $PONZU_SHARE/uploads $PROJECT_FOLDER/uploads
ln -sf $PONZU_SHARE/search $PROJECT_FOLDER/search
ln -sf $PONZU_SHARE/system.db $PROJECT_FOLDER/system.db
ln -sf $PONZU_SHARE/analytics.db $PROJECT_FOLDER/analytics.db
-# ponzu build",
-# ponzu -port=8080 --https run admin,api" \ No newline at end of file
+if [ "$1" = "start" ]; then
+ echo "building ponzu from project directory"
+ cd $PROJECT_FOLDER && ponzu build
+
+ echo "starting ponzu admin and api"
+ cd $PROJECT_FOLDER && ponzu -port=8080 --https run admin,api &>> $PONZU_SHARE/server.log
+
+ # this line starts and pipes to log, then continues terminal.
+ # cd $PROJECT_FOLDER && nohup ponzu -port=8080 --https run admin,api &> $PONZU_SHARE/server.log &
+ #
+
+ echo "Ponzu server started"
+fi
+