atome 0.1.00003 → 0.1.00009

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f5aa7876378282b20cc7aa36bb398fe6c0e2ce86186cc3cdea4491c6eb2ea40
4
- data.tar.gz: 4055a80485e3893754089b4f4206575c87ac0ff75edc7c57e58b5cd647337185
3
+ metadata.gz: f4b48cdeb89c228abfd54f7ff8a986bf57b856ee448248f8bc72d350f2102f92
4
+ data.tar.gz: 684ee3dbfb0c2f8a630203b70c76fee2c4bbc38e668236eb39ce4031fce07ad0
5
5
  SHA512:
6
- metadata.gz: 48c07c0594d5661cd3128f6097a5a72f83deb8303c3b3a57f15d17f1e1120f154dfd2d080905456ffcf39c42234705f7431266312398e9d17dd9100ea69369cc
7
- data.tar.gz: b5448c3e113016a6c4267d6e93ac9c98fc550f57d38889e0ec7ed483d661d4481dc308543eddc716117acd5cc16ebc98a4084708cabdfbf28a31fb5482d9bddb
6
+ metadata.gz: abce3a0481ef173040bff4c5753ddc0da3429b62b9d25c6b60b3dd87751b582d3c917fb84ed56b97b684fe8066ff99882f7be57a1530529f32eee02666fa2781
7
+ data.tar.gz: e1addd8946eed935d0becf3b612969387f6107271819913fc62a8fe0f633ed13f485974195f77f74f28c03e95c412af39171336efcde841683e3ee84337eef29
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'opal'
4
+ require 'opal-jquery'
5
+ require 'opal-browser'
6
+ require 'parser'
7
+ require 'uglifier'
8
+
9
+ Opal.append_path 'app'
10
+
11
+ def build_opal_browser(user_project_path, production = false)
12
+ browser_js = "#{user_project_path}/build/js/opal/opal_browser.js"
13
+ browser_content = Opal::Builder.build('../lib/atome/renderers/opal/opal_browser.rb').to_s
14
+ browser_content.gsub!("$$$('STDERR')['$write_proc='](typeof(process) === 'object' && typeof(process.stderr) === 'object' ? function(s){process.stderr.write(s)} : function(s){console.warn(s)});", "$$$('STDERR')['$write_proc='](typeof(process) === 'object' && typeof(process.stderr) === 'object' ? function(s){process.stderr.write(s)} : function(s){});")
15
+ browser_content = Uglifier.new.compile(browser_content) if production
16
+ File.open(browser_js, 'w') do |f|
17
+ f.puts browser_content
18
+ end
19
+ end
20
+
21
+ def build_atome_kernel(user_project_path, gem_location, production = false)
22
+ kernel_js = "#{user_project_path}/build/js/atome/kernel.js"
23
+ builder = Opal::Builder.new
24
+ builder.append_paths("#{gem_location}/../lib/")
25
+ kernel_content = builder.build("#{gem_location}/../lib/atome.rb").to_s
26
+ kernel_content = Uglifier.new.compile(kernel_content) if production
27
+ File.open(kernel_js, 'w') do |f|
28
+ f.puts kernel_content
29
+ end
30
+ end
31
+
32
+ def build_opal_parser(user_project_path, production = false)
33
+ parser_js = "#{user_project_path}/build/js/opal/opal_parser.js"
34
+ parser_content = Opal::Builder.build('../lib/atome/renderers/opal/opal_parser.rb').to_s
35
+ parser_content = Uglifier.new.compile(parser_content) if production
36
+ File.open(parser_js, 'w') do |f|
37
+ f.puts parser_content
38
+ end
39
+ end
40
+
41
+ def build_user_code(user_project_path, production = false)
42
+ application_js = "#{user_project_path}/build/js/application.js"
43
+ application_content = Opal::Builder.build('../vendor/assets/index.rb').to_s
44
+ application_content = Uglifier.new.compile(application_content) if production
45
+ File.open(application_js, 'w') do |f|
46
+ f.puts application_content
47
+ end
48
+ end
49
+
50
+ task :system_builder do
51
+ # change to false for not production mode and faster compile time
52
+ production = false
53
+ user_project_path = ARGV[1]
54
+ gem_location = File.join(File.dirname(__FILE__))
55
+ build_atome_kernel(user_project_path, gem_location, production)
56
+ build_opal_browser(user_project_path, production)
57
+ build_opal_parser(user_project_path, production)
58
+ build_user_code(user_project_path, production)
59
+ end
60
+
61
+ task :build do
62
+ puts 'nothing for now'
63
+ end
64
+
65
+ task default: :build
data/exe/atome CHANGED
@@ -1,16 +1,63 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'atome'
5
4
  require 'fileutils'
6
5
 
6
+ def delete_all(dir)
7
+ Dir.foreach(dir) do |e|
8
+ # Don't bother with . and ..
9
+ next if %w[. ..].include? e
10
+ fullname = dir + File::Separator + e
11
+ if FileTest.directory?(fullname)
12
+ delete_all(fullname)
13
+ else
14
+ File.delete(fullname)
15
+ end
16
+ end
17
+ Dir.delete(dir)
18
+ end
19
+
20
+ def run(option = :browser, location = nil)
21
+ case option
22
+ when :server
23
+ require 'atome'
24
+ if location
25
+ `cd ./#{location}/server;rackup --server puma --port 9292 --env production`
26
+ else
27
+ `cd ./server;rackup --server puma --port 9292 --env production`
28
+ end
29
+ when :browser
30
+ if location
31
+ `cd ./#{location}/build;open index.html`
32
+ else
33
+ `cd ./build;open index.html`
34
+ end
35
+ when :osx
36
+ require 'webview_ruby'
37
+ webview = WebviewRuby::Webview.new
38
+ webview.set_title('atome')
39
+ webview.set_size(480, 360)
40
+ if location
41
+ webview.navigate("file:/#{`pwd`}/#{location}/build/index.html")
42
+ else
43
+ webview.navigate("file:#{`pwd`.chomp}/build/index.html")
44
+ end
45
+ webview.run
46
+ else
47
+ # nothing for now
48
+ end
49
+
50
+ end
51
+
7
52
  case ARGV[0]
