Skip to content

Commit

Permalink
Added content ODD generation for new elements. Fixes #108
Browse files Browse the repository at this point in the history
  • Loading branch information
raffazizzi committed Nov 16, 2020
1 parent b04fded commit 7ccd014
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/reducers/odd/processClassMemberships.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function processClassMemberships(specElement, specData, localData, change
}

export function createClassMemberships(specElement, specData, odd) {
if (specData.classes) {
if (specData.classes.atts.length > 0 && specData.classes.model.length > 0) {
const classesEl = odd.createElementNS('http://www.tei-c.org/ns/1.0', 'classes')
for (const cl of specData.classes.atts.concat(specData.classes.model)) {
const memberOf = odd.createElementNS('http://www.tei-c.org/ns/1.0', 'memberOf')
Expand Down
55 changes: 36 additions & 19 deletions src/reducers/odd/updateElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ export function updateElements(localsource, customization, odd) {
// real change wouldn't really have happened.

for (const el of customization.elements) {
const _cntToXml = (content, parent) => {
for (const cntItem of content) {
const cntItemEl = odd.createElementNS('http://www.tei-c.org/ns/1.0', cntItem.type)
if (cntItem.key) {
cntItemEl.setAttribute('key', cntItem.key)
}
if (cntItem.maxOccurs) {
cntItemEl.setAttribute('maxOccurs', cntItem.maxOccurs)
}
if (cntItem.minOccurs) {
cntItemEl.setAttribute('minOccurs', cntItem.minOccurs)
}
if (cntItem.content) {
_cntToXml(cntItem.content, cntItemEl)
}
parent.appendChild(cntItemEl)
}
}

if (el._isNew) {
// Create new spec
const elSpec = odd.createElementNS('http://www.tei-c.org/ns/1.0', 'elementSpec')
Expand All @@ -41,10 +60,26 @@ export function updateElements(localsource, customization, odd) {
createClassMemberships(elSpec, el, odd)

// Create attributes
if (el.attributes) {
if (el.attributes.length > 0) {
createAttributes(elSpec, el, odd)
}

// Create content
if (el.content.length > 0) {
let contentEl = elSpec.querySelector('content')
if (!contentEl) {
contentEl = odd.createElementNS('http://www.tei-c.org/ns/1.0', 'content')
// Place <content> after documentation elements in right position
insertBetween(
elSpec, contentEl,
['desc', 'gloss', 'altIdent', 'equiv', 'classes'],
['valList', 'constraintSpec', 'attList', 'model', 'modelGrp',
'modelSequence', 'exemplum', 'remarks', 'listRef'])
}
// JSON -> XML
_cntToXml(el.content, contentEl)
}

const schemaSpec = odd.querySelector('schemaSpec')
schemaSpec.appendChild(elSpec)
} else if (el._changed) {
Expand Down Expand Up @@ -78,24 +113,6 @@ export function updateElements(localsource, customization, odd) {
processAttributes(elSpec, el, localEl, localsource, odd)
break
case 'content':
const _cntToXml = (content, parent) => {
for (const cntItem of content) {
const cntItemEl = odd.createElementNS('http://www.tei-c.org/ns/1.0', cntItem.type)
if (cntItem.key) {
cntItemEl.setAttribute('key', cntItem.key)
}
if (cntItem.maxOccurs) {
cntItemEl.setAttribute('maxOccurs', cntItem.maxOccurs)
}
if (cntItem.minOccurs) {
cntItemEl.setAttribute('minOccurs', cntItem.minOccurs)
}
if (cntItem.content) {
_cntToXml(cntItem.content, cntItemEl)
}
parent.appendChild(cntItemEl)
}
}
if (!deepCompare(el.content, localEl.content)) {
elSpec = getOrSetElementSpec(odd, el.ident)
let contentEl = elSpec.querySelector('content')
Expand Down

0 comments on commit 7ccd014

Please sign in to comment.