From 0f7c28fa2e1fec6b3ce006435cd4bd6c7725d4af Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Thu, 9 Apr 2015 00:50:38 -0400 Subject: Report stringify errors --- app/node_modules/oktemplate/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/node_modules/oktemplate/index.js b/app/node_modules/oktemplate/index.js index dafe5e6..a37f78e 100644 --- a/app/node_modules/oktemplate/index.js +++ b/app/node_modules/oktemplate/index.js @@ -18,7 +18,7 @@ var filters = { try { return '
' + stringify(obj) + '
'; } catch (e) { - return ''; + return 'Error stringifying'; } } -- cgit v1.2.3-70-g09d2 From c5e38d7f48e2b5d6ce5ea70f7337f983e55969d6 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Thu, 9 Apr 2015 01:58:01 -0400 Subject: Add captioned-image-list type --- app/node_modules/okschema/index.js | 27 +++++++++++++++++++++++++ examples/db.json | 26 +++++++++++++++++++++--- examples/index.js | 3 ++- themes/okadmin/public/css/main.css | 3 ++- themes/okadmin/templates/partials/inputs.liquid | 16 ++++++++++++++- 5 files changed, 69 insertions(+), 6 deletions(-) diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index 4e8ea73..0544c79 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -34,6 +34,33 @@ var types = { }]; } } + }, + 'captioned-image-list': { + parent: [{ + uri: { type: 'string' }, // TODO Implement URI type + caption: { type: 'string' } + }], + assertValid: function(spec, value) { + var message; + var actual; + if (!value || !value.length) { + throw [{ + message: 'Not an array', + expected: JSON.stringify(this.parent), + actual: value + }]; + } else { + value.forEach(function(obj) { + if (!(obj.uri && obj.caption)) { + throw [{ + message: 'Array contains invalid object', + expected: JSON.stringify(this.parent), + actual: obj + }]; + } + }); + } + } } } diff --git a/examples/db.json b/examples/db.json index b2cdf4a..ab4f7e1 100644 --- a/examples/db.json +++ b/examples/db.json @@ -6,18 +6,38 @@ "description": "really a very tasty bread! yup yes", "color": "blue", "id": "pretzel", - "title": "" + "title": "", + "images": [ + { + "uri": "cool", + "caption": "cool" + } + ] }, { "type": "bagel", "description": "very good and dense bread", - "id": "bagel" + "id": "bagel", + "title": "nice", + "color": "blue", + "images": [ + { + "uri": "http://del.h-cdn.co/assets/cm/15/10/54f928d7ada8d_-_1347910942518.jpg", + "caption": "beep" + } + ] }, { "type": "pumpernickel", "description": "grandma's recipe", "id": "pumpernickel", - "title": "Pumpernickel" + "title": "Pumpernickel", + "images": [ + { + "uri": "cool", + "caption": "cool" + } + ] } ], "page": [ diff --git a/examples/index.js b/examples/index.js index 3dd3a39..9c5b7b4 100644 --- a/examples/index.js +++ b/examples/index.js @@ -14,7 +14,8 @@ var app = okcms.createApp({ type: {type: 'string', id: true}, title: {type: 'string'}, description: {type: 'text'}, - color: {type: 'enum', options: ["red","blue","green"]} + color: {type: 'enum', options: ["red","blue","green"]}, + images: {type: 'captioned-image-list'} } }, diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index c5694eb..d120b0a 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -135,7 +135,8 @@ label { .main.resource form input, .main.resource form textarea, -.main.resource form select { +.main.resource form select, +.main.resource form img { display: block; float: left; width: 20em; diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 551a66c..8269d4e 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -3,7 +3,7 @@ {% assign spec = pair[1] %} {% assign type = spec.type %} -
+
{% if type == 'string' %} @@ -28,6 +28,20 @@ {% endfor %} + {% elsif type == 'captioned-image-list' %} +
    + {% for image in spec.value %} +
  1. + {{image.caption}} + +
    + + +
  2. + {% endfor %} +
+ + {% else %}

Admin template doesn't support '{{type}}' properties!

{% endif %} -- cgit v1.2.3-70-g09d2