8
53
  when 'create'
9
54
  project_name = ARGV[1]
55
+ force = ARGV[2]
56
+ delete_all(project_name) if force == 'force'
10
57
  Dir.mkdir project_name.to_s
11
58
  current_path = `pwd`.chomp
12
59
  gem_assets_location = File.join(File.dirname(__FILE__), '../vendor/assets/')
13
- gem_run_helpers = File.join(File.dirname(__FILE__), '../run_helpers')
60
+ app_builder_helpers = File.join(File.dirname(__FILE__), '../app_builder_helpers')
14
61
  target_template_location = "#{current_path}/#{project_name}"
15
62
  Dir.entries(gem_assets_location).select do |entry|
16
63
  if File.join(entry) && !%w[. ..].include?(entry)
@@ -19,26 +66,24 @@ when 'create'
19
66
  end
20
67
  end
21
68
  # now run the rake task to build the needed libraries (atome, renderers, etc...)
22
- `cd #{gem_run_helpers};rake system_builder #{current_path}/#{project_name}`
23
- # `cd #{project_name};bundle update`
24
- # `cd #{project_name};bundle install`
25
- # `cd #{project_name};bundle exec guard`
69
+ `cd #{app_builder_helpers};rake system_builder #{current_path}/#{project_name}`
70
+ run(:server, project_name)
26
71
  when 'run'
27
- case ARGV[0]
28
- when :android
29
- when :browser
30
- when :freebsd
31
- when :ios
32
- when :linux
33
- when :osx
34
- when :server
35
- when :windows
72
+ case ARGV[1]
73
+ when 'android'
74
+ when 'browser'
75
+ run(:browser)
76
+ when 'freebsd'
77
+ when 'ios'
78
+ when 'linux'
79
+ when 'osx'
80
+ run(:osx)
81
+ when 'server'
82
+ run(:server)
83
+ when 'windows'
36
84
  else
37
85
  # type code here
38
86
  end
39
-
40
- when 'build'
41
- # puts "first parameter is : #{ARGV[1]}"
42
- # puts "second parameter is : #{ARGV[2]}"
43
- # puts 'run command'
87
+ else
88
+ # type code here
44
89
  end
@@ -1,44 +1,2 @@
1
1
  # frozen_string_literal: true
2
-
3
- # this class hold all created atomes
4
-
5
-
6
- class Universe
7
- def self.initialize
8
- Atome.new({ type: :user })
9
- end
10
-
11
- def self.atomes_add(new_atome)
12
- @atomes << new_atome
13
- end
14
-
15
- class << self
16
- attr_reader :atomes
17
- end
18
-
19
- def self.connected
20
- true
21
- end
22
- end
23
-
24
- # this class build atomes
25
- class Atome
26
- include AtomeDummyMethods
27
-
28
- def initialize(params = {})
29
- puts "the object id is : #{object_id} , #{params}"
30
- end
31
-
32
- def properties_common(value, current_property, stack_property, optional_processor)
33
- puts "#{value}, #{current_property}, #{stack_property}, #{optional_processor}"
34
- end
35
- end
36
- # Universe.initialize
37
- Universe.connected
38
-
39
- puts Universe.atomes
40
-
41
- Atome.new({ top: 22 })
42
- Atome.new({ top: 22 })
43
- a = Atome.new({ top: 22 })
44
- a.left(33)
2
+ # here is the atome kernel
@@ -1,112 +1,2 @@
1
-
2
- module AtomeDummyMethods
3
-
4
- # def dummy(value = nil, stack_property = nil)
5
- # property = :dummy
6
- # optional_processor = { pre_process: true, post_process: true, store_atome: false, render_atome: false }
7
- # properties_common(property, value, stack_property, optional_processor)
8
- # end
9
- def universe(value = nil, stack_property = nil)
10
- property = :universe
11
- optional_processor = {}
12
- properties_common(property, value, stack_property, optional_processor)
13
- end
14
-
15
- def parent(value = nil, stack_property = nil)
16
- property = :parent
17
- optional_processor = { pre_process: true, post_process: true }
18
- properties_common(property, value, stack_property, optional_processor)
19
- end
20
-
21
- def left(value = nil, stack_property = nil)
22
- property = :left
23
- optional_processor = {}
24
- properties_common(property, value, stack_property, optional_processor)
25
- end
26
-
27
- def top(value = nil, stack_property = nil)
28
- property = :top
29
- optional_processor = {}
30
- properties_common(property, value, stack_property, optional_processor)
31
- end
32
- #
33
- # def bottom(value = nil, stack_property = nil)
34
- # property = :bottom
35
- # optional_processor = {}
36
- # properties_common(property, value, stack_property, optional_processor)
37
- # end
38
- #
39
- def right(value = nil, stack_property = nil)
40
- property = :right
41
- optional_processor = {}
42
- properties_common(property, value, stack_property, optional_processor)
43
- end
44
- #
45
- # def child(value = nil, stack_property = nil)
46
- # property = :child
47
- # optional_processor = {}
48
- # properties_common(property, value, stack_property, optional_processor)
49
- # end
50
- #
51
- # def id(value = nil, stack_property = nil)
52
- # property = :id
53
- # optional_processor = {}
54
- # properties_common(property, value, stack_property, optional_processor)
55
- # end
56
- #
57
- # def name(value = nil, stack_property = nil)
58
- # property = :name
59
- # optional_processor = {}
60
- # properties_common(property, value, stack_property, optional_processor)
61
- # end
62
- #
63
- # def view(value = nil, stack_property = nil)
64
- # property = :view
65
- # optional_processor = {}
66
- # properties_common(property, value, stack_property, optional_processor)
67
- # end
68
- #
69
- # def type(value = nil, stack_property = nil)
70
- # property = :type
71
- # optional_processor = {}
72
- # properties_common(property, value, stack_property, optional_processor)
73
- # end
74
- #
75
- # def preset(value = nil, stack_property = nil)
76
- # property = :preset
77
- # optional_processor = {}
78
- # properties_common(property, value, stack_property, optional_processor)
79
- # end
80
- #
81
-
82
- #
83
- # def red(value = nil, stack_property = nil)
84
- # property = :red
85
- # optional_processor = {}
86
- # properties_common(property, value, stack_property, optional_processor)
87
- # end
88
- #
89
- # def green(value = nil, stack_property = nil)
90
- # property = :green
91
- # optional_processor = {}
92
- # properties_common(property, value, stack_property, optional_processor)
93
- # end
94
- #
95
- # def blue(value = nil, stack_property = nil)
96
- # property = :blue
97
- # optional_processor = {}
98
- # properties_common(property, value, stack_property, optional_processor)
99
- # end
100
- #
101
- # def alpha(value = nil, stack_property = nil)
102
- # property = :alpha
103
- # optional_processor = {}
104
- # properties_common(property, value, stack_property, optional_processor)
105
- # end
106
- #
107
- # def radiation(value = nil, stack_property = nil)
108
- # property = :radiation
109
- # optional_processor = {}
110
- # properties_common(property, value, stack_property, optional_processor)
111
- # end
112
- end
1
+ # frozen_string_literal: true
2
+ # here are the geometry properties of atome
@@ -1,4 +0,0 @@
1
- # render methods
2
- module RenderHtml
3
-
4
- end
@@ -1,6 +0,0 @@
1
- module PropertyHtml
2
- def say_html(params)
3
- speech_dsp(params)
4
- end
5
-
6
- end
@@ -1,9 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # render methods
2
4
  require 'opal'
