Skip to content

Commit 0fe51c1

Browse files
authored
Add examples to the doc pages (#151)
* Push JS examples in doc page * fix jsoo assets decoding * simpler exception handling
1 parent 4a2a70f commit 0fe51c1

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ doc-common: build
2626
mkdir -p _build/docs
2727
rsync -auv docs/. _build/docs/.
2828

29+
doc-examples: build
30+
mkdir -p _build/docs/examples
31+
cp _build/default/examples/*.js _build/docs/examples/.
32+
cp _build/default/examples/*.html _build/docs/examples/.
33+
2934
sphinx: doc-common
3035
sphinx-build sphinx ${SPHINX_TARGET}
3136

@@ -34,7 +39,7 @@ odoc: doc-common
3439
opam exec -- dune build @doc
3540
rsync -auv --delete _build/default/_doc/_html/. ${ODOC_TARGET}
3641

37-
doc: doc-common odoc sphinx
42+
doc: doc-common doc-examples odoc sphinx
3843

3944
view:
4045
xdg-open file://$$(pwd)/_build/docs/index.html

docs/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ <h1>OCaml-Canvas</h1>
2525
<li><a href="https://github.com/ocamlpro/ocaml-canvas">Project on Github</a></li>
2626
<li><a href="https://ocamlpro.github.io/ocaml-canvas/sphinx">General Documentation</a></li>
2727
<li><a href="https://ocamlpro.github.io/ocaml-canvas/doc">API Documentation</a></li>
28+
<li><a href="examples/index.html">Examples</a></li>
2829
<li><a href="https://github.com/ocamlpro/ocaml-canvas/issues">Bug reports</a></li>
2930
</ul>
3031
<h3>Authors:</h3>

src/stubs/ml_canvas.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,15 @@ function _frame_handler(timestamp) {
217217
/* Image Data (aka Pixmaps) */
218218

219219
//Provides: _ml_canvas_image_of_png_file
220-
//Requires: caml_read_file_content
220+
//Requires: caml_read_file_content, caml_raise_with_string, caml_named_value
221221
function _ml_canvas_image_of_png_file(filename) {
222222
var file = caml_read_file_content(filename);
223223
if (file === null) {
224224
return null;
225225
}
226226
var fc = caml_read_file_content(filename);
227-
var data = window.btoa(fc.toUft16 === undefined ? fc.c : fc);
227+
// Test for mlBytes or JS-string
228+
var data = window.btoa(fc.c === undefined ? fc : fc.c);
228229
var img = new window.Image();
229230
img.loading = 'eager';
230231
img.decoding = 'sync';
@@ -294,8 +295,6 @@ function ml_canvas_image_data_create_from_png(filename, onload) {
294295
var ba = _ml_canvas_ba_of_img(img[1]);
295296
onload(ba);
296297
return 0;
297-
}, function (__err) {
298-
return 0;
299298
});
300299
return 0;
301300
}
@@ -440,8 +439,6 @@ function ml_canvas_image_data_import_png(data, pos, filename, onload) {
440439
}
441440
onload(data);
442441
return 0;
443-
}, function (__err) {
444-
return 0;
445442
});
446443
return 0;
447444
}
@@ -850,8 +847,6 @@ function ml_canvas_create_offscreen_from_png(filename, onload) {
850847
canvas.ctxt.drawImage(img[1], 0, 0);
851848
onload(canvas);
852849
return 0;
853-
}, function (__err) {
854-
return 0;
855850
});
856851
return 0;
857852
}
@@ -1550,8 +1545,6 @@ function ml_canvas_import_png(canvas, pos, filename, onload) {
15501545
// image, sx, sy, sWitdh, sHeight, dx, dy, dWidth, dHeight
15511546
onload(canvas);
15521547
return 0;
1553-
}, function (__err) {
1554-
return 0;
15551548
});
15561549
return 0;
15571550
}

0 commit comments

Comments
 (0)