flok 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +7 -0
- data/Rakefile +13 -17
- data/app/drivers/chrome/Rakefile +10 -17
- data/app/drivers/chrome/src/config0.js +1 -0
- data/app/drivers/chrome/src/helpers.js +6 -0
- data/app/drivers/chrome/src/net.js +46 -0
- data/app/drivers/chrome/src/ui.js +87 -0
- data/app/drivers/chrome/{vendor → src/vendor}/jquery.js +0 -0
- data/app/kern/hello.js +1 -0
- data/docs/compilation.md +7 -10
- data/docs/driver_interface.md +61 -0
- data/docs/interface.md +5 -0
- data/docs/platform_drivers.md +1 -0
- data/docs/project_layout.md +3 -2
- data/docs/testing.md +1 -0
- data/flok.gemspec +1 -0
- data/lib/flok.rb +1 -41
- data/lib/flok/build.rb +79 -0
- data/lib/flok/version.rb +1 -1
- data/{public/application.js → output.js} +0 -0
- data/spec/build_valid_spec.rb +61 -0
- data/spec/drivers/net_spec.rb +157 -157
- data/spec/helpers.rb +6 -0
- metadata +29 -15
- data/.run2 +0 -3
- data/app/drivers/chrome/net.js +0 -48
- data/app/drivers/chrome/ui.js +0 -87
- data/lib/js/kernel/pipe.js +0 -36
- data/lib/js/kernel/utils.js +0 -8
- data/lib/js/namespaces.js +0 -2
- data/spec/cli_spec.rb +0 -210
- data/spec/merge_source_spec.rb +0 -68
- data/ypou +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0aaa785dec6e5bd611a315aa4e7429461e06ce4
|
4
|
+
data.tar.gz: add685413b3340bb7fb21ff13b1331cbae7a586c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4daf5b712620fddf856254b13a19f4fb5e74e8309d19c1074b3f41836e2a86176429e692b02df2bd1d7660c59bc1bc6a2acaeb4cfa5a0aa113485e7611e1f53f
|
7
|
+
data.tar.gz: 3c06fa286b16563bbc4a68f07d567477dd43023889e62925b9415bb37b92911ca704de81d7732de3b1302ecfa69b9ab41208eb679247e27f1b61bfda0fa07ead
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -9,12 +9,19 @@
|
|
9
9
|
|
10
10
|
A work in progress
|
11
11
|
|
12
|
+
# Supported platforms
|
13
|
+
* iOS 8 (iPhone)
|
14
|
+
* HTML5
|
15
|
+
|
12
16
|
## Docs
|
13
17
|
|
14
18
|
* [Project Layout](./docs/project_layout.md)
|
15
19
|
* [Platform Drivers](./docs/platform_drivers.md)
|
20
|
+
* [Driver Interface](./docs/driver_interface.md)
|
16
21
|
* [Architecture](./docs/architecture.md)
|
17
22
|
* [Compilation](./docs/compilation.md)
|
23
|
+
* [System Interface](./docs/interface.md)
|
24
|
+
* [Testing](./docs/testing.md)
|
18
25
|
|
19
26
|
## Requirements
|
20
27
|
|
data/Rakefile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'rspec/core/rake_task'
|
2
2
|
require "bundler/gem_tasks"
|
3
|
+
require "fileutils"
|
4
|
+
require './lib/flok'
|
3
5
|
|
4
6
|
# Default directory to look in is `/specs`
|
5
7
|
# Run with `rake spec`
|
6
8
|
RSpec::Core::RakeTask.new(:spec)
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
#Gem things
|
11
|
+
#############################################################################
|
10
12
|
#Upgrade version of gem
|
11
13
|
def upgrade_version
|
12
14
|
versionf = './lib/flok/version.rb'
|
@@ -36,21 +38,15 @@ task :push do
|
|
36
38
|
`gem push flok-#{version}.gem`
|
37
39
|
`rm flok-#{version}.gem`
|
38
40
|
end
|
41
|
+
#############################################################################
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
#Compliation
|
44
|
+
#############################################################################
|
45
|
+
task :build_world do
|
46
|
+
#What platform are we working with?
|
47
|
+
raise "No $PLATFORM given" unless platform = ENV["PLATFORM"]
|
48
|
+
build_path = "./products/#{platform}"
|
45
49
|
|
46
|
-
|
47
|
-
puts ENV["FUCK"]
|
48
|
-
end
|
49
|
-
|
50
|
-
#Update documents to github
|
51
|
-
task :udocs do
|
52
|
-
`git add ./docs/*`
|
53
|
-
`git add README.md`
|
54
|
-
`git commit -a -m "Update docs"`
|
55
|
-
`git push`
|
50
|
+
Flok.build_world(build_path, platform)
|
56
51
|
end
|
52
|
+
#############################################################################
|
data/app/drivers/chrome/Rakefile
CHANGED
@@ -1,24 +1,17 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'flok/build'
|
3
|
+
require 'securerandom'
|
2
4
|
|
3
5
|
#Compile all the *.js files into one file
|
4
|
-
BUILD_PATH = '../../../products/drivers/browser.js'
|
5
6
|
task :build do
|
6
|
-
|
7
|
-
Dir["./vendor/*.js"].each do |js|
|
8
|
-
code = File.read(js)
|
9
|
-
out << code
|
10
|
-
out << "\n"
|
11
|
-
end
|
12
|
-
|
13
|
-
Dir["*.js"].each do |js|
|
14
|
-
code = File.read(js)
|
15
|
-
out << code
|
16
|
-
out << "\n"
|
17
|
-
end
|
7
|
+
raise "No BUILD_PATH given" unless BUILD_PATH=ENV["BUILD_PATH"]
|
18
8
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
my_path = File.expand_path(File.dirname(__FILE__))
|
10
|
+
Dir.mktmpdir(SecureRandom.hex) do |dir|
|
11
|
+
Dir.chdir dir do
|
12
|
+
Flok.src_glob("js", "#{my_path}/src/vendor", "0src_vendor.js")
|
13
|
+
Flok.src_glob("js", "#{my_path}/src/", "1src.js")
|
14
|
+
Flok.src_glob("js", ".", File.join(BUILD_PATH, "chrome.js"))
|
15
|
+
end
|
23
16
|
end
|
24
17
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
flok = {};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
//$(document).ready(function() {
|
2
|
+
//flok_request("GET", "http://test.services.fittr.com/ping", {}, null);
|
3
|
+
//})
|
4
|
+
|
5
|
+
//All requests are bound to this table and removed when cancelled
|
6
|
+
flok.net = {};
|
7
|
+
flok.net.callbackTable = {};
|
8
|
+
flok.net.socketIndex = 0 //The current index of the socket, incremented for new sockets
|
9
|
+
|
10
|
+
//A basic get request that supports callbacks
|
11
|
+
flok.net.request = function(verb, url, params, completion) {
|
12
|
+
//Store callback in the table
|
13
|
+
var socketIndex = flok.net.socketIndex++
|
14
|
+
flok.net.callbackTable[socketIndex] = true
|
15
|
+
|
16
|
+
$.ajax({
|
17
|
+
url: url,
|
18
|
+
type: verb,
|
19
|
+
data: params,
|
20
|
+
success: function(data) {
|
21
|
+
data = JSON.parse(data);
|
22
|
+
completion = completion || function() {}
|
23
|
+
if (completion != null) {
|
24
|
+
//Callback if possible
|
25
|
+
if (flok.net.callbackTable[socketIndex] === true) {
|
26
|
+
delete flok.net.callbackTable[socketIndex];
|
27
|
+
completion(data, false);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
},
|
31
|
+
error: function(xhr, status, err) {
|
32
|
+
if (flok.net.callbackTable[socketIndex] === true) {
|
33
|
+
delete flok.net.callbackTable[socketIndex];
|
34
|
+
completion({"message":status}, true);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
})
|
38
|
+
|
39
|
+
return socketIndex
|
40
|
+
}
|
41
|
+
|
42
|
+
flok.net.cancel_request = function(socket) {
|
43
|
+
res = flok.net.callbackTable[socket];
|
44
|
+
//Clear callback
|
45
|
+
delete flok.net.callbackTable[socket]
|
46
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
/*drivers = window.drivers || {}*/
|
2
|
+
//drivers.ui = {}
|
3
|
+
|
4
|
+
////Create a new surface based on a prototype name and information. Should return a surface pointer
|
5
|
+
//drivers.ui.createSurface = function(protoName, info) {
|
6
|
+
//var $proto = $("#surface-prototypes").find(".surface[data-name=\'"+protoName+"\']");
|
7
|
+
//if ($proto.length === 0) {
|
8
|
+
//throw "Couldn't find a surface prototype named: \(protoName)";
|
9
|
+
//}
|
10
|
+
|
11
|
+
////Get a UUID, move the surface to the 'body' element and hidden
|
12
|
+
//var uuid = UUID()
|
13
|
+
//$proto.attr("data-uuid", uuid);
|
14
|
+
//$("body").append($proto[0].outerHTML);
|
15
|
+
//$proto.removeAttr("data-uuid");
|
16
|
+
|
17
|
+
//$sel = $("[data-uuid='" + uuid + "']");
|
18
|
+
//$sel.addClass("hidden");
|
19
|
+
|
20
|
+
////Does this have a controller?
|
21
|
+
//var scc = drivers.ui.scc[protoName];
|
22
|
+
|
23
|
+
//(function() {
|
24
|
+
//var _sel = $sel;
|
25
|
+
//var p = pipe(function(msg) {
|
26
|
+
//console.log("CLICKED!");
|
27
|
+
//if (msg === "sign_in_clicked") {
|
28
|
+
//var source = drivers.ui.createSurface("nav_container", {color: "blue"});
|
29
|
+
//var source2 = drivers.ui.createSurface("login", {color: "blue"});
|
30
|
+
//drivers.ui.embedSurface(source, $("#root-surface"), "main", false, null);
|
31
|
+
//drivers.ui.embedSurface(source2, source, "content", false, null);
|
32
|
+
|
33
|
+
//} else if (msg === "login") {
|
34
|
+
//var source = drivers.ui.createSurface("loading");
|
35
|
+
//drivers.ui.embedSurface(source, $("#root-surface"), "main", false, null);
|
36
|
+
|
37
|
+
//var callback = function() {
|
38
|
+
//alert("error!");
|
39
|
+
//var source = drivers.ui.createSurface("nav_container", {color: "blue"});
|
40
|
+
//var source2 = drivers.ui.createSurface("login", {color: "blue"});
|
41
|
+
//drivers.ui.embedSurface(source, $("#root-surface"), "main", false, null);
|
42
|
+
//drivers.ui.embedSurface(source2, source, "content", false, null);
|
43
|
+
//}
|
44
|
+
//setTimeout(callback, 400);
|
45
|
+
|
46
|
+
//} else {
|
47
|
+
//var source = drivers.ui.createSurface("splash");
|
48
|
+
//drivers.ui.embedSurface(source, $("#root-surface"), "main", false, null);
|
49
|
+
//}
|
50
|
+
//});
|
51
|
+
|
52
|
+
//if (scc != undefined) {
|
53
|
+
//new scc($sel, info, p);
|
54
|
+
//}
|
55
|
+
//})();
|
56
|
+
|
57
|
+
////Our surface pointers are selectors
|
58
|
+
//return $sel
|
59
|
+
//}
|
60
|
+
|
61
|
+
////Delete a surface which removes it from the UI
|
62
|
+
//drivers.ui.deleteSurface = function(sp) {
|
63
|
+
//sp.remove();
|
64
|
+
//}
|
65
|
+
|
66
|
+
////Embed a surface into another surface in the view with the correct name
|
67
|
+
////source_sp - The surface we are embedding
|
68
|
+
////dest_sp - The surface we are embedding into
|
69
|
+
////animated - If true, a segue is allowed to take place
|
70
|
+
////animationDidComplete - Call this funtction if animated is true when you are done animating.
|
71
|
+
//drivers.ui.embedSurface = function(source_sp, dest_sp, viewName, animated, animationDidComplete) {
|
72
|
+
////Lookup view selector
|
73
|
+
//var $view = dest_sp.find(".view[data-name=" + viewName + "]");
|
74
|
+
//if ($view.length === 0) {
|
75
|
+
//throw "Found surface, but couldn't find a view *inside* a surface named: " + viewName;
|
76
|
+
//}
|
77
|
+
|
78
|
+
//$view.html("");
|
79
|
+
//source_sp.appendTo($view);
|
80
|
+
//source_sp.removeClass('hidden');
|
81
|
+
//}
|
82
|
+
|
83
|
+
////Surface controller constructors
|
84
|
+
//drivers.ui.scc = {};
|
85
|
+
//drivers.ui.regController = function(surfaceName, constructor) {
|
86
|
+
//drivers.ui.scc[surfaceName] = constructor;
|
87
|
+
/*}*/
|
File without changes
|
data/app/kern/hello.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
//console.log("Hello world");
|
data/docs/compilation.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Compliation
|
2
2
|
|
3
|
-
Compilation is handled by the `rake
|
4
|
-
Compilation *always* results in a `./products/$PLATFORM/application.js` file along with other files in `./products/$PLATFORM/` that
|
3
|
+
Compilation is handled by the `rake build_world PLATFORM=YOUR_PLATFORM` and then end result of that compliation is put in ./products/
|
4
|
+
Compilation *always* results in a `./products/$PLATFORM/application.js` file along with other files in `./products/$PLATFORM/drivers/` that
|
5
5
|
were deemed necessary by the platform driver `build` scripts.
|
6
6
|
|
7
7
|
### Build Order
|
@@ -10,11 +10,8 @@ as necessary.*
|
|
10
10
|
|
11
11
|
### Compilation is accomplished in the following order.
|
12
12
|
|
13
|
-
1.
|
14
|
-
2.
|
15
|
-
3.
|
16
|
-
4. All js files
|
17
|
-
5.
|
18
|
-
6. All js files in `./app/user/config/*.js` are globbed togeather and sent to `./products/$PLATFORM/glob/3user_config.js`
|
19
|
-
7. All js files in `./app/user/*.js` are globbed togeather and sent to `./products/$PLATFORM/glob/4user.js`
|
20
|
-
8. All js files are globbed from `./products/$PLATFORM/glob` and combined into `./products/$PLATFORM/application.js`
|
13
|
+
1. `rake build` is run inside `./app/drivers/$PLATFORM` with the environmental variables set to BUILD_PATH=`./produts/$PLATFORM/driver` (and folder
|
14
|
+
2. All js files in `./app/kern/config/*.js` are globbed togeather and sent to `./products/$PLATFORM/glob/1kern_config.js`
|
15
|
+
3. All js files in `./app/kern/*.js` are globbed togeather and sent to `./products/$PLATFORM/glob/2kern.js`
|
16
|
+
4. All js files are globbed from `./products/$PLATFORM/glob` and combined into `./products/$PLATFORM/application.js`
|
17
|
+
5. Auto-generated code is placed at the end (like uname_p)
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#Driver Interface
|
2
|
+
|
3
|
+
**This file contains a lot of information duplicated in [platform drivers](./platform_drivers.md)**
|
4
|
+
|
5
|
+
There is no standard communication protocol or interface for drivers. The driver stack operates by
|
6
|
+
|
7
|
+
1. The platform drivers bundle, e.g. `./app/drivers/CHROME/` will declare it's `ifaces` in `config.yml`
|
8
|
+
2. During compilation, the `application.js` file is embedded with `lsiface()`
|
9
|
+
3. Your application may now use `lsiface()` to dynamically alter it's behavior to be suitable. The application may then make function calls that are specified in the `./app/drivers/iface/$YOUR_INTERFACE.js`.
|
10
|
+
|
11
|
+
#What are Driver Interfaces?
|
12
|
+
An interface is just a javascript file with a set of function definitions a-lot like C header files. They are located in `./app/drivers/iface`. These are not actually used in your compiled program but serve as a reference to other developers on how to implement your interface. We have future plans to use the interface files themselves so please, please, please... implement the interface files.
|
13
|
+
|
14
|
+
Here is an example interface file for a printer.
|
15
|
+
|
16
|
+
```js
|
17
|
+
//./app/drivers/iface/printer.js
|
18
|
+
//This interface provides printing capabilities
|
19
|
+
|
20
|
+
//Print a document out from a string, returns a opaque print job pointer. (job)
|
21
|
+
function if_print(str) {}
|
22
|
+
|
23
|
+
//Cancel a currently queued print.
|
24
|
+
function if_cancel_print(job) {}
|
25
|
+
```
|
26
|
+
|
27
|
+
**Note the 'if_' infront of each function's name, this stands for interface and must be used on all interface functions**.
|
28
|
+
|
29
|
+
As you can see, there is no implementation in this code. This is not just an abbreviated example, this is the entire interface file. For each platform, you will now have to do two things to use this driver.
|
30
|
+
|
31
|
+
1. You must add this driver to your driver's `config.yml` file in the `ifaces`. In this case, you would add `printer` to the `ifaces` array.
|
32
|
+
2. You must ensure that when the application makes a call to any functions declared in the interface, they are handled appropriately. For full javascripts systems (like HTML5), this is accomplished by simply defining the needed functions. For other platforms that use native code, the functions are usually implemented by exporting a native function into the javascript space.
|
33
|
+
|
34
|
+
```swift
|
35
|
+
let if_print: @objc_block String -> Int = { str in
|
36
|
+
var mutableString = NSMutableString(string: str) as CFMutableStringRef
|
37
|
+
/*
|
38
|
+
-------------------------
|
39
|
+
Execute print code here
|
40
|
+
-------------------------
|
41
|
+
*/
|
42
|
+
|
43
|
+
return printPointer;
|
44
|
+
}
|
45
|
+
|
46
|
+
context.setObject(unsafeBitCast(if_print, AnyObject.self), forKeyedSubscript: "if_print")
|
47
|
+
```
|
48
|
+
|
49
|
+
#Writing good driver interfaces
|
50
|
+
A good driver interface, and driver for that matter, implement no logic beyond what is necessary for the completion of that action. There are exceptions to this rule and they usually are around performant code where it is necessary to use native drivers to number crunch, parse, etc.
|
51
|
+
|
52
|
+
#States & Opaque Pointers
|
53
|
+
If it can be avoided, it is best to avoid using any state information in your drivers. Opaque pointers can assist with this. E.g. the `if_print` function as described above returns an `opaque pointer` that is compatible with `if_cancel_print`. The driver that implements this interface is free to implement opaque pointers in any way that seems sensible. The only restriction is that the pointers are able to be read by javascript itself and regurgetated in a useful form. Try to avoid using a hash table if possible if you can directly feed native pointers as there are performance benefits and less state information.
|
54
|
+
|
55
|
+
------
|
56
|
+
|
57
|
+
|
58
|
+
#Dynamic Drivers
|
59
|
+
Flok does not currently support dypnamic driver attachment or probing like many operating systems, e.g. Freebsd's `kldload`. If you need the ability to probe dynamically, for example, some devices support *LTE Bleuetooth Activity Trackers*, then it would be best to create a driver interface called `sensors` which would tell you if any `LTE Bluetooth Activity Trackers` are available.
|
60
|
+
|
61
|
+
|
data/docs/interface.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
#Kernel Interface
|
2
|
+
|
3
|
+
### Information added into javascript during compilation
|
4
|
+
* `IFACES` - An array of strings representing the interfaces the driver supported (through config.yml). Static compiled at end.
|
5
|
+
* `PLATFORM` - A string that represents the current platform name
|
data/docs/platform_drivers.md
CHANGED
@@ -30,6 +30,7 @@ ifaces:
|
|
30
30
|
- ui
|
31
31
|
- network
|
32
32
|
```
|
33
|
+
You may access this list in a compiled kernel via `lsiface()`. See functions for more info.
|
33
34
|
|
34
35
|
### Platform specifics
|
35
36
|
See the ./app/drivers/$PLATFORM/README.md file for information on each individual platforms specifics.
|
data/docs/project_layout.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Project layout
|
2
2
|
* app/ - All actual pieces of the kernel code sit here.
|
3
3
|
* app/drivers - Parts of (a) and (b)
|
4
|
-
* app/drivers/
|
5
|
-
* app/drivers/$PLATFORM - Platform specific way to implement the interface. See
|
4
|
+
* app/drivers/iface- Generic interfaces that are suggested to be implemented.
|
5
|
+
* app/drivers/$PLATFORM/ - Platform specific way to implement the interface. See [platform drivers](./platform_drivers.md) for information.
|
6
|
+
* app/kern - The remaining part, your app, the kernel, etc. all live under here.
|
data/docs/testing.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Testing
|
data/flok.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_development_dependency "execjs", "~> 2.5"
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
23
|
spec.add_development_dependency "rake", "~> 10.3"
|
23
24
|
spec.add_development_dependency "rspec", "~> 3.2"
|
data/lib/flok.rb
CHANGED
@@ -1,45 +1,5 @@
|
|
1
1
|
require "flok/version"
|
2
|
+
require "flok/build"
|
2
3
|
|
3
4
|
module Flok
|
4
|
-
module MergeSource
|
5
|
-
#Merge all the kernel javascript files into one string
|
6
|
-
def self.merge_kernel
|
7
|
-
Dir.chdir(File.dirname(__FILE__)) do
|
8
|
-
#Embed drivers
|
9
|
-
Dir.chdir("../app/drivers/browser") do
|
10
|
-
`rake build`
|
11
|
-
end
|
12
|
-
out = File.read("../products/drivers/browser.js")
|
13
|
-
|
14
|
-
Dir.chdir("./js/kernel/") do
|
15
|
-
js_files = Dir["*.js"]
|
16
|
-
js_files.each do |js|
|
17
|
-
out << File.read(js)
|
18
|
-
out << "\n"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
return out
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.merge_user_app
|
28
|
-
js_files = Dir["./app/*.js"]
|
29
|
-
out = ""
|
30
|
-
js_files.each do |js|
|
31
|
-
out << File.read(js)
|
32
|
-
out << "\n"
|
33
|
-
end
|
34
|
-
|
35
|
-
return out
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.merge_all
|
39
|
-
str_kernel = self.merge_kernel
|
40
|
-
str_user = self.merge_user_app
|
41
|
-
|
42
|
-
return str_kernel + "\n" + str_user
|
43
|
-
end
|
44
|
-
end
|
45
5
|
end
|