3
5
  require 'native'
4
6
  require 'promise'
5
- require 'browser/setup/full'
6
-
7
- module RenderHtml
8
-
9
- end
7
+ require 'browser/setup/full'
@@ -1 +1,2 @@
1
+ # frozen_string_literal: true
1
2
  require 'opal-parser'
@@ -1,6 +0,0 @@
1
- module PropertyHtml
2
- def say_html(params)
3
- speech_dsp(params)
4
- end
5
-
6
- end
data/lib/atome/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Atome
4
- VERSION = '0.1.00003'
4
+ VERSION = '0.1.00009'
5
5
  end
data/lib/atome.rb CHANGED
@@ -1,29 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'fileutils'
4
- require 'atome/version.rb'
5
- require 'atome/kernel/properties/geometry.rb'
6
- require 'atome/kernel/atome_genesis.rb'
7
- puts "look why this file code is executed\n"*9
8
- # current_path_location = `pwd`.chomp
9
- # temp_location = '/tmp/com.atome.one'
10
- # user_script_location=File.join(File.dirname(__FILE__), '../tmp/')
11
- # Dir.exist?( user_script_location )
12
- #
13
- # FileUtils.mkdir_p temp_location
14
- #
15
- # guard_content = <<~STR
16
- # guard 'rake', :task => 'build' do
17
- # watch(%r{^#{current_path_location}})
18
- # end
19
- # STR
20
- #
21
- # rakefile_content = <<~STR
22
- # task :build do
23
- #
24
- # end
25
- # STR
26
- # File.open("#{temp_location}/Guardfile", 'w') { |f| f.write(guard_content) }
27
- # File.open("#{temp_location}/Rakefile", 'w') { |f| f.write(rakefile_content) }
28
- # user_code = File.read("#{temp_location}/Guardfile")
29
-
4
+ require 'atome/version'
5
+ require 'atome/kernel/properties/geometry'
6
+ require 'atome/kernel/atome_genesis'
@@ -1,164 +1,166 @@
1
- # require "opal-jquery"
2
-
3
- # class Element
4
- # def self.create(tag = 'div', opt = {})
5
- # `jQuery('<'+tag+'/>',opt.$to_n())`
1
+ # def toto(e)
2
+ # e.prevent
3
+ # e.on.inner_text = "Super Clicked!"
4
+ # end
5
+ #
6
+ # $document.on(:mousedown, "#good") do |e|
7
+ # toto(e)
8
+ # end
9
+ # $document.on(:touchstart, "#good") do |e|
10
+ # toto(e)
11
+ # end
12
+ #
13
+ # verif = <<-STR
14
+ # $document.ready do
15
+ # DOM {
16
+ # div.info {
17
+ # span.red "Opal eval cooked up!"
18
+ # }
19
+ # }.append_to($document.body)
20
+ # end
21
+ # STR
22
+ #
23
+ # eval(verif)
24
+ #
25
+ #
26
+ # $document.body.style.apply {
27
+ # background color: 'black'
28
+ # color 'orange'
29
+ # font family: 'Verdana'
30
+ # }
31
+ # $document.ready do
32
+ # DOM {
33
+ # div.info {
34
+ # i=0
35
+ # while i< 20
36
+ # i+=1
37
+ # span(id: "good").red "Opal cooked up, click me #{i}"
38
+ # div(id: "hook").red "lllll#{i} --"
39
+ # end
40
+ # }
41
+ # }.append_to($document["user_view"])
42
+ #
43
+ # # alert($document.body.id)
44
+ # # $document.getElementById("hook").style.color("red")
45
+ # # bb=$document.find('header')
46
+ # bb=`document.getElementById('hook')`
47
+ # # a= $document.get_element_by_id(:hook)
48
+ # a= $document[:hook]
49
+ #
50
+ # elem = $document.at_css(".red").style(color: :yellow)
51
+ #
52
+ # $document.on :click do |e|
53
+ # elem.style(color: :yellowgreen)
54
+ # # elem.style.apply {
55
+ # # background color: 'blue'
56
+ # # color 'green'
57
+ # # font family: 'Verdana'
58
+ # # }
59
+ # # a.style.apply {
60
+ # # background color: 'red'
61
+ # # color 'black'
62
+ # # font family: 'Verdana'
63
+ # # }
6
64
  # end
