Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #38

Merged
merged 4 commits into from
Feb 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved stuff from some files to other files
  • Loading branch information
glennsl committed Feb 18, 2017
commit 5b9c09ad43fdcff3ea9eeea2aa5bafe722b126ea
3 changes: 1 addition & 2 deletions src/extension/Content.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
open Rebase;
open Core;
open Core.Dom;
open Dom;
open Common;

Hljs.registerLanguage "ocaml" [%bs.raw "require('highlight.js/lib/languages/ocaml')"];
Expand Down
2 changes: 0 additions & 2 deletions src/extension/ContentLoader.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Core;

let loaded = ref false;

let load () =>
Expand Down
2 changes: 1 addition & 1 deletion src/extension/Page.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Rebase;
open Core;
open Core.Dom;
open Dom;

[%bs.raw {|require('../../../../src/popup.html')|}];
[%bs.raw {|require('../../../../src/images/logo19.png')|}];
Expand Down
2 changes: 1 addition & 1 deletion src/extension/Popup.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Rebase;
open Core;
open Core.Dom;
open Dom;

[%bs.raw {|require('../../../../src/popup.html')|}];
[%bs.raw {|require('../../../../src/images/logo19.png')|}];
Expand Down
29 changes: 29 additions & 0 deletions src/extension/common/Chrome.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Extension = {
external getURL : string => string = "chrome.extension.getURL" [@@bs.val];
};

module Runtime = {
external sendMessage : 'a => ('b => unit) = "chrome.runtime.sendMessage" [@@bs.val];
external addMessageListener : ('a => Js.t {..} => ('b => unit) => unit) => unit = "chrome.runtime.onMessage.addListener" [@@bs.val];
};

