Skip to content

Commit

Permalink
Use more constants for mobiledoc versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Nov 19, 2015
1 parent 79d6f6c commit 2d1b59f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/js/parsers/mobiledoc/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MobiledocParser_0_2 from './0-2';
import { MOBILEDOC_VERSION } from 'mobiledoc-kit/renderers/mobiledoc/0-2';

function parseVersion(mobiledoc) {
return mobiledoc.version;
Expand All @@ -8,7 +9,7 @@ export default {
parse(builder, mobiledoc) {
let version = parseVersion(mobiledoc);
switch (version) {
case '0.2.0':
case MOBILEDOC_VERSION:
return new MobiledocParser_0_2(builder).parse(mobiledoc);
default:
throw new Error(`Unknown version of mobiledoc parser requested: ${version}`);
Expand Down
2 changes: 1 addition & 1 deletion src/js/renderers/mobiledoc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export { MOBILEDOC_VERSION };
export default {
render(post, version) {
switch (version) {
case '0.2.0':
case MOBILEDOC_VERSION:
case undefined:
case null:
return MobiledocRenderer_0_2.render(post);
Expand Down
9 changes: 5 additions & 4 deletions tests/helpers/mobiledoc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PostAbstractHelpers from './post-abstract';
import mobiledocRenderers from 'mobiledoc-kit/renderers/mobiledoc';
import MobiledocRenderer_0_2 from 'mobiledoc-kit/renderers/mobiledoc/0-2';
import MobiledocRenderer_0_2, { MOBILEDOC_VERSION } from 'mobiledoc-kit/renderers/mobiledoc/0-2';

/*
* usage:
Expand All @@ -13,12 +13,13 @@ import MobiledocRenderer_0_2 from 'mobiledoc-kit/renderers/mobiledoc/0-2';
* )
*/
function build(treeFn, version) {
let post = PostAbstractHelpers.build(treeFn);
switch (version) {
case '0.2.0':
return MobiledocRenderer_0_2.render(PostAbstractHelpers.build(treeFn));
case MOBILEDOC_VERSION:
return MobiledocRenderer_0_2.render(post);
case undefined:
case null:
return mobiledocRenderers.render(PostAbstractHelpers.build(treeFn));
return mobiledocRenderers.render(post);
default:
throw new Error(`Unknown version of mobiledoc renderer requested: ${version}`);
}
Expand Down

0 comments on commit 2d1b59f

Please sign in to comment.