65
+ #
66
+ # # bb =$document.id='hook'
67
+ # # bb= $document["hook"]
68
+ # # bb.on.inner_text"jsqhdgfjqhsdgfjqhsgdjhqsg Clicked!"
69
+ # # bb.style.apply {
70
+ # # background color: 'black'
71
+ # # color 'orange'
72
+ # # font family: 'Verdana'
73
+ # # }
74
+ #
75
+ # end
76
+ #
77
+ # $document.body.style.apply {
78
+ # background color: 'black'
79
+ # color 'orange'
80
+ # font family: 'Verdana'
81
+ # }
82
+ #
83
+ #
84
+ # def box(params={})
85
+ # DOM do
86
+ # el=div(id: "hook")
87
+ # el( ",jb,jb")
88
+ # end.append_to($document["user_view"])
89
+ #
7
90
  # end
8
91
  #
92
+ # box
93
+ #
94
+ # e=$document.at_css("#hook")
95
+ # e.style { background color: 'lime' }
96
+ # $document.at_css("#hook").style(color: :red)
97
+ # # Example 2
98
+ # DOM do
99
+ # div(id: "hook").red "lllll"
100
+ # div(id: "poil").red "kool"
101
+ # end.append_to($document["user_view"])
102
+ # elem = $document.css("#poil").style(color: :orange)
103
+ #
104
+ # # #Example 3
9
105
  # def box(params = {})
10
- # # el = Element.new(:div)
11
- # el = Element.create(:div, { id: 'some_big_id',
12
- # class: 'some-class some-other-class',
13
- # title: 'now this div has a title!' })
14
- # # el.text("kjh")
15
- # Element.find('#user_view').append(el)
16
- # el.css(:color, :red).css( "box-shadow": "0px 0px 9px red")
17
- # .css(:width, 33).css(:height, 33).css(:position, "absolute").css(:left, "33px").css(:top, "33px")
18
- # .css( 'border-radius', '3px 6px 3px 6px')
19
- #
20
- # el.on(:click) do
21
- # el.css("background-color", "yellowgreen")
22
- # el.text(el.css("background-color"))
23
- # end
106
+ # params = { color: :pink, width: 100, height: 100 }.merge(params)
107
+ # DOM do
108
+ # div(id: "hook",
109
+ # class: :toto,
110
+ # style: "background-color: #{params[:color]};
111
+ # width: #{params[:width]}px;
112
+ # height: #{params[:height]}px;
113
+ # box-shadow: #{params[:shadow]};
114
+ # ")
115
+ # .the_class
116
+ # end.append_to($document["user_view"])
117
+ # end
118
+ #
119
+ # window_height= $window.view.height/12
120
+ # window_width= $window.view.width/12
121
+ # box({ color: :green, shadow: "0px 0px 10px black;" })
122
+ # $document.body['foo'] = 'bar'
123
+ #
124
+ #
125
+ # $window.on :resize do |e|
126
+ # puts $window.view.height
127
+ # puts $window.view.width
128
+ # puts "------"
129
+ # # alert $document.body.width
24
130
  # end
25
- # alert :kool
26
- # box({ width: 33, height: 33, smooth: 6, shadow: { blur: 6, x: 6, y: 6, invert: false, thickness: 0, bounding: true, color: :black } })
131
+ #
132
+ # puts $document.search('div').size
133
+ # # $document.search('div')['foo'] = 'bar'
134
+ #
135
+ #
27
136
 
28
137
 
29
138
 
30
- def toto(e)
31
- e.prevent
32
- e.on.inner_text = "Super Clicked!"
33
- end
139
+ # require 'browser/socket'
34
140
 
35
- $document.on(:mousedown, "#good") do |e|
36
- toto(e)
37
- end
38
- $document.on(:touchstart, "#good") do |e|
39
- toto(e)
141
+ ws =Browser::Socket.new 'ws://127.0.0.1:9292'
142
+ ws.on :open do
40
143
  end
41
144
 
42
- verif = <<-STR
43
- $document.ready do
44
- DOM {
45
- div.info {
46
- span.red "Opal eval cooked up!"
47
- }
48
- }.append_to($document.body)
49
- end
50
- STR
51
-
52
- eval(verif)
53
-
54
-
55
- $document.body.style.apply {
56
- background color: 'black'
57
- color 'orange'
58
- font family: 'Verdana'
59
- }
60
- $document.ready do
61
- DOM {
62
- div.info {
63
- i=0
64
- while i< 20
65
- i+=1
66
- span(id: "good").red "Opal cooked up, click me #{i}"
67
- div(id: "hook").red "lllll#{i} --"
68
- end
69
- }
70
- }.append_to($document["user_view"])
71
-
72
- # alert($document.body.id)
73
- # $document.getElementById("hook").style.color("red")
74
- # bb=$document.find('header')
75
- bb=`document.getElementById('hook')`
76
- # a= $document.get_element_by_id(:hook)
77
- a= $document[:hook]
78
-
79
- elem = $document.at_css(".red").style(color: :yellow)
80
-
81
- $document.on :click do |e|
82
- elem.style(color: :yellowgreen)
83
- # elem.style.apply {
84
- # background color: 'blue'
85
- # color 'green'
86
- # font family: 'Verdana'
87
- # }
88
- # a.style.apply {
89
- # background color: 'red'
90
- # color 'black'
91
- # font family: 'Verdana'
92
- # }
93
- end
94
-
95
- # bb =$document.id='hook'
96
- # bb= $document["hook"]
97
- # bb.on.inner_text"jsqhdgfjqhsdgfjqhsgdjhqsg Clicked!"
98
- # bb.style.apply {
99
- # background color: 'black'
100
- # color 'orange'
101
- # font family: 'Verdana'
102
- # }
103
-
145
+ ws.on :message do |e|
146
+ alert e.data
104
147
  end
105
148
 
106
- $document.body.style.apply {
107
- background color: 'black'
108
- color 'orange'
109
- font family: 'Verdana'
110
- }
111
-
112
-
113
- def box(params={})
114
- DOM do
115
- el=div(id: "hook")
116
- el( ",jb,jb")
117
- end.append_to($document["user_view"])
118
149
 