module Storage = {
module Local = {
external get : string => ('a => unit) => unit = "chrome.storage.local.get" [@@bs.val];
external set : Js.t {..} => unit = "chrome.storage.local.set" [@@bs.val];
}
};

module Tabs = {
external create : Js.t {. url: string } => unit = "chrome.tabs.create" [@@bs.val];

/* TODO: Need MaybeArray to work because Chrome will return an array, but FF supposedly does not */
/*external executeScript : Js.t {. code: string } => (MaybeArray.t (Js.t {..}) => unit) => unit = "chrome.tabs.executeScript" [@@bs.val];*/
external executeScript : Js.t {. code: string } => (Js.null_undefined (array string) => unit) => unit = "chrome.tabs.executeScript" [@@bs.val];

external sendMessage : 'id => 'a => ('b => unit) = "chrome.tabs.sendMessage" [@@bs.val];
};

module ContextMenus = {
external create : Js.t {..} => unit = "chrome.contextMenus.create" [@@bs.val];
};
174 changes: 0 additions & 174 deletions src/extension/common/Core.re
Original file line number Diff line number Diff line change
Expand Up @@ -32,174 +32,6 @@ module Promise = {
external resolve : 'a => t 'a = "Promise.resolve" [@@bs.val];
};

module Chrome = {
type promise;
type resolve;

module Extension = {
external getURL : string => string = "chrome.extension.getURL" [@@bs.val];
};

module Runtime = {
external sendMessage : 'a => ('b => unit) = "chrome.runtime.sendMessage" [@@bs.val];
external addMessageListener : ('a => Js.t {..} => ('b => unit) => unit) => unit = "chrome.runtime.onMessage.addListener" [@@bs.val];
};

module Storage = {
module Local = {
external get : string => ('a => unit) => unit = "chrome.storage.local.get" [@@bs.val];
external set : Js.t {..} => unit = "chrome.storage.local.set" [@@bs.val];
}
};

module Tabs = {
external create : Js.t {. url: string } => unit = "chrome.tabs.create" [@@bs.val];

/* TODO: Need MaybeArray to work because Chrome will return an array, but FF supposedly does not */
/*external executeScript : Js.t {. code: string } => (MaybeArray.t (Js.t {..}) => unit) => unit = "chrome.tabs.executeScript" [@@bs.val];*/
external executeScript : Js.t {. code: string } => (Js.null_undefined (array string) => unit) => unit = "chrome.tabs.executeScript" [@@bs.val];

external sendMessage : 'id => 'a => ('b => unit) = "chrome.tabs.sendMessage" [@@bs.val];
};

module ContextMenus = {
external create : Js.t {..} => unit = "chrome.contextMenus.create" [@@bs.val];
};
};

module Message = {
type message 'a = {
type_: string,
message: 'a
};

let send type_ message =>
Chrome.Runtime.sendMessage { type_, message } noop;

let sendTab id type_ message =>
Chrome.Tabs.sendMessage id { type_, message } noop;

let query type_ message callback =>
Chrome.Runtime.sendMessage { type_, message } callback;

let queryTab id type_ message callback =>
Chrome.Tabs.sendMessage id { type_, message } callback;

let receive type_ callback =>
Chrome.Runtime.addMessageListener
(fun request sender respond =>
if (request.type_ == type_) { callback request.message sender respond; })
};

module Dom = {
module Arrayish = {
type t 'a;

external toArray : t 'a => array 'a = "Array.prototype.slice.call" [@@bs.val];
};

module DOMTokenList = {
type t;

external contains : t => string => Js.boolean = "contains" [@@bs.send];
};

module Style = {
type t;

external backgroundImage : t => string = "" [@@bs.get];
external setBackgroundImage : t => string => unit = "backgroundImage" [@@bs.set];
external setBackgroundSize : t => string => unit = "backgroundSize" [@@bs.set];
external setTop : t => string => unit = "top" [@@bs.set];
};

module Element = {
type t;

external classList : t => DOMTokenList.t = "classList" [@@bs.get];
external setClassName : t => string => unit = "className" [@@bs.set];
external href : t => string = "href" [@@bs.get];
external setHref : t => string => unit = "href" [@@bs.set];
external id : t => string = "id" [@@bs.get];
external setId : t => string => unit = "id" [@@bs.set];
external setInnerHTML : t => string => unit = "innerHTML" [@@bs.set];
external innerText : t => string = "innerText" [@@bs.get];
external setInnerText : t => string => unit = "innerText" [@@bs.set];
external nextSibling : t => Js.null t = "nextSibling" [@@bs.get];
external setRel : t => string => unit = "rel" [@@bs.set];
external style : t => Style.t = "style" [@@bs.get];
external setStyle : t => string => unit = "style" [@@bs.set];
external setType : t => string => unit = "type" [@@bs.set];

external setOnClick : t => (Js.t {..} => unit) => unit = "onclick" [@@bs.set];

external appendChild : t => t => unit = "" [@@bs.send];
external getAttribute : t => string => string = "getAttribute" [@@bs.send];
external getElementsByClassName : t => string => Arrayish.t t = "" [@@bs.send];
external getElementsByTagName : t => string => Arrayish.t t = "" [@@bs.send];
external remove : t => unit = "remove" [@@bs.send];
external querySelectorAll : t => string => Arrayish.t t = "" [@@bs.send];

external attachShadow : t => Js.t {..} => t = "" [@@bs.send];

external toReasonJsElement : t => ReasonJs.Document.element = "%identity";
};

module Node = {
let _TEXT_NODE = 3;
let _DOCUMENT_POSITION_PRECEDING = 2;
let _DOCUMENT_POSITION_CONTAINS = 8;

external nodeType : Element.t => int = "" [@@bs.get];
external nodeValue : Element.t => string = "" [@@bs.get];
external parentNode : Element.t => Element.t = "" [@@bs.get];
external cloneNode : Element.t => Element.t = "" [@@bs.send];

external compareDocumentPosition : Element.t => Element.t => int = "" [@@bs.send];
external insertBefore : target::Element.t => new_::Element.t => ref_::Element.t => unit = "" [@@bs.send];
};

module Document = {
type t;

external addEventListener : string => (unit => unit) => unit = "document.addEventListener" [@@bs.val];
external createElement : string => Element.t = "document.createElement" [@@bs.val];
external getElementsByClassName : string => Arrayish.t Element.t = "document.getElementsByClassName" [@@bs.val];
external getElementById : string => Element.t = "document.getElementById" [@@bs.val];
external getElementsByTagName : string => Arrayish.t Element.t = "document.getElementsByTagName" [@@bs.val];
};

module Location = {
external hash : string = "window.location.hash" [@@bs.val];

external reload : Js.boolean => unit = "window.location.reload" [@@bs.val];
};

module Body = {
external outerHTML : string = "document.body.outerHTML" [@@bs.val];

external appendChild : Element.t => unit = "document.body.appendChild" [@@bs.val];
external removeChild : Element.t => unit = "document.body.removeChild" [@@bs.val];
};

module Head = {
external appendChild : Element.t => unit = "document.head.appendChild" [@@bs.val];
};

module Selection = {
type t;

external anchorNode : t => Element.t = "" [@@bs.get];
external focusNode : t => Element.t = "" [@@bs.get];
external toString : t => string = "" [@@bs.send];
external removeAllRanges : t => unit = "" [@@bs.send];
};

module Window = {
external getSelection : unit => Selection.t = "window.getSelection" [@@bs.val];
}
};

module Util = {
external btoa : string => string = "window.btoa" [@@bs.val];
external atob : string => string = "window.atob" [@@bs.val];
Expand All @@ -210,9 +42,3 @@ module Util = {
|> List.filter (fun s => s !== "")
|> String.concat " ";
};

module Hljs = {
external registerLanguage : string => string => unit = "registerLanguage" [@@bs.module "highlight.js/lib/highlight"];
external configure : Js.t {..} => unit = "configure" [@@bs.module "highlight.js/lib/highlight"];
external highlightBlock : Dom.Element.t => unit = "highlightBlock" [@@bs.module "highlight.js/lib/highlight"];
};
109 changes: 109 additions & 0 deletions src/extension/common/Dom.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

/* Should be replaced by ReasonJs eventually */

module Arrayish = {
type t 'a;

external toArray : t 'a => array 'a = "Array.prototype.slice.call" [@@bs.val];
};

module DOMTokenList = {
type t;

external contains : t => string => Js.boolean = "contains" [@@bs.send];
};

module Style = {
type t;

external backgroundImage : t => string = "" [@@bs.get];
external setBackgroundImage : t => string => unit = "backgroundImage" [@@bs.set];
external setBackgroundSize : t => string => unit = "backgroundSize" [@@bs.set];
external setTop : t => string => unit = "top" [@@bs.set];
};

module Element = {
type t;

external classList : t => DOMTokenList.t = "classList" [@@bs.get];
external setClassName : t => string => unit = "className" [@@bs.set];
external href : t => string = "href" [@@bs.get];
external setHref : t => string => unit = "href" [@@bs.set];
external id : t => string = "id" [@@bs.get];
external setId : t => string => unit = "id" [@@bs.set];
external setInnerHTML : t => string => unit = "innerHTML" [@@bs.set];
external innerText : t => string = "innerText" [@@bs.get];
external setInnerText : t => string => unit = "innerText" [@@bs.set];
external nextSibling : t => Js.null t = "nextSibling" [@@bs.get];
external setRel : t => string => unit = "rel" [@@bs.set];
external style : t => Style.t = "style" [@@bs.get];
external setStyle : t => string => unit = "style" [@@bs.set];
external setType : t => string => unit = "type" [@@bs.set];

external setOnClick : t => (Js.t {..} => unit) => unit = "onclick" [@@bs.set];

external appendChild : t => t => unit = "" [@@bs.send];
external getAttribute : t => string => string = "getAttribute" [@@bs.send];
external getElementsByClassName : t => string => Arrayish.t t = "" [@@bs.send];
external getElementsByTagName : t => string => Arrayish.t t = "" [@@bs.send];
external remove : t => unit = "remove" [@@bs.send];
external querySelectorAll : t => string => Arrayish.t t = "" [@@bs.send];

external attachShadow : t => Js.t {..} => t = "" [@@bs.send];

external toReasonJsElement : t => ReasonJs.Document.element = "%identity";
};

module Node = {
let _TEXT_NODE = 3;
let _DOCUMENT_POSITION_PRECEDING = 2;
let _DOCUMENT_POSITION_CONTAINS = 8;

external nodeType : Element.t => int = "" [@@bs.get];
external nodeValue : Element.t => string = "" [@@bs.get];
external parentNode : Element.t => Element.t = "" [@@bs.get];
external cloneNode : Element.t => Element.t = "" [@@bs.send];

external compareDocumentPosition : Element.t => Element.t => int = "" [@@bs.send];
external insertBefore : target::Element.t => new_::Element.t => ref_::Element.t => unit = "" [@@bs.send];
};

module Document = {
type t;

external addEventListener : string => (unit => unit) => unit = "document.addEventListener" [@@bs.val];
external createElement : string => Element.t = "document.createElement" [@@bs.val];
external getElementsByClassName : string => Arrayish.t Element.t = "document.getElementsByClassName" [@@bs.val];
external getElementById : string => Element.t = "document.getElementById" [@@bs.val];
external getElementsByTagName : string => Arrayish.t Element.t = "document.getElementsByTagName" [@@bs.val];
};

module Location = {
external hash : string = "window.location.hash" [@@bs.val];

external reload : Js.boolean => unit = "window.location.reload" [@@bs.val];
};

module Body = {
external outerHTML : string = "document.body.outerHTML" [@@bs.val];

external appendChild : Element.t => unit = "document.body.appendChild" [@@bs.val];
external removeChild : Element.t => unit = "document.body.removeChild" [@@bs.val];
};

module Head = {
external appendChild : Element.t => unit = "document.head.appendChild" [@@bs.val];
};

module Selection = {
type t;

external anchorNode : t => Element.t = "" [@@bs.get];
external focusNode : t => Element.t = "" [@@bs.get];
external toString : t => string = "" [@@bs.send];
external removeAllRanges : t => unit = "" [@@bs.send];
};

module Window = {
external getSelection : unit => Selection.t = "window.getSelection" [@@bs.val];
}
3 changes: 3 additions & 0 deletions src/extension/common/Hljs.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
external registerLanguage : string => string => unit = "registerLanguage" [@@bs.module "highlight.js/lib/highlight"];
external configure : Js.t {..} => unit = "configure" [@@bs.module "highlight.js/lib/highlight"];
external highlightBlock : Dom.Element.t => unit = "highlightBlock" [@@bs.module "highlight.js/lib/highlight"];
23 changes: 23 additions & 0 deletions src/extension/common/Message.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
open Core;

type message 'a = {
type_: string,
message: 'a
};

let send type_ message =>
Chrome.Runtime.sendMessage { type_, message } noop;

let sendTab id type_ message =>
Chrome.Tabs.sendMessage id { type_, message } noop;

let query type_ message callback =>
Chrome.Runtime.sendMessage { type_, message } callback;

let queryTab id type_ message callback =>
Chrome.Tabs.sendMessage id { type_, message } callback;

let receive type_ callback =>
Chrome.Runtime.addMessageListener
(fun request sender respond =>
if (request.type_ == type_) { callback request.message sender respond; })
2 changes: 0 additions & 2 deletions src/extension/common/RefmtProtocol.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Core;

exception DeserializationFail;

type request = {
Expand Down
3 changes: 1 addition & 2 deletions src/extension/content/UI.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Core;
open Core.Dom;
open Dom;

let ocamlLogo = [%bs.raw {|require('../../../../../src/images/ocamlLogo128.png')|}];
let reasonLogo = [%bs.raw {|require('../../../../../src/images/logo128.png')|}];
Expand Down
Loading