RaspberryPiFoundation / lesson_format

Lesson formatter
17 stars 28 forks source link

Use scratchblocks2.js on frontend? (and remove pandoc_scratchblocks) #120

Closed andylolz closed 9 years ago

andylolz commented 9 years ago

Paging @tef: this question is specifically directed to you!

Background

lesson_format runs pandoc with the custom pandoc_scratchblocks filter, which in turn uses scratchblocks2.js + phantom.js to generate scratchblock images that are embedded into html.

Alternative

An alternative would be to use scratchblocks2.js client-side, to render scratchblocks on the fly. This does add a dependency on javascript… But that’s not obviously A Bad Thing – to me, at least.

Question

Why do we do it the complicated way? Are there potentially unforeseen issues with doing it the easy way?

Thanks!

tef commented 9 years ago

Why do we do it the complicated way?

  • Browsers are terrible
  • Javascript breaks across platforms and renders differently
  • When you hit print, you have no idea if they will come out/render properly.
  • Resing the window may change everything

We have a mechanism that produces images, such that we don't rely on browsers working, they always render properly when printed out, they're trivially inlineable, they can be copied and pasted, or even saved easily. We can also use the images within PDFS.

That latter reason was one of the major reasons we pre-render scratchblocks, rather than crossing our fingers and hoping the browser works. (Hint; IT NEVER DOES)

It may seem like the complex way, but really it's the easy way for the people who end up using the lessons.

But that’s not obviously A Bad Thing – to me, at least.

The whole point of doing it as a pre-processing step is to make it easier, simpler, and reliable for the people who are reading the tutorials. Not to make it easier for the person running a build script, that's the wrong sort of person to optimize for.

Are there potentially unforeseen issues with doing it the easy way?

If it ain't broke...

My question is: Why, given that we have a mechanism, relatively encapsulated in the process, that produces pretty good images for scratchblocks, why would you want to replace it with a mechanism that might not work across browsers in uncertain ways?

tef commented 9 years ago

It may feel like pre-rendering the scratchblocks adds complexity, but really I think it moves the complexity away from the end user's computer an into the developers—where it belongs.

andylolz commented 9 years ago

Thanks so much for this, @tef (and the twitter chat!)

So it seems some of the things that were issues then (e.g. printability) are hopefully no longer issues, now that we have (auto-generated) PDFs. It would be cool if the HTML were nicely printable too, but that isn’t the case at present anyway, due to the lack of print stylesheet (I’ll make a ticket for that! see #122)

Using scratchblock images in PDFs is a little bit of an issue, as it unnecessarily inflates the filesize of the PDF (and the PDFs are pretty big already…) We could fix that totally separately to this, by doing a separate run of pandoc that generates HTML with the js scratchblocks solution, then runs phantom.js on that HTML (#123). Once that’s done, it might end up quite tempting to just use that solution for everything.

Phantom on heroku seems a bit temperamental… It will usually crash once in the course of generating all those scratchblocks & PDFs. Again, that’s a separate issue, really (#87) – doing this would definitely be a lazy fix for that.

I think it’s important to bear in mind that the end users are actually not the only people to optimise for. There are a lot of volunteers contributing to projects, and it would be great to make it painless for them to test output. Removing the dependence on phantom.js (for HTML output, at least) would help with that (though it is installed via npm now, and there are some rough instructions… but still.) I’m going to say that this is also a separate issue (or… can be solved a different way) because we could host a sort of “Lesson Formatter as a Service”. I’ll make a separate ticket for that See #126. [EDIT it would also be simple to add a command line switch to lesson_format, to generate javascripty scratchblock HTML (#124).]

I’m going to close this one, because (as the label suggests) it was intended as a question, which @tef has answered thoroughly. Thanks again!