Add slide widget, view and model
parent
dc988e0faa
commit
cc7891ada3
@ -0,0 +1,23 @@
|
||||
define(['underscore', 'backbone'], function SlideModelDefine(_, Backbone) {
|
||||
'use strict';
|
||||
var Model = Backbone.Model;
|
||||
|
||||
function SlideModel() {
|
||||
Model.apply(this, arguments);
|
||||
}
|
||||
|
||||
SlideModel.prototype = new Model();
|
||||
|
||||
_.extend(SlideModel.prototype, {
|
||||
url: function url() {
|
||||
var id = this.get('id');
|
||||
if (id < 10) {
|
||||
return '/slide/0' + id;
|
||||
} else {
|
||||
return '/slide/' + id;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return SlideModel;
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
<div class="copy"></div>
|
||||
<code code="language-javascript"><pre class="language-javascript">
|
||||
{{code}}
|
||||
</pre></code>
|
@ -0,0 +1,30 @@
|
||||
define([
|
||||
'underscore',
|
||||
'marionette',
|
||||
'lib/markdown',
|
||||
'widgets/slide/template'
|
||||
], function AppSlideWidget(_, Marionette, markdown, template) {
|
||||
'use strict';
|
||||
|
||||
var SlideView = Marionette.ItemView.extend({
|
||||
template: template,
|
||||
|
||||
ui: {
|
||||
copy: '.copy',
|
||||
code: 'pre.language-javascript'
|
||||
},
|
||||
|
||||
modelEvents: {
|
||||
change: 'render'
|
||||
},
|
||||
|
||||
onRender: function onRender() {
|
||||
var copy = this.model.get('copy');
|
||||
if (copy) {
|
||||
this.ui.copy.html(markdown(copy));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return SlideView;
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
define(['widgets/slide/model'], function (SlideModel) {
|
||||
describe('SlideModel', function () {
|
||||
it('→ exits', function () {
|
||||
expect(new SlideModel()).not.toBeUndefined();
|
||||
});
|
||||
|
||||
describe('→ url', function () {
|
||||
it('→ with slide id 1', function () {
|
||||
expect((new SlideModel({id: 1})).url()).toBe('/slide/01');
|
||||
});
|
||||
|
||||
it('→ with slide id 10', function () {
|
||||
expect((new SlideModel({id: 10})).url()).toBe('/slide/10');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
define([
|
||||
'backbone',
|
||||
'lib/markdown',
|
||||
'widgets/slide/view'
|
||||
], function (Backbone, markdown, SlideView) {
|
||||
var Model = Backbone.Model;
|
||||
|
||||
describe('SlideView', function () {
|
||||
it('→ exits', function () {
|
||||
expect(new SlideView()).not.toBeUndefined();
|
||||
});
|
||||
|
||||
describe('→ onRender', function () {
|
||||
it('→ renders', function () {
|
||||
var model = new Model({'copy': '**hello**'});
|
||||
var view = new SlideView({model: model});
|
||||
view.render();
|
||||
expect(view.ui.copy.html()).toBe(markdown('**hello**'));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue