diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5bf04c8 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,55 @@ +name: Main workflow + +on: + - pull_request + - push + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Use OCaml 4.11.0 + uses: avsm/setup-ocaml@v1 + with: + ocaml-version: 4.11.0 + - name: "Install ocamlformat.0.15.0" + run: opam install ocamlformat.0.15.0 + - name: "Check lint" + run: opam exec -- ocamlformat --check src/*.ml* + + build: + strategy: + fail-fast: false + matrix: + os: + - macos-latest + - ubuntu-latest + - windows-latest + ocaml-version: + - 4.11.1 + - 4.10.2 + - 4.09.1 + - 4.08.1 + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Use OCaml ${{ matrix.ocaml-version }} + uses: avsm/setup-ocaml@v1 + with: + ocaml-version: ${{ matrix.ocaml-version }} + + - run: opam pin add cordova-plugin-inappbrowser.dev . --no-action + + - run: opam depext cordova-plugin-inappbrowser --yes --with-doc --with-test + + - run: opam install . --deps-only --with-doc --with-test + + - run: opam exec -- dune build + + - run: opam exec -- dune runtest diff --git a/.gitignore b/.gitignore index 546bf95..2fce751 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -*.cma -*.cmo -*.cmi -*.ml +_build +_opam \ No newline at end of file diff --git a/.merlin b/.merlin deleted file mode 100644 index 3f5d233..0000000 --- a/.merlin +++ /dev/null @@ -1 +0,0 @@ -PKG gen_js_api diff --git a/.travis-ci.sh b/.travis-ci.sh deleted file mode 100644 index d9db752..0000000 --- a/.travis-ci.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -#=============================================================================== -# -# FILE: .travis-ci.sh -# -# USAGE: ./.travis-ci.sh -# -# DESCRIPTION: Generate the ml file and compile -# -# AUTHOR: Danny Willems -# CREATED: 04/06/2016 11:26 -# REVISION: 1.0 -#=============================================================================== - -set -o nounset # Treat unset variables as an error - -URL=https://github.com/dannywillems/ocaml-cordova-plugin-inappbrowser.git -PLUGIN_PIN=cordova-plugin-inappbrowser - -export OPAMYES=1 - -if [ -f "$HOME/.opam/config" ]; then - opam update - opam upgrade -else - opam init -fi - -if [ -n "${OPAM_SWITCH}" ]; then - opam switch ${OPAM_SWITCH} -fi -eval `opam config env` - -export OCAMLRUNPARAM=b - -opam install ocamlfind gen_js_api - -# Test for make and make clean -make && make clean - -# Test for make install and make remove -make install && make remove && make clean diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e41d8e7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: c - -sudo: false - -addons: - apt: - sources: - - avsm - packages: - - ocaml - - ocaml-native-compilers - - opam - -script: bash -ex .travis-ci.sh - -env: - - OPAM_SWITCH=4.03.0 - -git: - depth: 1 diff --git a/META b/META deleted file mode 100644 index 8c5193b..0000000 --- a/META +++ /dev/null @@ -1,3 +0,0 @@ -version = "1.0" -description = "Binding to the inappbrowser cordova plugin using gen_js_api" -archive(byte) = "cordova_in_app_browser.cma" diff --git a/Makefile b/Makefile deleted file mode 100644 index 6329fcd..0000000 --- a/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -include Makefile.conf - -################################################################################ -CC = ocamlc -PACKAGES = -package gen_js_api - -ML_FILE = $(patsubst %.mli, %.ml, $(MLI_FILE)) -CMI_FILE = $(patsubst %.mli, %.cmi, $(MLI_FILE)) -CMO_FILE = $(patsubst %.mli, %.cmo, $(MLI_FILE)) -CMA_FILE = $(patsubst %.mli, %.cma, $(MLI_FILE)) -################################################################################ - -################################################################################ -build: - ocamlfind gen_js_api/gen_js_api $(MLI_FILE) - ocamlfind $(CC) -c $(PACKAGES) $(MLI_FILE) - ocamlfind $(CC) -c $(PACKAGES) $(ML_FILE) - ocamlfind $(CC) -a -o $(CMA_FILE) $(CMO_FILE) - -install: build - ocamlfind install $(LIB_NAME) META $(CMA_FILE) $(CMI_FILE) - -remove: - ocamlfind remove $(LIB_NAME) - -clean: - $(RM) $(CMI_FILE) $(CMO_FILE) $(ML_FILE) $(CMA_FILE) - -re: clean all -################################################################################ diff --git a/Makefile.conf b/Makefile.conf deleted file mode 100644 index 5fd7ab6..0000000 --- a/Makefile.conf +++ /dev/null @@ -1,5 +0,0 @@ -################################################################################ -MLI_FILE = cordova_in_app_browser.mli -## Name which will be used in -package with ocamlfind -LIB_NAME = cordova-plugin-inappbrowser -################################################################################ diff --git a/README.md b/README.md index 2886f2d..5bf8c4d 100644 --- a/README.md +++ b/README.md @@ -9,21 +9,22 @@ Binding to [Example application](https://github.com/dannywillems/ocaml-cordova-plugin-inappbrowser-example). -## What does cordova-plugin-inappbrowser do ? +## Setup a dev environment +```shell +# create a local switch +opam install ocamlformat.0.15.0 merlin +opam install -y . ``` -This plugin provides a web browser view that displays when calling + +## What does cordova-plugin-inappbrowser do ? + +> This plugin provides a web browser view that displays when calling `cordova.InAppBrowser.open()`. -``` Source: [cordova-plugin-inappbrowser](https://github.com/apache/cordova-plugin-inappbrowser) -## How to install and compile your project by using this plugin ? - -Don't forget to switch to a compiler **>= 4.03.0**. -```Shell -opam switch 4.03.0 -``` +## How to install and compile your project by using this plugin? You can use opam by pinning the repository with ```Shell @@ -32,7 +33,7 @@ opam pin add cordova-plugin-inappbrowser https://github.com/dannywillems/ocaml-c and to compile your project, use ```Shell -ocamlfind ocamlc -c -o [output_file] -package gen_js_api -package cordova-plugin-inappbrowser [...] -linkpkg [other arguments] +dune build @install ``` Don't forget to install the cordova plugin inappbrowser with diff --git a/opam/opam b/cordova-plugin-inappbrowser.opam similarity index 55% rename from opam/opam rename to cordova-plugin-inappbrowser.opam index 0da497c..24009aa 100644 --- a/opam/opam +++ b/cordova-plugin-inappbrowser.opam @@ -1,22 +1,14 @@ -opam-version: "1.2" -name: "ocaml-cordova-plugin-inappbrowser" +opam-version: "2.0" maintainer: "Danny Willems " -author: "Danny Willems " - +authors: "Danny Willems " homepage: "https://github.com/dannywillems/ocaml-cordova-plugin-inappbrowser" bug-reports: "https://github.com/dannywillems/ocaml-cordova-plugin-inappbrowser/issues" - dev-repo: "https://github.com/dannywillems/ocaml-cordova-plugin-inappbrowser" - license: "LGPL-3.0 with OCaml linking exception" - -version: "1.0" - -build: [make "build"] -install: [make "install"] -remove: [make "remove"] - +description: "Binding to the inappbrowser cordova plugin using gen_js_api" +synopsis: "Binding to the inappbrowser cordova plugin using gen_js_api" +build: [[ "dune" "build" "-j" jobs "-p" name "@install" ]] depends: [ + "ocaml" { >= "4.03.0" } "gen_js_api" ] -available: [ ocaml-version >= "4.03.0" ] diff --git a/cordova_in_app_browser.mli b/cordova_in_app_browser.mli deleted file mode 100644 index 286e6be..0000000 --- a/cordova_in_app_browser.mli +++ /dev/null @@ -1,206 +0,0 @@ -(* -------------------------------------------------------------------------- *) -type target = - | Self [@js "_self"] - | Blank [@js "_blank"] - | System [@js "_system"] - [@@js.enum] -(* -------------------------------------------------------------------------- *) - -(* -------------------------------------------------------------------------- *) -[@@@js.stop] -type presentation_style - -val presentation_pagesheet : presentation_style -val presentation_formsheet : presentation_style -val presentation_fullscreen : presentation_style -[@@@js.start] - -[@@@js.implem -type presentation_style = - | Pagesheet - | Formsheet - | Fullscreen - -let presentation_pagesheet = Pagesheet -let presentation_formsheet = Formsheet -let presentation_fullscreen = Fullscreen - -let presentation_style_to_str x = match x with - | Pagesheet -> "pagesheet" - | Formsheet -> "formsheet" - | Fullscreen -> "fullscreen" -] -(* -------------------------------------------------------------------------- *) - -(* -------------------------------------------------------------------------- *) -[@@@js.stop] -type transition_style - -val transition_flip : transition_style -val transition_cross : transition_style -val transition_cover : transition_style -[@@@js.start] - -[@@@js.implem -type transition_style = - | Flip_horizontal - | Cross_dissolve - | Cover_vertical - -let transition_flip = Flip_horizontal -let transition_cross = Cross_dissolve -let transition_cover = Cover_vertical - -let transition_style_to_str x = match x with - | Flip_horizontal -> "fliphorizontal" - | Cross_dissolve -> "crossdisolve" - | Cover_vertical -> "coververtical" -] -(* -------------------------------------------------------------------------- *) - -(* -------------------------------------------------------------------------- *) - -[@@@js.stop] -type toolbar_position - -val toolbar_top : toolbar_position -val toolbar_bottom : toolbar_position -[@@@js.start] - -[@@@js.implem -type toolbar_position = - | Top - | Bottom - -let toolbar_top = Top -let toolbar_bottom = Bottom - -let toolbar_position_to_str x = match x with - | Top -> "top" - | Bottom -> "bottom" -] -(* -------------------------------------------------------------------------- *) - -(* -------------------------------------------------------------------------- *) - -(* -------------------------------------------------------------------------- *) -(* See documentation for the description of each options. - * Location and Hidden are available for all plateforms (android, ios, windows - * phone). Options with AI are available only on android and ios, I only on ios - * and W only on windows phone. - *) - -[@@@js.stop] -type options - -val location : bool -> options -val hidden : bool -> options -val ai_clear_cache : bool -> options -val ai_clear_session_cache : bool -> options -val ai_media_playback_require_user_action : bool -> options -val a_zoom : bool -> options -val a_hardware_back : bool -> options -val i_close_button_caption : bool -> options -val i_disallow_overscroll : bool -> options -val i_toolbar : bool -> options -val i_enable_viewport_scale : bool -> options -val i_allow_inline_media_player : bool -> options -val i_keyboard_display_require_user_action : bool -> options -val i_suppresses_incremental_rendering : bool -> options -val i_presentation_style : presentation_style -> options -val i_transition_style : transition_style -> options -val i_toolbar_position : toolbar_position -> options -val w_fullscreen : bool -> options - -val options_list_to_str : options list -> string -[@@@js.start] - -[@@@js.implem -type options = - | Location of bool - | Hidden of bool - | AI_clear_chache of bool - | AI_clear_session_cache of bool - | AI_media_playback_require_user_action of bool - | A_zoom of bool - | A_hardware_back of bool - | I_close_button_caption of bool - | I_disallow_overscroll of bool - | I_toolbar of bool - | I_enable_viewport_scale of bool - | I_allow_inline_media_player of bool - | I_keyboard_display_require_user_action of bool - | I_suppresses_incremental_rendering of bool - | I_presentation_style of presentation_style - | I_transition_style of transition_style - | I_toolbar_position of toolbar_position - | W_fullscreen of bool - -let location x = Location x -let hidden x = Hidden x -let ai_clear_cache x = AI_clear_chache x -let ai_clear_session_cache x = AI_clear_session_cache x -let ai_media_playback_require_user_action x = - AI_media_playback_require_user_action x -let a_zoom x = A_zoom x -let a_hardware_back x = A_hardware_back x -let i_close_button_caption x = I_close_button_caption x -let i_disallow_overscroll x = I_disallow_overscroll x -let i_toolbar x = I_toolbar x -let i_enable_viewport_scale x = I_enable_viewport_scale x -let i_allow_inline_media_player x = I_allow_inline_media_player x -let i_keyboard_display_require_user_action x = - I_keyboard_display_require_user_action x -let i_suppresses_incremental_rendering x = - I_suppresses_incremental_rendering x -let i_presentation_style x = I_presentation_style x -let i_transition_style x = I_transition_style x -let i_toolbar_position x = I_toolbar_position x -let w_fullscreen x = W_fullscreen x - -let bool_to_confirmation b = match b with - | true -> "yes" - | false -> "no" - -let options_to_str o = match o with - | Location x -> "location=" ^ bool_to_confirmation x - | Hidden x -> "hidden=" ^ bool_to_confirmation x - | AI_clear_chache x -> "clearcache=" ^ bool_to_confirmation x - | AI_clear_session_cache x -> "clearsessioncache=" ^ bool_to_confirmation x - | AI_media_playback_require_user_action x -> - "mediaPlaybackRequireUserAction=" ^ bool_to_confirmation x - | A_zoom x -> "zoom=" ^ bool_to_confirmation x - | A_hardware_back x -> "hardwareback=" ^ bool_to_confirmation x - | I_close_button_caption x -> "closebuttoncaption=" ^ bool_to_confirmation x - | I_disallow_overscroll x -> "disallowoverscroll=" ^ bool_to_confirmation x - | I_toolbar x -> "toolbar=" ^ bool_to_confirmation x - | I_enable_viewport_scale x -> "enableViewportScale=" ^ bool_to_confirmation x - | I_allow_inline_media_player x -> - "allowInlineMediaPlayer=" ^ bool_to_confirmation x - | I_keyboard_display_require_user_action x -> - "keyboardDisplayRequiresUserAction=" ^ bool_to_confirmation x - | I_suppresses_incremental_rendering x -> - "suppressesIncrementalRendering=" ^ bool_to_confirmation x - | I_presentation_style x -> - "presentationstyle=" ^ presentation_style_to_str x - | I_transition_style x -> - "transitionstyle=" ^ transition_style_to_str x - | I_toolbar_position x -> - "toolbarposition=" ^ toolbar_position_to_str x - | W_fullscreen x -> "fullscreen=" ^ bool_to_confirmation x - -let rec options_list_to_str o = match o with - | [] -> "" - | h::[] -> options_to_str h - | h::t -> options_to_str h ^ "," ^ options_list_to_str t -] -(* -------------------------------------------------------------------------- *) - -(* -------------------------------------------------------------------------- *) -val open_ : - string -> (* The URL to load *) - target -> (* The target in which to load the URL *) - string -> (* Options for the InAppBrowser *) - unit -[@@js.global "cordova.InAppBrowser.open"] -(* -------------------------------------------------------------------------- *) diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..d4ad503 --- /dev/null +++ b/dune-project @@ -0,0 +1,2 @@ +(lang dune 2.8) +(name cordova-plugin-inappbrowser) diff --git a/src/.ocamlformat b/src/.ocamlformat new file mode 100644 index 0000000..1a50ada --- /dev/null +++ b/src/.ocamlformat @@ -0,0 +1,13 @@ +wrap-fun-args=false +let-binding-spacing=compact +field-space=loose +sequence-style=separator +doc-comments=before +margin=80 +module-item-spacing=sparse +parens-tuple=always +parens-tuple-patterns=always +break-string-literals=auto +break-separators=after +space-around-lists=false +dock-collection-brackets=false \ No newline at end of file diff --git a/src/cordova_in_app_browser.mli b/src/cordova_in_app_browser.mli new file mode 100644 index 0000000..8e43b27 --- /dev/null +++ b/src/cordova_in_app_browser.mli @@ -0,0 +1,229 @@ +type target = + | Self [@js "_self"] + | Blank [@js "_blank"] + | System [@js "_system"] +[@@js.enum] + +[@@@js.stop] + +type presentation_style + +val presentation_pagesheet : presentation_style + +val presentation_formsheet : presentation_style + +val presentation_fullscreen : presentation_style + +[@@@js.start] + +[@@@js.implem +type presentation_style = Pagesheet | Formsheet | Fullscreen + +let presentation_pagesheet = Pagesheet + +let presentation_formsheet = Formsheet + +let presentation_fullscreen = Fullscreen + +let presentation_style_to_str x = + match x with + | Pagesheet -> "pagesheet" + | Formsheet -> "formsheet" + | Fullscreen -> "fullscreen"] + +[@@@js.stop] + +type transition_style + +val transition_flip : transition_style + +val transition_cross : transition_style + +val transition_cover : transition_style + +[@@@js.start] + +[@@@js.implem +type transition_style = Flip_horizontal | Cross_dissolve | Cover_vertical + +let transition_flip = Flip_horizontal + +let transition_cross = Cross_dissolve + +let transition_cover = Cover_vertical + +let transition_style_to_str x = + match x with + | Flip_horizontal -> "fliphorizontal" + | Cross_dissolve -> "crossdisolve" + | Cover_vertical -> "coververtical"] + +[@@@js.stop] + +type toolbar_position + +val toolbar_top : toolbar_position + +val toolbar_bottom : toolbar_position + +[@@@js.start] + +[@@@js.implem +type toolbar_position = Top | Bottom + +let toolbar_top = Top + +let toolbar_bottom = Bottom + +let toolbar_position_to_str x = match x with Top -> "top" | Bottom -> "bottom"] + +(* See documentation for the description of each options. + * Location and Hidden are available for all plateforms (android, ios, windows + * phone). Options with AI are available only on android and ios, I only on ios + * and W only on windows phone. + *) +[@@@js.stop] + +type options + +val location : bool -> options + +val hidden : bool -> options + +val ai_clear_cache : bool -> options + +val ai_clear_session_cache : bool -> options + +val ai_media_playback_require_user_action : bool -> options + +val a_zoom : bool -> options + +val a_hardware_back : bool -> options + +val i_close_button_caption : bool -> options + +val i_disallow_overscroll : bool -> options + +val i_toolbar : bool -> options + +val i_enable_viewport_scale : bool -> options + +val i_allow_inline_media_player : bool -> options + +val i_keyboard_display_require_user_action : bool -> options + +val i_suppresses_incremental_rendering : bool -> options + +val i_presentation_style : presentation_style -> options + +val i_transition_style : transition_style -> options + +val i_toolbar_position : toolbar_position -> options + +val w_fullscreen : bool -> options + +val options_list_to_str : options list -> string + +[@@@js.start] + +[@@@js.implem +type options = + | Location of bool + | Hidden of bool + | AI_clear_chache of bool + | AI_clear_session_cache of bool + | AI_media_playback_require_user_action of bool + | A_zoom of bool + | A_hardware_back of bool + | I_close_button_caption of bool + | I_disallow_overscroll of bool + | I_toolbar of bool + | I_enable_viewport_scale of bool + | I_allow_inline_media_player of bool + | I_keyboard_display_require_user_action of bool + | I_suppresses_incremental_rendering of bool + | I_presentation_style of presentation_style + | I_transition_style of transition_style + | I_toolbar_position of toolbar_position + | W_fullscreen of bool + +let location x = Location x + +let hidden x = Hidden x + +let ai_clear_cache x = AI_clear_chache x + +let ai_clear_session_cache x = AI_clear_session_cache x + +let ai_media_playback_require_user_action x = + AI_media_playback_require_user_action x + +let a_zoom x = A_zoom x + +let a_hardware_back x = A_hardware_back x + +let i_close_button_caption x = I_close_button_caption x + +let i_disallow_overscroll x = I_disallow_overscroll x + +let i_toolbar x = I_toolbar x + +let i_enable_viewport_scale x = I_enable_viewport_scale x + +let i_allow_inline_media_player x = I_allow_inline_media_player x + +let i_keyboard_display_require_user_action x = + I_keyboard_display_require_user_action x + +let i_suppresses_incremental_rendering x = I_suppresses_incremental_rendering x + +let i_presentation_style x = I_presentation_style x + +let i_transition_style x = I_transition_style x + +let i_toolbar_position x = I_toolbar_position x + +let w_fullscreen x = W_fullscreen x + +let bool_to_confirmation b = match b with true -> "yes" | false -> "no" + +let options_to_str o = + match o with + | Location x -> "location=" ^ bool_to_confirmation x + | Hidden x -> "hidden=" ^ bool_to_confirmation x + | AI_clear_chache x -> "clearcache=" ^ bool_to_confirmation x + | AI_clear_session_cache x -> "clearsessioncache=" ^ bool_to_confirmation x + | AI_media_playback_require_user_action x -> + "mediaPlaybackRequireUserAction=" ^ bool_to_confirmation x + | A_zoom x -> "zoom=" ^ bool_to_confirmation x + | A_hardware_back x -> "hardwareback=" ^ bool_to_confirmation x + | I_close_button_caption x -> "closebuttoncaption=" ^ bool_to_confirmation x + | I_disallow_overscroll x -> "disallowoverscroll=" ^ bool_to_confirmation x + | I_toolbar x -> "toolbar=" ^ bool_to_confirmation x + | I_enable_viewport_scale x -> "enableViewportScale=" ^ bool_to_confirmation x + | I_allow_inline_media_player x -> + "allowInlineMediaPlayer=" ^ bool_to_confirmation x + | I_keyboard_display_require_user_action x -> + "keyboardDisplayRequiresUserAction=" ^ bool_to_confirmation x + | I_suppresses_incremental_rendering x -> + "suppressesIncrementalRendering=" ^ bool_to_confirmation x + | I_presentation_style x -> "presentationstyle=" ^ presentation_style_to_str x + | I_transition_style x -> "transitionstyle=" ^ transition_style_to_str x + | I_toolbar_position x -> "toolbarposition=" ^ toolbar_position_to_str x + | W_fullscreen x -> "fullscreen=" ^ bool_to_confirmation x + +let rec options_list_to_str o = + match o with + | [] -> "" + | [h] -> options_to_str h + | h :: t -> options_to_str h ^ "," ^ options_list_to_str t] + +val open_ : + string -> + (* The URL to load *) + target -> + (* The target in which to load the URL *) + string -> + (* Options for the InAppBrowser *) + unit + [@@js.global "cordova.InAppBrowser.open"] diff --git a/src/dune b/src/dune new file mode 100644 index 0000000..03b9000 --- /dev/null +++ b/src/dune @@ -0,0 +1,12 @@ +(rule + (targets cordova_in_app_browser.ml) + (deps cordova_in_app_browser.mli) + (action (run %{bin:gen_js_api} %{deps}))) + +(library + (public_name cordova-plugin-inappbrowser) + (name cordova_in_app_browser) + (modes byte) + (libraries gen_js_api) + ; (preprocess (pps gen_js_api)) +)