DocuBricks / docubricksViewer

1 stars 3 forks source link

How do I generate viewertest.html #4

Closed rwb27 closed 7 years ago

rwb27 commented 7 years ago

Hello, I'm working on the documentation for the OpenFlexure Microscope. This is a not-entirely-straightforward problem because there's quite a few different options (e.g. different cameras, different optics, different sizes) that need different assembly instructions. Feedback from more or less everyone who has assembled this is that I need specific documentation for each version of the microscope - it's not enough just to have alternative steps in the instructions. So, I'm trying to auto-generate the DocuBricks XML as part of my build process. I'd love to be able to preview what I've done without spamming the DocuBricks website with many half-finished versions, and I've got as far as being able to view the bundled example with this repository on my PC. However, I can't find the code that turns my DocuBricks XML file into the (JSON?) "hiddendata" div in the HTML file that launches the viewer. Is there code somewhere that might be able to do this?

Thanks,

Richard

rwb27 commented 7 years ago

Just thought I'd say I played around with doing this using xml2js. The XML file parses nicely, but I couldn't get it into the strictly typed DocuBricks objects because it's not the same format as the parsed JSON.

The format returned by the XML parser is a dictionary, the keys are the XML tags it finds and each one evaluates to an array - elements of the array are instances of tags with that name. This is different to what we expect from JSON in two ways:

  1. For tags where we expect only one, it should evaluate to the value (i.e. array[0]) not an array
  2. For tags where there is more than one, JSON uses a plural noun and XML is singular.

Nice solution: Write a machine-readable schema and parse it according to that

Easier solution:

Make a list of singular/plural properties and convert them accordingly.

rwb27 commented 7 years ago

I've currently got this working by adding a copyFromXML function to each of the classes that represent elements. This now seems to work (at least on my source file after some cleaning up) which is progress for me! Any comments on my approach (in a branch on my fork) most appreciated - particularly if I'm being a moron and I'm missing some super obvious way to deal with the XML import...

I have a few feature requests for the viewer, but I'll have a bash at implementing the more important ones myself first :)

rwb27 commented 7 years ago

PS let me know if it's worth making a pull request...