150
+ def send_message(socket,msg)
151
+ if socket.alive?
152
+ socket.send(msg )
153
+ else
154
+ after 0.1 do
155
+ send_message(socket,msg)
156
+ end
119
157
  end
120
158
 
121
- box
122
-
123
- e=$document.at_css("#hook")
124
- e.style { background color: 'lime' }
125
- $document.at_css("#hook").style(color: :red)
126
- # Example 2
127
- DOM do
128
- div(id: "hook").red "lllll"
129
- div(id: "poil").red "kool"
130
- end.append_to($document["user_view"])
131
- elem = $document.css("#poil").style(color: :orange)
132
-
133
- # #Example 3
134
- def box(params = {})
135
- params = { color: :pink, width: 100, height: 100 }.merge(params)
136
- DOM do
137
- div(id: "hook",
138
- class: :toto,
139
- style: "background-color: #{params[:color]};
140
- width: #{params[:width]}px;
141
- height: #{params[:height]}px;
142
- box-shadow: #{params[:shadow]};
143
- ")
144
- .the_class
145
- end.append_to($document["user_view"])
146
159
  end
147
160
 
148
- window_height= $window.view.height/12
149
- window_width= $window.view.width/12
150
- box({ color: :green, shadow: "0px 0px 10px black;" })
151
- $document.body['foo'] = 'bar'
152
-
153
-
154
- $window.on :resize do |e|
155
- puts $window.view.height
156
- puts $window.view.width
157
- puts "------"
158
- # alert $document.body.width
159
- end
161
+ my_msg={ foo: "bar" }
162
+ my_msg=JSON.generate(my_msg)
163
+ send_message(ws,my_msg)
160
164
 
161
- puts $document.search('div').size
162
- # $document.search('div')['foo'] = 'bar'
163
165
 
164
166
 
@@ -1,13 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ # atome server
2
3
 
3
- # instructions to install :
4
- # gem install bundler roda sqlite3 sequel rack-unreloader faye-websocket websocket-extensions websocket-driver puma -N
5
- # important if crash the gem install rack-unreloader -v 1.7.0 gem install roda -v 2.26.0
6
- # bundle update
7
- # bundle install
8
- # to run: rackup --server puma --port 4567 or without puma : rackup -p 4567
9
-
10
- # puts RUBY_VERSION
11
4
  if RUBY_PLATFORM == "x64-mingw32"
12
5
  require "em/pure_ruby"
13
6
  end
@@ -19,9 +12,6 @@ require "json"
19
12
  require "securerandom"
20
13
  require "mail"
21
14
  require "digest"
22
- require "filewatcher"
23
-
24
-
25
15
 
26
16
  class String
27
17
  def is_json?
@@ -34,12 +24,6 @@ class String
34
24
  end
35
25
 
36
26
  class App < Roda
37
-
38
- @@channels = {}
39
- @@user
40
- @@test_socket = []
41
-
42
- #plugin :mail_processor
43
27
  eden = Sequel.connect("sqlite://eden.sqlite3")
44
28
  unless File.exist?("eden.sqlite3")
45
29
  eden.create_table :objects do
@@ -50,248 +34,28 @@ class App < Roda
50
34
  String :content
51
35
  end
52
36
  end
37
+ index_content = File.read("../build/index.html")
53
38
 
54
- index_content = File.read("../view/index.html")
55
-
56
- # index_content = index_content.gsub('<script type="text/javascript" src="../cordova.js"></script>', "")
57
- # below an attempt to load atome in pure ruby not opal
58
- require "../atome/lib/atome.rb"
59
- box("je sais pas ou ca passe")
60
- opts[:root] = '../view'
61
- plugin :static, %w[/css /js /medias], root: '../view'
62
- # plugin "faye/websocket"
39
+ require 'atome'
40
+ opts[:root] = '../build'
41
+ plugin :static, %w[/css /js /medias], root: '../build'
63
42
  route do |r|
64
43
  if Faye::WebSocket.websocket?(env)
65
- ws = Faye::WebSocket.new(env)
66
- # @@test_socket[0] = ws
67
- @@test_socket[0] = ws
68
- ws.on :message do |event|
44
+ websocket = Faye::WebSocket.new(env)
45
+ websocket.on :message do |event|
69
46
  client_data = event.data
70
47
  if client_data.is_json?
71
- data = JSON.parse(client_data)
72
- # puts data
73
- case data["type"]
74
- when "login"
75
- user_id = data["username"]
76
- # @user_id[user_id]=ws
77
- # @user[data["username"]] = ws
78
- # ws.send()
79
- # message_back = "text ({content: '#{data["username"]} with id : #{data["id"]} is connected!', y:330})"
80
- # message_back={id: data["id"], log: true}
81
- #
82
- session_id = SecureRandom.uuid
83
- message_back = JSON.generate({ type: :response, request_id: data["request_id"], session_id: session_id, log: true })
84
- ws.send(message_back)
85
-
86
- when "start_channel"
87
- channel_id = SecureRandom.uuid
88
- # self.channels(channel_id)
89
- @@channels[channel_id] = []
90
- # @session[data["username"]] =session_id
91
- message_back = JSON.generate({ type: :response, request_id: data["request_id"], channel_id: channel_id })
92
- ws.send(message_back)
93
- when "list_channels"
94
- message_back = JSON.generate({ type: :response, request_id: data["request_id"], channels: @@channels.keys })
95
- ws.send(message_back)
96
- when "connect_channel"
97
- channel_id = data["channel_id"]
98
- @@channels[channel_id] << ws
99
- message_back = JSON.generate({ type: :response, request_id: data["request_id"], connected: true })
100
- ws.send(message_back)
101
- when "push_to_channel"
102
- channel_id = data["channel_id"]
103
- message_received = data["message"]
104
- #fixme the type depend on the kind if received message
105
- message_to_push = JSON.generate({ type: :code, content: message_received })
106
- @@channels[channel_id].each do |ws_found|
107
- # we exclude the sender from the recipient
108
- unless ws_found == ws
109
- ws_found.send(message_to_push)
110
- end
111
- end
112
- message_back = JSON.generate({ type: :response, request_id: data["request_id"], pushed: true })
113
- ws.send(message_back)
114
- when "read"
115
- file_content = File.read(data["file"])
116
- hashed_content = { content: file_content }
117
- hashed_options = { options: data["options"].to_s }
118
- message_to_push = JSON.generate({ type: :read, atome: data["atome"], target: data["target"], content: hashed_content, options: hashed_options })
119
- ws.send(message_to_push)
120
- when "set"
121
- msg = { type: :monitor, atome: data["atome"], target: data["target"], output: data["output"], content: data["content"],options: data["options"] }
122
- set_output msg
123
- when "monitor"
124
- # file = data["file"]
125
- # monitor "public/medias/e_projects/chambon/code.rb"
126
- # puts file.class
127
- # if !file.instance_of?(Array)
128
- # file=[file]
129
- # end
130
-
131
-
132
- # @@threads << Thread.new do
133
- # puts "hello from thread"
134
- # Filewatcher.new(file).watch do |changes|
135
- # file_content = file
136
- # hashed_content = { content: data["file"] }
137
- # hashed_options = { options: data["options"].to_s }
138
- if data["file"]
139
- msg = { type: :monitor, atome: data["atome"], target: data["target"], content: data["file"], options: data["options"] }
140
- monitor msg
141
- else
142
- msg = { type: :monitor, atome: data["atome"], target: data["target"], input: data["input"], options: data["options"] }
143
- capture_input msg
144
- end
145
- # puts "------"
146
- # puts file.class
147
- # puts "------"
148
- # message_to_push = JSON.generate({ type: :monitor, atome: data["atome"], target: data["target"], content: hashed_content, options: hashed_options })
149
- # # puts ws.inspect
150
- # # puts "---"
151
- # puts "hashed_content : #{hashed_content}}"
152
- # puts "hashed_options : #{hashed_options}}"
153
- # puts "message_to_push : #{message_to_push}}"
154
- # ws.send(message_to_push)
155
- # # @@channels[channel_id].each do |ws_found|
156
- # # # we exclude the sender from the recipient
157
- # # unless ws_found == ws
158
- # # ws_found.send(message_to_push)
159
- # # end
160
- # # end
161
- # end
162
- # puts "koolll!!!!"
163
- # end
164
- # @@threads.each(&:join)
165
-
166
- # t= Thread.new do
167
- # puts "hello from thread"
168
- # Filewatcher.new(file).watch do |changes|
169
- # # file_content = File.read(changes)
170
- # hashed_content = { content: file_content }
171
- # hashed_options = { options: data["options"].to_s }
172
- # message_to_push = JSON.generate({ type: :monitor, atome: data["atome"], target: data["target"], content: hashed_content, options: hashed_options })
173
- # # puts ws.inspect
174
- # # puts "---"
175
- # puts "hashed_content : #{hashed_content}}"
176
- # puts "hashed_options : #{hashed_options}}"
177
- # puts "message_to_push : #{message_to_push}}"
178
- # ws.send(message_to_push)
179
- # # @@channels[channel_id].each do |ws_found|
180
- # # # we exclude the sender from the recipient
181
- # # unless ws_found == ws
182
- # # ws_found.send(message_to_push)
183
- # # end
184
- # # end
185
- # end
186
- #
187
- # end
188
- #
189
- # t.join
190
-
191
- # # ugly patch below needs to use filewatcher above instead
192
- # t=Thread.new do
193
- # sleep 12
194
- # puts file = data["file"]
195
- # end
196
- # t.join
197
- # if @file_require == (Digest::SHA256.hexdigest File.read data["file"])
198
- # @file_require = Digest::SHA256.hexdigest File.read data["file"]
199
- # else
200
- # @file_require = Digest::SHA256.hexdigest File.read data["file"]
201
- # # file_content = File.read()
202
- # file = data["file"]
203
- # hashed_file = { content: file }
204
- # hashed_options = { options: data["options"].to_s }
205
- # message_to_push = JSON.generate({ type: :monitor, atome: data["atome"], target: data["target"], file: hashed_file, options: hashed_options })
206
- # ws.send(message_to_push)
207
- # end
208
- when "list"
209
- files_found = Dir[data["path"] + "/*"]
210
- hashed_content = { content: files_found }
211
- hashed_options = { options: data["options"].to_s }
212
- message_to_push = JSON.generate({ type: :read, target: data["target"], content: hashed_content, options: hashed_options })
213
- ws.send(message_to_push)
214
- when "write"
215
- File.write(data["file"], data["content"])
216
- hashed_content = { content: data["content"].to_s }
217
- hashed_options = { options: data["options"].to_s }
218
- message_to_push = JSON.generate({ type: :read, target: data["target"], content: hashed_content, options: hashed_options })
219
- ws.send(message_to_push)
220
- when "copy"
221
- FileUtils.cp data["source"], data["dest"]
222
- when "delete"
223
- File.delete(data["file"])
224
- hashed_content = { content: data["file"].to_s }
225
- hashed_options = { options: data["options"].to_s }
226
- message_to_push = JSON.generate({ type: :read, target: data["target"], content: hashed_content, options: hashed_options })
227
- ws.send(message_to_push)
228
- when "mail"
229
- if data["from"]
230
- sender = data["from"]
231
- else
232
- sender = "contact@atome.one"
233
- end
234
- receiver = data["to"]
235
- mail_subject = data["subject"]
236
- content = data["content"]
237
- attachment = data["attachment"]
238
- attachments = []
239
- if attachment
240
- if attachment.instance_of?(Array)
241
- attachment.each do |file|
242
- filename = File.basename(file)
243
- attachments << { file: file, filename: filename }
244
- end
245
- else
246
- filename = File.basename(attachment)
247
- attachments << { file: attachment, filename: filename }
248
- end
249
- end
250
- # puts "----- + -----"
251
- # puts "sender: #{sender}"
252
- # puts "receiver: #{receiver}"
253
- # puts "mail_subject: #{mail_subject}"
254
- # puts "content: #{content}"
255
- # puts "attachments: #{attachments}"
256
- # puts "----- - -----"
257
- mail = Mail.new do
258
- from sender
259
- to receiver
260
- subject mail_subject
261
- body content
262
- attachments.each do |file_to_add|
263
- file = file_to_add[:file]
264
- filename = file_to_add[:filename]
265
- add_file :filename => filename, :content => File.read(file)
266
- end
267
- end
268
-
269
- mail.delivery_method :sendmail
270
-
271
- mail.deliver
272
- when "atome"
273
- message_to_push = JSON.generate({ type: :atome, target: data["target"], atome: data["atome"], content: data["content"] })
274
- ws.send(message_to_push)
275
- when "code"
276
- message_to_push = JSON.generate({ type: :code, content: data["content"] })
277
- ws.send(message_to_push)
278
- when "command"
279
- file_content = `#{data["content"]}`
280
- # hashed_content = { content: file_content }.merge(data["options"])
281
- message_to_push = JSON.generate({ type: :command, target: data["target"], atome: data["atome"], content: file_content })
282
- ws.send(message_to_push)
283
- else
284
- # ws.send("unknown message received")
285
- end
48
+ # to get hash from data: data_to_hash = JSON.parse(client_data)
49
+ websocket.send(client_data)
286
50
  end
287
51
  end
288
- #ws.on :open do |event|
289
- # #ws = nil
290
- #end
291
- ws.on :close do |event|
292
- #ws = nil
52
+ websocket.on :open do
53
+ # websocket.send(event.data)
293
54
  end
294
- ws.rack_response
55
+ websocket.on :close do
56
+ # websocket.send(event.data)
57
+ end
58
+ websocket.rack_response
295
59
  end
296
60
  r.root do
297
61
  r.redirect "/index"
@@ -299,78 +63,9 @@ class App < Roda
299
63
  r.on "index" do
300
64
  r.is do
301
65
  r.get do
302
- #sleep 7
303
- #box()
304
66
  index_content
305
67
  end
306
68
  end
307
69
  end
308
70
  end
309
-
310
- def self.monitor_callback(val, params)
311
- ws = @@test_socket[0]
312
- file_content = File.read(val)
313
- params[:content] = val
314
- msg = { "type": "eval", "atome": "text", "target": "tryout", "content": { "content": file_content }, "options": "clear" }
315
- params[:content] = { "content": { "content": file_content } }
316
- message_to_push = JSON.generate(msg)
317
- ws.send(message_to_push)
318
- end
319
-
320
- def self.device_output_callback( params)
321
- ws = @@test_socket[0]
322
- file_content = params[:content]
323
- msg = { "type": "read", "atome": "text", "target": "tryout", "content": { "content": file_content }, "options": "clear" }
324
- params[:content] = { "content": { "content": file_content } }
325
- message_to_push = JSON.generate(msg)
326
- ws.send(message_to_push)
327
- end
328
- end
329
-
330
-
331
-
332
-
333
- # Update all connections in a single thread
334
- def monitor(params)
335
- Thread.new do
336
- Filewatcher.new(params[:content]).watch do |changes|
337
- App.monitor_callback(changes, params)
338
- end
339
- end
340
- end
341
-
342
- @bbb_ready = false
343
- @bbb_thread = false
344
-
345
- def capture_input params
346
- unless @bbb_ready
347
- @bbb_ready = true
348
- puts "bbb is ready"
349
- # require "./beagleboard"
350
-
351
- end
352
- if @bbb_thread
353
- @bbb_thread.exit
354
- end
355
-
356
- @bbb_thread = Thread.new do
357
-
358
- i = 0
359
- while i < 2000
360
- puts i
361
- sleep 1
362
- i += 1
363
- end
364
- end
365
71
  end
366
-
367
-
368
- def set_output params
369
- App.device_output_callback( params)
370
- end
371
-
372
-
373
- # capture_input(1, { my_condition: :callback })
374
- #
375
- # capture_input(1, { my_condition: :callback })
376
- # capture_input(1, { my_condition: :callback })
@@ -7,7 +7,7 @@
7
7
 
8
8
  require 'roda'
9
9
  Thread.new do
10
- sleep 0.9
10
+ sleep 1.5
11
11
  system("open", "http://127.0.0.1:9292")
12
12
  end
13
13
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.00003
4
+ version: 0.1.00009
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Eric Godard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-12 00:00:00.000000000 Z
11
+ date: 2022-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: artoo
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.8'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.8'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: faye-websocket
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -278,7 +264,7 @@ dependencies:
278
264
  version: '0.1'
279
265
  description: the creative framework.
280
266
  email:
281
- - jeezs@jeezs.net
267
+ - jeezs@atopme.one
282
268
  executables:
283
269
  - atome
284
270
  extensions: []
@@ -289,6 +275,7 @@ files:
289
275
  - LICENSE.txt
290
276
  - README.md
291
277
  - Rakefile
278
+ - app_builder_helpers/Rakefile
292
279
  - exe/atome
293
280
  - lib/atome.rb
294
281
  - lib/atome/kernel/atome_genesis.rb
@@ -300,8 +287,6 @@ files:
300
287
  - lib/atome/renderers/opal/properties/generator.rb
301
288
  - lib/atome/renderers/server/server.rb
302
289
  - lib/atome/version.rb
303
- - run_helpers/Rakefile
304
- - run_helpers/start_server.ru
305
290
  - sig/atome.rbs
306
291
  - vendor/assets/build/css/style.css
307
292
  - vendor/assets/build/index.html
@@ -314,6 +299,7 @@ files:
314
299
  - vendor/assets/build/js/third_parties/popmotion.min.js
315
300
  - vendor/assets/index.rb
316
301
  - vendor/assets/server/atome_server.rb
302
+ - vendor/assets/server/config.ru
317
303
  homepage: https://atome.one
318
304
  licenses:
319
305
  - MIT
@@ -337,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
323
  - !ruby/object:Gem::Version
338
324
  version: '0'
339
325
  requirements: []
340
- rubygems_version: 3.3.10
326
+ rubygems_version: 3.3.11
341
327
  signing_key:
342
328
  specification_version: 4
343
329
  summary: the creative framework
data/run_helpers/Rakefile DELETED
@@ -1,150 +0,0 @@
1
- require 'opal'
2
- require 'opal-jquery'
3
- require 'opal-browser'
4
- require 'parser'
5
- require 'uglifier'
6
-
7
- Opal.append_path "app"
8
-
9
- def build_opal_browser(user_project_path)
10
- puts "###### browser path : #{`pwd`} ######"
11
- opal_browser = "#{user_project_path}/build/js/opal/opal_browser.js"
12
- File.binwrite opal_browser, Opal::Builder.build("../lib/atome/renderers/opal/opal_browser.rb").to_s
13
- uglified = Uglifier.new.compile(File.read(opal_browser))
14
- File.open(opal_browser, "w") do |f|
15
- f.puts uglified
16
- end
17
- end
18
-
19
- def build_atome_kernel(user_project_path,gem_location)
20
- atome_kernel = "#{user_project_path}/build/js/atome/kernel.js"
21
- builder = Opal::Builder.new
22
- builder.append_paths("#{gem_location}/../lib/")
23
- File.binwrite atome_kernel, builder.build("#{gem_location}/../lib/atome.rb").to_s
24
- end
25
-
26
- def build_opal_parser(user_project_path)
27
- opal_parser = "#{user_project_path}/build/js/opal/opal_parser.js"
28
- File.binwrite opal_parser, Opal::Builder.build("../lib/atome/renderers/opal/opal_parser.rb").to_s
29
- uglified = Uglifier.new.compile(File.read(opal_parser))
30
- File.open(opal_parser, "w") do |f|
31
- f.puts uglified
32
- end
33
- end
34
-
35
- def build_user_code(user_project_path)
36
- application = "#{user_project_path}/build/js/application.js"
37
- File.binwrite application, Opal::Builder.build("../vendor/assets/index.rb").to_s
38
- uglified = Uglifier.new.compile(File.read(application))
39
- File.open(application, "w") do |f|
40
- f.puts uglified
41
- end
42
- end
43
-
44
- task :system_builder do
45
- user_project_path=ARGV[1]
46
- gem_location = File.join(File.dirname(__FILE__))
47
- build_atome_kernel(user_project_path,gem_location)
48
- build_opal_browser(user_project_path)
49
- build_opal_parser(user_project_path)
50
- build_user_code(user_project_path)
51
- end
52
-
53
- task :build do
54
- # code_to_debug = File.read("./app/app.rb")
55
-
56
- # ############# start of the patch
57
- # class Element
58
- # def self.create(tag = 'div', opt = {})
59
- # `jQuery('<'+tag+'/>',opt.$to_n())`
60
- # end
61
- #
62
- # def self.find(val)
63
- # puts val
64
- # end
65
- # end
66
- #
67
- # def box(params = {})
68
- # # el = Element.new(:div)
69
- # el = Element.create(:div, { id: 'some_big_id',
70
- # class: 'some-class some-other-class',
71
- # title: 'now this div has a title!' })
72
- # # el.text("kjh")
73
- # Element.find('#user_view').append(el)
74
- # el.css(:color, :red).css("box-shadow": "0px 0px 9px red")
75
- # .css(:width, 33).css(:height, 33).css(:position, "absolute").css(:left, "33px").css(:top, "33px")
76
- # .css('border-radius', '3px 6px 3px 6px')
77
- #
78
- # el.on(:click) do
79
- # el.css("background-color", "yellowgreen")
80
- # el.text(el.css("background-color"))
81
- # end
82
- # end
83
- #
84
- # ############# end of the patch
85
- # `ruby ./app/index.rb`
86
- # eval code_to_debug
87
- # build the python
88
- # html_file = File.read(html_page)
89
- # python_code = File.read(python_file)
90
- # html_file = html_file.gsub("#**python**#", python_code)
91
- # File.open("../view/index.html", "w") do |f|
92
- # f.puts html_file
93
- # end
94
- # now the ruby
95
- # File.binwrite application, Opal::Builder.build("./atome/lib/atome.rb").to_s
96
- # File.binwrite html_render_lib, Opal::Builder.build("./atome/lib/html_render_lib.rb").to_s
97
-
98
-
99
-
100
- # uncomment below for production
101
- # uglified = Uglifier.new().compile(File.read(application))
102
- # File.open(application, "w") do |f|
103
- # f.puts uglified
104
- # end
105
- # # now we open the page
106
- # system("open", index)
107
- end
108
-
109
- task :default => :build
110
-
111
- opal_jquery = "./view/js/opal_jquery.js"
112
- opal_browser = "./view/js/opal_browser.js"
113
- opal_parser = "./view/js/opal_parser.js"
114
-
115
- task :server do
116
- Dir.chdir("app") do
117
- require "rack"
118
- # Thread.new do
119
- # sleep 2
120
- # system("open", "http://127.0.0.1:9292")
121
- # end
122
- sh "rackup"
123
- end
124
- end
125
-
126
- task :jquery do
127
- File.binwrite opal_jquery, Opal::Builder.build("./opal/opal_jquery_libs.rb").to_s
128
- uglified = Uglifier.new.compile(File.read(opal_jquery))
129
- File.open(opal_jquery, "w") do |f|
130
- f.puts uglified
131
- end
132
- end
133
-
134
- task :browser do
135
- File.binwrite opal_browser, Opal::Builder.build("./opal/opal_browser_libs.rb").to_s
136
- uglified = Uglifier.new.compile(File.read(opal_browser))
137
- File.open(opal_browser, "w") do |f|
138
- f.puts uglified
139
- end
140
- end
141
-
142
- task :parser do
143
- File.binwrite opal_parser, Opal::Builder.build("./opal/opal_parser_libs.rb").to_s
144
- uglified = Uglifier.new.compile(File.read(opal_parser))
145
- File.open(opal_parser, "w") do |f|
146
- f.puts uglified
147
- end
148
-
149
- end
150
-