Skip to content

Commit

Permalink
Add examples to the doc pages (#151)
Browse files Browse the repository at this point in the history
* Push JS examples in doc page

* fix jsoo assets decoding

* simpler exception handling
  • Loading branch information
Keryan-dev authored Jun 13, 2024
1 parent 4a2a70f commit 0fe51c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ doc-common: build
mkdir -p _build/docs
rsync -auv docs/. _build/docs/.

doc-examples: build
mkdir -p _build/docs/examples
cp _build/default/examples/*.js _build/docs/examples/.
cp _build/default/examples/*.html _build/docs/examples/.

sphinx: doc-common
sphinx-build sphinx ${SPHINX_TARGET}

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

doc: doc-common odoc sphinx
doc: doc-common doc-examples odoc sphinx

view:
xdg-open file://$$(pwd)/_build/docs/index.html
Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h1>OCaml-Canvas</h1>
<li><a href="https://github.com/ocamlpro/ocaml-canvas">Project on Github</a></li>
<li><a href="https://ocamlpro.github.io/ocaml-canvas/sphinx">General Documentation</a></li>
<li><a href="https://ocamlpro.github.io/ocaml-canvas/doc">API Documentation</a></li>
<li><a href="examples/index.html">Examples</a></li>
<li><a href="https://github.com/ocamlpro/ocaml-canvas/issues">Bug reports</a></li>
</ul>
<h3>Authors:</h3>
Expand Down
13 changes: 3 additions & 10 deletions src/stubs/ml_canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,15 @@ function _frame_handler(timestamp) {
/* Image Data (aka Pixmaps) */

//Provides: _ml_canvas_image_of_png_file
//Requires: caml_read_file_content
//Requires: caml_read_file_content, caml_raise_with_string, caml_named_value
function _ml_canvas_image_of_png_file(filename) {
var file = caml_read_file_content(filename);
if (file === null) {
return null;
}
var fc = caml_read_file_content(filename);
var data = window.btoa(fc.toUft16 === undefined ? fc.c : fc);
// Test for mlBytes or JS-string
var data = window.btoa(fc.c === undefined ? fc : fc.c);
var img = new window.Image();
img.loading = 'eager';
img.decoding = 'sync';
Expand Down Expand Up @@ -294,8 +295,6 @@ function ml_canvas_image_data_create_from_png(filename, onload) {
var ba = _ml_canvas_ba_of_img(img[1]);
onload(ba);
return 0;
}, function (__err) {
return 0;
});
return 0;
}
Expand Down Expand Up @@ -440,8 +439,6 @@ function ml_canvas_image_data_import_png(data, pos, filename, onload) {
}
onload(data);
return 0;
}, function (__err) {
return 0;
});
return 0;
}
Expand Down Expand Up @@ -850,8 +847,6 @@ function ml_canvas_create_offscreen_from_png(filename, onload) {
canvas.ctxt.drawImage(img[1], 0, 0);
onload(canvas);
return 0;
}, function (__err) {
return 0;
});
return 0;
}
Expand Down Expand Up @@ -1550,8 +1545,6 @@ function ml_canvas_import_png(canvas, pos, filename, onload) {
// image, sx, sy, sWitdh, sHeight, dx, dy, dWidth, dHeight
onload(canvas);
return 0;
}, function (__err) {
return 0;
});
return 0;
}
Expand Down

0 comments on commit 0fe51c1

Please sign in to comment.