From 788045896419d6b5cdfa6b045fb2f065859f1816 Mon Sep 17 00:00:00 2001 From: Todd Jordan Date: Thu, 25 Aug 2016 00:37:09 -0400 Subject: [PATCH 1/4] Add init layout hook to renderer to set templates for component renderers --- addon/components/dynamic-form.js | 4 +++- addon/renderers/alpaca.js | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addon/components/dynamic-form.js b/addon/components/dynamic-form.js index 8b16a04..9886e87 100644 --- a/addon/components/dynamic-form.js +++ b/addon/components/dynamic-form.js @@ -25,14 +25,16 @@ const DynamicForm = Ember.Component.extend({ if (config.dynamicForms && config.dynamicForms.renderer) { set(this, 'formRenderer', container.lookup(`${config.dynamicForms.renderer}:renderers`)); } else { + //default to alpaca set(this, 'formRenderer', container.lookup('alpaca:renderers')); } + get(this, 'formRenderer').initLayout(this); }, _render() { Ember.Logger.debug('_render'); let renderer = get(this, 'formRenderer'); - renderer.render(get(this, 'renderSchema'), this.$()); + renderer.render(get(this, 'renderSchema'), this); }, didInsertElement() { diff --git a/addon/renderers/alpaca.js b/addon/renderers/alpaca.js index acd3b66..785b6d1 100644 --- a/addon/renderers/alpaca.js +++ b/addon/renderers/alpaca.js @@ -1,7 +1,13 @@ import Ember from 'ember'; export default Ember.Object.extend({ - render(schema, element) { + + initLayout(/*component*/) { + // no template for alpaca + }, + + render(schema, component) { + let element = component.$(); element.empty(); element.alpaca(schema); } From fef3907c76feb2927181401a285d3eb4f029a6d9 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Mon, 29 Aug 2016 12:39:51 +0100 Subject: [PATCH 2/4] Add the ability to disable the inclusion of certain assets. --- README.md | 12 ++++++++++++ index.js | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 215eaf3..f3d15a6 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,18 @@ For more details component usage and asset generation, see the [ember-cli-dynami The schema variable can be in string or object form, but needs to be a valid json-schema alpaca form definition. See the [alpacajs website](http://alpacajs.org) for more information about building valid schemas. +## Excluding Assets +By default ember-cli-dynamic-forms imports bootstrap and alpaca assets to the broccoli tree. If you wish to disable this behaviour and use your own assets, simply specify it in your ember-cli-build.js. + +```js +var app = new EmberApp({ + 'ember-cli-dynamic-forms': { + includeAssets: false, // disables the includion of all assets + includeBootstrapAssets: false // disables just the inclusion of bootstrap assets whilst leaving the rest inplace + } +}); +``` + ## Development ### Setup diff --git a/index.js b/index.js index db8ba68..e19a77c 100644 --- a/index.js +++ b/index.js @@ -5,30 +5,42 @@ module.exports = { name: 'ember-cli-dynamic-forms', included: function (app) { this._super.included(app); + + app.options = app.options || {}; // ensure options is actually set to prevent undefined errors + var options = app.options['ember-cli-dynamic-forms'] || {}; // ensure we have an options object at the very least + + // opt out early if we don't want any assets + if('includeAssets' in options && !options.includeAssets) { + return; + } + app.import(app.bowerDirectory + '/handlebars/handlebars.js'); - app.import(app.bowerDirectory + '/bootstrap/dist/js/bootstrap.js'); - app.import(app.bowerDirectory + '/bootstrap/dist/css/bootstrap.css'); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff', { - destDir: 'fonts' - }); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot', { - destDir: 'fonts' - }); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg', { - destDir: 'fonts' - }); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf', { - destDir: 'fonts' - }); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2', { - destDir: 'fonts' - }); + + // include bootstrap assets unless explicitly told otherwise + if(!('includeBootstrapAssets' in options) || options.includeBootstrapAssets) { + app.import(app.bowerDirectory + '/bootstrap/dist/js/bootstrap.js'); + app.import(app.bowerDirectory + '/bootstrap/dist/css/bootstrap.css'); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff', { + destDir: 'fonts' + }); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot', { + destDir: 'fonts' + }); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg', { + destDir: 'fonts' + }); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf', { + destDir: 'fonts' + }); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2', { + destDir: 'fonts' + }); + } app.import(app.bowerDirectory + '/alpaca/dist/alpaca/bootstrap/alpaca.js'); app.import(app.bowerDirectory + '/alpaca/dist/alpaca/bootstrap/alpaca.css'); app.import(app.bowerDirectory + '/lodash/lodash.js'); - }, isDevelopingAddon: function () { return false; From 85bed6aee979d89489174d4f8d71f479fb0d9f5c Mon Sep 17 00:00:00 2001 From: Todd Jordan Date: Sat, 3 Sep 2016 01:26:46 -0400 Subject: [PATCH 3/4] load renderers from dynamic-forms/renderers --- addon/components/dynamic-form.js | 4 ++-- addon/{ => dynamic-forms}/renderers/alpaca.js | 0 app/dynamic-forms/renderers/alpaca.js | 3 +++ app/renderers/alpaca.js | 3 --- index.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename addon/{ => dynamic-forms}/renderers/alpaca.js (100%) create mode 100644 app/dynamic-forms/renderers/alpaca.js delete mode 100644 app/renderers/alpaca.js diff --git a/addon/components/dynamic-form.js b/addon/components/dynamic-form.js index 9886e87..523fd1d 100644 --- a/addon/components/dynamic-form.js +++ b/addon/components/dynamic-form.js @@ -23,10 +23,10 @@ const DynamicForm = Ember.Component.extend({ let container = getOwner(this); let config = container.resolveRegistration('config:environment'); if (config.dynamicForms && config.dynamicForms.renderer) { - set(this, 'formRenderer', container.lookup(`${config.dynamicForms.renderer}:renderers`)); + set(this, 'formRenderer', container.lookup(`${config.dynamicForms.renderer}:dynamic-forms.renderers`)); } else { //default to alpaca - set(this, 'formRenderer', container.lookup('alpaca:renderers')); + set(this, 'formRenderer', container.lookup('alpaca:dynamic-forms.renderers')); } get(this, 'formRenderer').initLayout(this); }, diff --git a/addon/renderers/alpaca.js b/addon/dynamic-forms/renderers/alpaca.js similarity index 100% rename from addon/renderers/alpaca.js rename to addon/dynamic-forms/renderers/alpaca.js diff --git a/app/dynamic-forms/renderers/alpaca.js b/app/dynamic-forms/renderers/alpaca.js new file mode 100644 index 0000000..72e61bf --- /dev/null +++ b/app/dynamic-forms/renderers/alpaca.js @@ -0,0 +1,3 @@ +import Alpaca from 'ember-cli-dynamic-forms/dynamic-forms/renderers/alpaca'; + +export default Alpaca; diff --git a/app/renderers/alpaca.js b/app/renderers/alpaca.js deleted file mode 100644 index 3416ac3..0000000 --- a/app/renderers/alpaca.js +++ /dev/null @@ -1,3 +0,0 @@ -import Alpaca from 'ember-cli-dynamic-forms/renderers/alpaca'; - -export default Alpaca; diff --git a/index.js b/index.js index db8ba68..d6e2227 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,6 @@ module.exports = { }, isDevelopingAddon: function () { - return false; + return true; } }; From 9cbfdbf74198c0a73c9c0333be441c7b10824937 Mon Sep 17 00:00:00 2001 From: Todd Jordan Date: Sat, 3 Sep 2016 01:39:04 -0400 Subject: [PATCH 4/4] 0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d75266b..c52f808 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-cli-dynamic-forms", - "version": "0.1.3", + "version": "0.2.0", "description": "An Ember addon for creating dynamic forms", "directories": { "doc": "doc",