rubink 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rubink.rb ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+ ################################################################################
3
+ # Rubink (Ruby Ink)
4
+ # Author: Peter Lamber
5
+ #
6
+ # Usage:
7
+ # rubink "path_to_your_script.rb"
8
+ #
9
+ # Example:
10
+ # bin/rubink example/wormpainter.rb
11
+ #
12
+ # Does 2 things:
13
+ # Compiles the ruby script into javascript
14
+ # Creates a main_your_script_name.html with compiled script ready to run
15
+ #
16
+ # CAUTION: Generated files overwrite previous script if the same name was given
17
+ #
18
+ ################################################################################
19
+
20
+ require 'opal'
21
+
22
+ class Rubink
23
+ class << self
24
+
25
+ def build(script)
26
+ @script = script
27
+
28
+ return if invalid
29
+
30
+ @app_name = File.basename(script,"rb")
31
+
32
+ root = File.expand_path '../..', __FILE__
33
+
34
+ Opal.append_path "."
35
+ Opal.append_path root+"/lib"
36
+
37
+ src = ""
38
+
39
+ #Adding Libraries first
40
+ src << IO.binread(root+"/lib/processing.js")
41
+ src << IO.binread(root+"/lib/hammer.js")
42
+
43
+ #Compile Rubink, script and wire it up
44
+ src << Opal::Builder.build("app").to_s
45
+ src << Opal::Builder.build(script).to_s
46
+ src << Opal::Builder.build("start").to_s
47
+
48
+ File.binwrite "app_#{@app_name}js", src
49
+ File.binwrite "main_#{@app_name}html", main_html_template
50
+ puts "main_#{@app_name}html was generated"
51
+ end
52
+
53
+ def invalid
54
+ if @script.nil?
55
+ puts "Stopping, no script given, provide script path"
56
+ return true
57
+ end
58
+
59
+ unless File.exist?(@script)
60
+ puts "Stopping, invalid filename"
61
+ return true
62
+ end
63
+ end
64
+
65
+ def main_html_template
66
+ "<meta charset='utf-8'> <canvas style='outline:none' id='canvas'></canvas> <script src='app_#{@app_name}js'></script>"
67
+ end
68
+
69
+ def run
70
+
71
+ opal_v = %x( opal -v )
72
+
73
+ if opal_v
74
+ puts "Rubink is working on it"
75
+ build(ARGV[0])
76
+ else
77
+ puts "Stopping, Opal not found. Please first run:"
78
+ puts "gem insall opal"
79
+ end
80
+
81
+ end
82
+ end
83
+ end
data/lib/start.js ADDED
@@ -0,0 +1,49 @@
1
+ var canvas = document.getElementById('canvas');
2
+
3
+ function sketchProc(processing) {
4
+
5
+ window.p = processing
6
+
7
+ var a = Opal.App.$new();
8
+
9
+ window.a = a
10
+
11
+ processing.setup = function() {
12
+ a.$setup();
13
+ };
14
+
15
+ processing.draw = function() {
16
+ a.$draw();
17
+ };
18
+
19
+ processing.mousePressed = function() {
20
+ a.$mousePressed();
21
+ };
22
+
23
+ processing.mouseReleased = function() {
24
+ a.$mouseReleased();
25
+ };
26
+
27
+ processing.mouseClicked = function() {
28
+ a.$mouseClicked();
29
+ };
30
+
31
+ processing.mouseMoved = function() {
32
+ a.$mouseMoved();
33
+ };
34
+
35
+ processing.keyPressed = function() {
36
+ a.$keyPressed();
37
+ };
38
+
39
+
40
+ }
41
+
42
+ window.sketchProc = sketchProc
43
+ var mc = new Hammer(canvas);
44
+
45
+ mc.on("panmove", function(ev) {
46
+ a.$drag(ev.center.x,ev.center.y);
47
+ });
48
+
49
+ new Processing(canvas, window.sketchProc);
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Lamber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ description: Write animations with ruby
28
+ email: peter.lamber@protonmail.com
29
+ executables:
30
+ - rubink
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - bin/rubink
35
+ - lib/app.rb
36
+ - lib/hammer.js
37
+ - lib/opal.js
38
+ - lib/processing.js
39
+ - lib/rubink.rb
40
+ - lib/start.js
41
+ homepage: http://rubygems.org/gems/rubink
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.5.1
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Rubink
65
+ test_files: []