Skip to content

Commit

Permalink
Pass version number and sections payload on mobiledocs
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jul 29, 2015
1 parent 5e25491 commit 148735b
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 221 deletions.
209 changes: 125 additions & 84 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,99 +289,140 @@ function attemptEditorReboot(editor, textarea) {
}
}

var MOBILEDOC_VERSION = "0.1";
var sampleMobiledocs = {
simpleMobiledoc: [
[],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[], 0, "hello world"]
]]
simpleMobiledoc: {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[], 0, "hello world"]
]]
]
]
],

mobileDocWithMarker: [
[['B']],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[0], 1, "bold world"]
]]
},

mobileDocWithMarker: {
version: MOBILEDOC_VERSION,
sections: [
[['B']],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[0], 1, "bold world"]
]]
]
]
],

mobileDocWithMultipleMarkers: [
[['B'], ['I']],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[], 0, "hello "],
[[0], 1, "bold, "],
[[1], 1, "italic "],
[[], 0, "world."]
]]
},

mobileDocWithMultipleMarkers: {
version: MOBILEDOC_VERSION,
sections: [
[['B'], ['I']],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[], 0, "hello "],
[[0], 1, "bold, "],
[[1], 1, "italic "],
[[], 0, "world."]
]]
]
]
],

mobileDocWithAttributeMarker: [
[['A', ['href', 'http://github.com/bustlelabs/content-kit-editor']]],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[], 0, "see it "],
[[0], 1, "on github"],
[[], 0, "."]
]]
},

mobileDocWithAttributeMarker: {
version: MOBILEDOC_VERSION,
sections: [
[['A', ['href', 'http://github.com/bustlelabs/content-kit-editor']]],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[], 0, "see it "],
[[0], 1, "on github"],
[[], 0, "."]
]]
]
]
},

mobileDocWithAttributeMarker: {
version: MOBILEDOC_VERSION,
sections: [
[['A', ['href', 'http://github.com/bustlelabs/content-kit-editor']]],
[
[1, "H2", [
[[], 0, "headline h2"]
]],
[1, "P", [
[[], 0, "see it "],
[[0], 1, "on github."]
]]
]
]
],

mobileDocWithSimpleCard: [
[],
[
[1, "H2", [
[[], 0, "Simple Card"]
]],
[10, "simple-card"]
},

mobileDocWithSimpleCard: {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "H2", [
[[], 0, "Simple Card"]
]],
[10, "simple-card"]
]
]
],

mobileDocWithEditCard: [
[],
[
[1, "H2", [
[[], 0, "Edit Card"]
]],
[10, "edit-card"]
},

mobileDocWithEditCard: {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "H2", [
[[], 0, "Edit Card"]
]],
[10, "edit-card"]
]
]
],

mobileDocWithInputCard: [
[],
[
[1, "H2", [
[[], 0, "Input Card"]
]],
[10, "input-card"]
},

mobileDocWithInputCard: {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "H2", [
[[], 0, "Input Card"]
]],
[10, "input-card"]
]
]
],

mobileDocWithSelfieCard: [
[],
[
[1, "H2", [
[[], 0, "SelfieCard"]
]],
[10, "selfie-card"]
},

mobileDocWithSelfieCard: {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "H2", [
[[], 0, "SelfieCard"]
]],
[10, "selfie-card"]
]
]
]
}
};


Expand Down
6 changes: 3 additions & 3 deletions src/js/parsers/mobiledoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export default class MobiledocParser {
this.builder = generateBuilder();
}

parse(mobiledoc) {
const markerTypes = mobiledoc[0];
const sections = mobiledoc[1];
parse({version, sections: sectionData}) {
const markerTypes = sectionData[0];
const sections = sectionData[1];

const post = this.builder.generatePost();

Expand Down
7 changes: 6 additions & 1 deletion src/js/renderers/mobiledoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { IMAGE_SECTION_TYPE } from "../models/image";
import { MARKER_TYPE } from "../models/marker";
import { MARKUP_TYPE } from "../models/markup";

export const MOBILEDOC_VERSION = '0.1';

let visitor = {
[POST_TYPE](node, opcodes) {
opcodes.push(['openPost']);
Expand Down Expand Up @@ -51,7 +53,10 @@ let postOpcodeCompiler = {
openPost() {
this.markerTypes = [];
this.sections = [];
this.result = [this.markerTypes, this.sections];
this.result = {
version: MOBILEDOC_VERSION,
sections: [this.markerTypes, this.sections]
};
},
openMarkup(tagName, attributes) {
if (!this._seenMarkerTypes) {
Expand Down
70 changes: 40 additions & 30 deletions tests/acceptance/editor-sections-test.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
import { Editor } from 'content-kit-editor';
import Helpers from '../test-helpers';
import { MOBILEDOC_VERSION } from 'content-kit-editor/renderers/mobiledoc';

const { test, module } = QUnit;

const newline = '\r\n';

let fixture, editor, editorElement;
const mobileDocWith1Section = [
[],
[
[1, "P", [
[[], 0, "only section"]
]]
const mobileDocWith1Section = {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "P", [
[[], 0, "only section"]
]]
]
]
];
const mobileDocWith2Sections = [
[],
[
[1, "P", [
[[], 0, "first section"]
]],
[1, "P", [
[[], 0, "second section"]
]]
};
const mobileDocWith2Sections = {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "P", [
[[], 0, "first section"]
]],
[1, "P", [
[[], 0, "second section"]
]]
]
]
];
const mobileDocWith3Sections = [
[],
[
[1, "P", [
[[], 0, "first section"]
]],
[1, "P", [
[[], 0, "second section"]
]],
[1, "P", [
[[], 0, "third section"]
]]
};
const mobileDocWith3Sections = {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "P", [
[[], 0, "first section"]
]],
[1, "P", [
[[], 0, "second section"]
]],
[1, "P", [
[[], 0, "third section"]
]]
]
]
];
};

module('Acceptance: Editor sections', {
beforeEach() {
Expand Down
Loading

0 comments on commit 148735b

Please sign in to comment.