Consolidation of widgets and modules into modules + cleaning up module classes

This commit is contained in:
dominiclord
2015-12-08 13:24:02 -05:00
parent 39d10692b3
commit 4c75102da5
8 changed files with 99 additions and 110 deletions

View File

@@ -14,7 +14,7 @@
<link rel="stylesheet" href="modules/boilerplate/assets/styles/dist/main.css">
</head>
<body data-widget="generic">
<body data-module="generic">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="modules/boilerplate/assets/scripts/dist/jquery-1.11.3.min.js"><\/script>')</script>

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
/* jshint esnext: true */
// ==========================================================================
import * as widgets from './widgets'
import * as modules from './modules'
import * as templates from './templates'
class App {
@@ -13,47 +13,40 @@ class App {
this.params = {
current_modules: [],
current_template: this.elements.html.getAttribute('data-template'),
current_widgets: []
current_template: this.elements.html.getAttribute('data-template')
};
this.widgets = widgets;
this.modules = modules;
this.templates = templates;
/**
* @todo Discuss naming conventions and difference between modules and widgets
* @todo [1] Discuss storing instanciated objects
* @todo [2] Discuss singleton concept (one off functions/declarations)
*/
// Modules
// ==========================================================================
//var modules = document.querySelectorAll('[data-app]');
//for (let i = 0, len = modules.length; i < len; i++) {
// let ident = modules[i].getAttribute('data-app');
// if (typeof this[ident] === 'object' && this.params.current_modules.indexOf(ident) === -1) {
// this[ident].init();
// this.params.current_modules.push(ident);
// }
//}
var moduleEls = document.querySelectorAll('[data-module]');
for (let i = 0, len = moduleEls.length; i < len; i++) {
let attr = moduleEls[i].getAttribute('data-module');
// Uppercasing for class usage
let ident = attr.charAt(0).toUpperCase() + attr.slice(1) + 'Module';
if (typeof this.modules[ident] === 'function' && this.params.current_modules.indexOf(ident) === -1) {
// [1,2]
let widget = new this.modules[ident];
// [2]
this.params.current_modules.push(widget);
}
}
// Template
// ==========================================================================
var templateIdent = this.params.current_template + 'Template';
var templateIdent = this.params.current_template.charAt(0).toUpperCase() + this.params.current_template.slice(1) + 'Template';
if (typeof this.templates[templateIdent] === 'function') {
var template = new this.templates[templateIdent];
}
// Widgets
// ==========================================================================
var widgetEls = document.querySelectorAll('[data-widget]');
for (let i = 0, len = widgetEls.length; i < len; i++) {
let ident = widgetEls[i].getAttribute('data-widget') + 'Widget';
if (typeof this.widgets[ident] === 'function' && this.params.current_widgets.indexOf(ident) === -1) {
/**
* @todo Discuss storing instanciated objects
*/
let widget = new this.widgets[ident];
this.params.current_widgets.push(widget);
}
}
}
};

View File

@@ -0,0 +1 @@
export {default as GenericModule} from './modules/Generic';

View File

@@ -1,10 +1,12 @@
// ==========================================================================
// Generic widget
// Generic module
// ==========================================================================
export default class genericWidget {
class GenericModule {
constructor (options) {
console.log('Generic widget');
console.log('Generic module');
this.options = options;
}
}
export default GenericModule;

View File

@@ -1 +1 @@
export {default as genericTemplate} from './templates/generic';
export {default as GenericTemplate} from './templates/Generic';

View File

@@ -2,9 +2,11 @@
// Generic template
// ==========================================================================
export default class genericTemplate {
class GenericTemplate {
constructor (options) {
console.log('Generic template');
this.options = options;
}
}
export default GenericTemplate;

View File

@@ -1 +0,0 @@
export {default as genericWidget} from './widgets/generic';