Skip to content

Commit

Permalink
Persist output names in cell attributes
Browse files Browse the repository at this point in the history
This is needed to be able to allow for rendering cells without starting
the engine.
  • Loading branch information
obuchtala committed Jul 27, 2018
1 parent 1d98195 commit 6c2d0e5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/StencilaArchive.js
@@ -1,6 +1,7 @@
import { prettyPrintXML } from 'substance'
import { JATSExporter, TextureArchive } from 'substance-texture'
import { TextureArchive } from 'substance-texture'
import ArticleLoader from './article/ArticleLoader'
import ArticleExporter from './article/ArticleExporter'
import SheetLoader from './sheet/SheetLoader'

export default class StencilaArchive extends TextureArchive {
Expand Down Expand Up @@ -66,19 +67,7 @@ export default class StencilaArchive extends TextureArchive {
_exportDocument(type, session, sessions) {
switch (type) {
case 'article': {
// FIXME: hard-coded, and thus bad
// TODO: export only those resources which have been changed
// Also we need to
let jatsExporter = new JATSExporter()
let pubMetaDb = sessions['pub-meta'].getDocument()
let doc = session.getDocument()
let dom = doc.toXML()
let res = jatsExporter.export(dom, { pubMetaDb, doc })
console.info('saving jats', res.dom.getNativeElement())
// TODO: bring back pretty printing (currently messes up CDATA content)
let xmlStr = prettyPrintXML(res.dom)
//let xmlStr = res.dom.serialize()
return xmlStr
return ArticleExporter.export(session, { sessions })
}
case 'sheet': {
let dom = session.getDocument().toXML()
Expand Down
23 changes: 23 additions & 0 deletions src/article/ArticleExporter.js
@@ -0,0 +1,23 @@
import { prettyPrintXML } from 'substance'
import { JATSExporter } from 'substance-texture'
import persistCellStates from './persistCellStates'

export default {
export (session, { sessions }) {
// FIXME: hard-coded, and thus bad
// TODO: export only those resources which have been changed
// Also we need to
let jatsExporter = new JATSExporter()
let pubMetaDb = sessions['pub-meta'].getDocument()
let doc = session.getDocument()
let dom = doc.toXML()

let res = jatsExporter.export(dom, { pubMetaDb, doc })
persistCellStates(doc, res.dom)

console.info('saving jats', res.dom.getNativeElement())
// TODO: bring back pretty printing (currently messes up CDATA content)
let xmlStr = prettyPrintXML(res.dom)
return xmlStr
}
}
13 changes: 13 additions & 0 deletions src/article/persistCellStates.js
@@ -0,0 +1,13 @@
import { forEach } from 'substance'

export default function persistCellStates (doc, dom) {
let cells = doc.getIndex('type').get('cell')
forEach(cells, cell => {
let el = dom.find(`#${cell.id}`)
let state = cell.state
// store the cell output
if (state.output) {
el.attr('output-name', state.output)
}
})
}

0 comments on commit 6c2d0e5

Please sign in to comment.