Skip to content

Commit

Permalink
Merge pull request #22 from sutori/0-3-2
Browse files Browse the repository at this point in the history
Support Mobiledoc 0.3.2
  • Loading branch information
mixonic authored Jul 16, 2019
2 parents ecfa8ce + b64fa2c commit ff9f191
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/renderer-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import Renderer_0_2, {
} from './renderers/0-2';
import Renderer_0_3, {
MOBILEDOC_VERSION_0_3,
MOBILEDOC_VERSION_0_3_1
MOBILEDOC_VERSION_0_3_1,
MOBILEDOC_VERSION_0_3_2
} from './renderers/0-3';
import RENDER_TYPE from './utils/render-type';
/**
Expand Down Expand Up @@ -64,6 +65,7 @@ export default class RendererFactory {
case null:
case MOBILEDOC_VERSION_0_3:
case MOBILEDOC_VERSION_0_3_1:
case MOBILEDOC_VERSION_0_3_2:
return new Renderer_0_3(mobiledoc, this.state).render();
default:
throw new Error(`Unexpected Mobiledoc version "${version}"`);
Expand Down
5 changes: 3 additions & 2 deletions lib/renderers/0-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import {

export const MOBILEDOC_VERSION_0_3 = '0.3.0';
export const MOBILEDOC_VERSION_0_3_1 = '0.3.1';
export const MOBILEDOC_VERSION = MOBILEDOC_VERSION_0_3_1;
export const MOBILEDOC_VERSION_0_3_2 = '0.3.2';

function validateVersion(version) {
if (
version !== MOBILEDOC_VERSION_0_3 &&
version !== MOBILEDOC_VERSION_0_3_1
version !== MOBILEDOC_VERSION_0_3_1 &&
version !== MOBILEDOC_VERSION_0_3_2
) {
throw new Error(`Unexpected Mobiledoc version "${version}"`);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Renders mobiledoc input to text (string) output",
"main": "dist/commonjs/mobiledoc-text-renderer/index.js",
"scripts": {
"start": "broccoli serve",
"test": "testem ci",
"build": "rm -rf dist/ && broccoli build dist"
},
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/renderers/0-3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
const { test, module } = QUnit;
const MOBILEDOC_VERSION_0_3= '0.3.0';
const MOBILEDOC_VERSION_0_3_1 = '0.3.1';
const MOBILEDOC_VERSION_0_3_2 = '0.3.2';

let renderer;
module('Unit: Mobiledoc Text Renderer - 0.3', {
Expand Down Expand Up @@ -71,6 +72,20 @@ test('renders a mobiledoc 0.3.1 without markers with aside', (assert) => {
'hello world');
});

test('renders a mobiledoc 0.3.2', (assert) => {
let mobiledoc = {
version: MOBILEDOC_VERSION_0_3_2,
atoms: [],
cards: [],
markups: [],
sections: []
};
let {result: rendered} = renderer.render(mobiledoc);

assert.equal(rendered,
'');
});

test('renders a mobiledoc with simple (no attributes) marker', (assert) => {
let mobiledoc = {
version: MOBILEDOC_VERSION_0_3,
Expand Down Expand Up @@ -638,3 +653,26 @@ test('rendering unknown atom uses unknownAtomHandler', (assert) => {
renderer = new Renderer({atoms: [], unknownAtomHandler, cardOptions});
renderer.render(mobiledoc);
});

test('renders a mobiledoc 0.3.2 with attributes', (assert) => {
let mobiledoc = {
version: MOBILEDOC_VERSION_0_3_2,
atoms: [],
cards: [],
markups: [],
sections: [
[
MARKUP_SECTION_TYPE,
'P',
[
[0, [], 0, "Simple aligned example"]
],
['data-md-text-align', 'center']
]
]
};
let {result: rendered} = renderer.render(mobiledoc);

assert.equal(rendered,
'Simple aligned example');
});

0 comments on commit ff9f191

Please sign in to comment.