Home

Awesome

ocaml-cordova-plugin-list

<a href="url"><img src="https://raw.githubusercontent.com/dannywillems/ocaml-cordova-plugin-list/master/res/ocaml-cordova.png" align="center" height="220" width="501" ></a>

Join the chat at https://gitter.im/dannywillems/ocaml-cordova-plugin-list

A complete tutorial with an example

This repository contains the list of bindings in OCaml to Cordova plugins using gen_js_api.

What are Cordova, js_of_ocaml and gen_js_api?

How does it work?

Some bindings has two branches: gen_js_api (master) and js_of_ocaml.

Use gen_js_api for simplicity and maintainability because js_of_ocaml branch is no longer supported.

How can I use a binding?

Needs compiler >= 4.03.0

Each binding has one repository for some reasons: maintainability, update easier, add to list easier and often we only need one binding, not all).

For each bindings listed here, the corresponding opam repository begins with cordova-plugin- and ends with the plugin name. For example, the binding to the camera plugin is cordova-plugin-camera. So, if you want to install the camera binding, you need to use

opam install cordova-plugin-camera

The appropriate opam package is given in the appropriate GitHub repository (list is given below).

If the plugin needs the binding to the standard js library such as device-motion, you need to pin the ocaml-js-stdlib first. If the plugin needs it, it is mentioned in the GitHub repository.

What about documentation for each bindings?

Bindings interface are very close to initial plugins JavaScript interface. For example, for cordova-plugin-camera which allows you to take a picture through navigator.camera.getPicture JavaScript function, you use Cordova_camera.get_picture OCaml function. The equivalent OCaml code to

var success_callback = function(success) {
	console.log(success);
}

var error_callback = function(error) {
	console.log(error);
}

var options = {quality: 25, destinationType: Camera.DestinationType.DATA_URL}

navigator.camera.getPicture(success_callback, error_callback, options)

is

let success_callback success = Jsoo_lib.console_log success in

let error_callback error = Jsoo_lib.console_log error in

let options =
	Cordova_camera.create_options
		~quality:25
		~destination_type:Cordova_camera.Data_url
		()
	in

Cordova_camera.get_picture success_callback error_callback ~opt:options ()

(supposing Jsoo_lib.console_log is the binding to console.log function, see jsoo_lib). Most functions are implemented with optional arguments and these arguments are at the end of the arguments list, so unit is often mandatory.

As the OCaml interface is very close to JavaScript interface, no OCaml documentation is done yet. Feel free to contribute

Bindings which don't have example application are not tested. Please give a feedback about it and open issues if it's the case.

Bindings list

In development

Not planned

MISC

Be careful!

Most of bindings create new objects which are only available when the deviceready event fires. You need to have as first lines:

let on_device_ready () =
	(* Your code using plugins here *)

let _ = Cordova.Event.device_ready on_device_ready

The module Cordova comes from the binding to the cordova object so you need to add it for each project. This module can be installed with

opam install cordova

Help me! I need a binding but it is not listed!

Simply make a pull request and add it in the TO-DO section. Other people could be also interested.

I did a binding to a Cordova plugin which are not listed or not yet done.

It will be a pleasure to add your binding to the list. Don't forget to add a license to your repository: LGPL or less restrictive (MIT, Apache, etc) is recommended. GPL will not be accepted because is too much restrictive.

Here some plugin market for inspiration

Improvements and To-do

cordova plugin add [plugin_name]

It could be interesting to analyse the source code of the Cordova application (written in OCaml), detect used plugins and automatically run the cordova plugin add command. Use merlin method to analyse the code?

Contributors

Maintainer

Related projects