Create layout module
This commit is contained in:
parent
44e4ce2a77
commit
07b9f12fac
@ -40,6 +40,7 @@
|
||||
"module": true,
|
||||
"require": true,
|
||||
"requirejs": true,
|
||||
"spyOn": true,
|
||||
"xdescribe": true,
|
||||
"xit": true
|
||||
}
|
||||
|
||||
@ -1,25 +1,22 @@
|
||||
define([
|
||||
'marionette',
|
||||
'jquery',
|
||||
'template'
|
||||
], function AppDefine(Marionette, $, tmpl) {
|
||||
'core/layout/module'
|
||||
], function AppDefine(Marionette, Layout) {
|
||||
'use strict';
|
||||
|
||||
var Application = Marionette.Application;
|
||||
|
||||
function App() {
|
||||
Application.apply(this, arguments);
|
||||
}
|
||||
App.prototype = new Application();
|
||||
|
||||
App.prototype.onStart = function onStart(options) {
|
||||
function App(options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if (options.el == null) {
|
||||
options.el = 'body';
|
||||
Application.apply(this, arguments);
|
||||
}
|
||||
$(options.el).html(tmpl({title: 'started'}));
|
||||
|
||||
App.prototype = new Application();
|
||||
|
||||
App.prototype.initialize = function initialize() {
|
||||
this.module('layout', Layout);
|
||||
};
|
||||
|
||||
return App;
|
||||
|
||||
18
assets/app/core/layout/model.js
Normal file
18
assets/app/core/layout/model.js
Normal file
@ -0,0 +1,18 @@
|
||||
define(['backbone'], function LayoutModelDefine(Backbone) {
|
||||
'use strict';
|
||||
|
||||
var Model = Backbone.Model;
|
||||
|
||||
function LayoutModel() {
|
||||
Model.apply(this, arguments);
|
||||
}
|
||||
LayoutModel.prototype = new Model();
|
||||
|
||||
LayoutModel.prototype.defaults = function defaults() {
|
||||
return {
|
||||
title: 'some title'
|
||||
};
|
||||
};
|
||||
|
||||
return LayoutModel;
|
||||
});
|
||||
26
assets/app/core/layout/module.js
Normal file
26
assets/app/core/layout/module.js
Normal file
@ -0,0 +1,26 @@
|
||||
define([
|
||||
'underscore',
|
||||
'marionette',
|
||||
'core/layout/view',
|
||||
'core/layout/model'
|
||||
], function LayoutModuleDefine(_, Marionette, LayoutView, LayoutModel) {
|
||||
'use strict';
|
||||
|
||||
var LayoutModule = Marionette.Module.extend({
|
||||
Model: LayoutModel,
|
||||
View: LayoutView,
|
||||
|
||||
onStart: function(options) {
|
||||
var opts = _.defaults({}, options || {}, {layout: {}});
|
||||
_.defaults(opts.layout, {view: {}, model: {}});
|
||||
|
||||
var config = opts.layout;
|
||||
this.model = new this.Model(config.model);
|
||||
config.view.model = this.model;
|
||||
this.view = new this.View(config.view);
|
||||
this.view.render();
|
||||
}
|
||||
});
|
||||
|
||||
return LayoutModule;
|
||||
});
|
||||
12
assets/app/core/layout/view.js
Normal file
12
assets/app/core/layout/view.js
Normal file
@ -0,0 +1,12 @@
|
||||
define([
|
||||
'marionette',
|
||||
'core/layout/template'
|
||||
], function CoreLayoutDefine(Marionette, template) {
|
||||
'use strict';
|
||||
|
||||
var CoreLayout = Marionette.LayoutView.extend({
|
||||
template: template
|
||||
});
|
||||
|
||||
return CoreLayout;
|
||||
});
|
||||
@ -1,9 +1,10 @@
|
||||
define('main', ['config', 'app'], function main(config, App) {
|
||||
define('main', ['underscore', 'config', 'app'], function main(_, config, App) {
|
||||
'use strict';
|
||||
requirejs.config(config());
|
||||
return function main(options) {
|
||||
var app = new App();
|
||||
app.start(options);
|
||||
var opts = _.defaults({}, options, {config: {}});
|
||||
var app = new App(opts);
|
||||
app.start(opts.config);
|
||||
return app;
|
||||
};
|
||||
});
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
<script>
|
||||
(function (global) {
|
||||
require(['main'], function _main(main) {
|
||||
global.app = main({el: '#deck'});
|
||||
global.app = main({config: {layout: {view: {el: '#deck'}}}});
|
||||
});
|
||||
}(this));
|
||||
</script>
|
||||
|
||||
@ -15,8 +15,9 @@ module.exports = function(config) {
|
||||
{pattern: 'test/**/!(test-main).js', included: false},
|
||||
{pattern: 'static/**/!(config).js', included: false},
|
||||
{pattern: 'static/**/*.map', included: false},
|
||||
{pattern: 'static/app/config.js', included: true},
|
||||
{pattern: 'test/test-main.js', included: true}
|
||||
'static/style/main.css',
|
||||
'static/app/config.js',
|
||||
'test/test-main.js'
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
|
||||
@ -11,5 +11,11 @@ define(['app'], function (App) {
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('→ has layout', function () {
|
||||
it('→ exits', function () {
|
||||
expect(new App().layout).not.toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
13
test/app/core/layout/model.js
Normal file
13
test/app/core/layout/model.js
Normal file
@ -0,0 +1,13 @@
|
||||
define(['core/layout/model'], function (LayoutModel) {
|
||||
describe('LayoutModel', function () {
|
||||
it('→ exits', function () {
|
||||
expect(new LayoutModel()).not.toBeUndefined();
|
||||
});
|
||||
|
||||
describe('→ has defaults', function () {
|
||||
it('→ title', function () {
|
||||
expect(typeof (new LayoutModel()).get('title')).toBe('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
22
test/app/core/layout/module.js
Normal file
22
test/app/core/layout/module.js
Normal file
@ -0,0 +1,22 @@
|
||||
define([
|
||||
'marionette',
|
||||
'core/layout/module'
|
||||
], function (Marionette, LayoutModule) {
|
||||
describe('LayoutModule', function () {
|
||||
it('→ exits', function () {
|
||||
var app = new Marionette.Application();
|
||||
var module = new LayoutModule('layout', app, {});
|
||||
expect(module).not.toBeUndefined();
|
||||
});
|
||||
|
||||
describe('→ onStart', function () {
|
||||
it('→ will render view', function () {
|
||||
var app = new Marionette.Application();
|
||||
var module = new LayoutModule('layout', app, {});
|
||||
spyOn(module.View.prototype, 'render');
|
||||
module.onStart();
|
||||
expect(module.View.prototype.render).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
7
test/app/core/layout/view.js
Normal file
7
test/app/core/layout/view.js
Normal file
@ -0,0 +1,7 @@
|
||||
define(['core/layout/view'], function (LayoutView) {
|
||||
describe('→ LayoutView', function () {
|
||||
it('→ exists', function () {
|
||||
expect(new LayoutView()).not.toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user