atome 0.5.7.3.2 → 0.5.7.3.5

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: 6bf0aa348d59571692a14c0bbd2910cddcb94fa1c1507e5a2d9ccdbd9c75f565
4
- data.tar.gz: 43f0dd9848d94f025018efd4b86fc6d3209998fe37e23f34c707a97a0f7680ca
3
+ metadata.gz: 7d7593f1e5f01474e9e5445f3af74ca576521aa07623acc289a2df9946d38447
4
+ data.tar.gz: 157a8892017ec1c64a7193d261ae21c2c0361c8fef232ceeda18181a02e470b8
5
5
  SHA512:
6
- metadata.gz: 83d133860dd02158c3f8b72923987299a90b1f84c90816c9a79c67be923c4d56815fd76433117540ce9eb2341ad2f51cbdc2d32ee0b28e623dfb3de709cac572
7
- data.tar.gz: 18580c37a8635cd805e23fa9daf8d39b7f7ccca3d6a954d731ca0b9bf819b5a1dffda460f25b27217b5a51e112409db90f3d897a91b6465f59220486a01f8f97
6
+ metadata.gz: 49dff402a4d28eaf636d76574701b7739b4e33d961b1402936469facd548234c17c4d4e4733aecbea7c1a5e31d8089bbbdd5a8b4c2cf008d8c6b220af8be6f6a
7
+ data.tar.gz: 0ab6747de306ebcd4d0e06974bc0f6ecdbad1eb59477c2b96aca7be4bfaaf5851bb507d5cdb04f8ea8e6fdf5196842b5c1d8bd083aafa07bcc53c8e882d68e88
data/lib/atome/atome.rb CHANGED
@@ -19,7 +19,6 @@ class Atome
19
19
  #
20
20
  # end
21
21
 
22
-
23
22
  def initialize(new_atome = {}, &atomes_proc)
24
23
  # TODO: atome format should always be as followed : {value: 0.44, unit: :px, opt1: 554}
25
24
  # when using optimised version of atome you must type eg : a.set({left: {value: 33, unit: '%', reference: :center}})
@@ -38,8 +37,8 @@ class Atome
38
37
  # @language = :english
39
38
  # @callback = {}
40
39
  @tag = {}
41
- @tick={}
42
- @storage={}
40
+ @tick = {}
41
+ @storage = {}
43
42
  @behavior = {}
44
43
  @selected = false
45
44
  #@metrics = {}
@@ -48,49 +47,44 @@ class Atome
48
47
  @collect = {}
49
48
  @int8 = {}
50
49
  @css = {}
51
- @code={}
52
- @aid= new_atome[:aid] || identity_generator
53
- @controller_proc=[]
50
+ @code = {}
51
+ @aid = new_atome[:aid] || identity_generator
52
+ @controller_proc = []
54
53
  @id = new_atome[:id] || @aid
55
- Universe.atomes.each_value do |atome_f|
56
- # we affect the already existing atome to target
57
- next unless atome_f.id == @id
54
+ # if grab(@id)
55
+ # collapse({})
56
+ # puts "#{@id} already exists"
57
+ # else
58
+ Universe.atomes.each_value do |atome_f|
59
+ # we affect the already existing atome to target
60
+ next unless atome_f.id == @id
58
61
 
59
- new_atome[:affect].each do |affected|
60
- grab(affected).apply(@id)
62
+ new_atome[:affect].each do |affected|
63
+ grab(affected).apply(@id)
64
+ end if new_atome[:affect]
65
+ return false
61
66
  end
62
- return false
63
- end
64
- Universe.add_to_atomes(@aid, self)
65
- Universe.id_to_aid(@id, @aid)
66
- @type = new_atome[:type] || :element
67
- @attached = []
68
- @affect = []
69
- @category = []
70
- # @display = { mode: :default }
71
- # @backup={} # mainly used to restore particle when using grid /table /list display mode
72
- @html = HTML.new(@id, self)
73
- @headless = Headless.new(@id, self)
74
- @initialized={}
75
- @creator= Universe.current_user
76
- # now we store the proc in a an atome's property called :bloc
77
- new_atome[:code] = atomes_proc if atomes_proc
78
- # we reorder the hash
79
- reordered_atome = reorder_particles(new_atome)
80
- # FIXME : try to remove the condition below (it crash in the method : def generator ... in genesis.rb)
81
- collapse(reordered_atome)
82
- # end
83
- # puts "@initialized : #{Atome.instance_variable_get('@initialized')}"
84
- # puts "****> #{Atome.instance_variable_get('@initialized')}"
67
+ Universe.add_to_atomes(@aid, self)
68
+ Universe.id_to_aid(@id, @aid)
69
+ @type = new_atome[:type] || :element
70
+ @attached = []
71
+ @affect = []
72
+ @category = []
73
+ # @display = { mode: :default }
74
+ # @backup={} # mainly used to restore particle when using grid /table /list display mode
75
+ @html = HTML.new(@id, self)
76
+ @headless = Headless.new(@id, self)
77
+ @initialized = {}
78
+ @creator = Universe.current_user
79
+ # now we store the proc in a an atome's property called :bloc
80
+ new_atome[:code] = atomes_proc if atomes_proc
81
+ # we reorder the hash
82
+ reordered_atome = reorder_particles(new_atome)
83
+ # FIXME : try to remove the condition below (it crash in the method : def generator ... in genesis.rb)
85
84
 
86
- # if Atome.instance_variable_get('@initialized')
87
- # puts "-----> #{Atome.instance_variable_get('@initialized')}"
88
- # Atome.instance_variable_get('@initialized').each do |p_found, bloc|
89
- # # puts "==> #{p_found}"
90
- # # instance_exec.call
91
- # # instance_exec(p_found, &bloc) if bloc.is_a?(Proc)
92
- # end
85
+ collapse(reordered_atome)
93
86
  # end
87
+
94
88
  end
95
89
 
96
90
  def js
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ObjectExtension
3
+ require 'time'
4
4
 
5
+ module ObjectExtension
5
6
 
6
7
  def new(params, &bloc)
7
8
  # Genesis = Genesis.Genesis
8
9
  if params.key?(:atome)
9
- # if Universe.atome_list.include?(params[:atome])
10
- # puts "atome #{params[:atome]} already exist you can't create it"
11
- # else
12
- Universe.add_atomes_specificities params[:atome]
13
- Genesis.build_atome(params[:atome], &bloc)
10
+ Universe.add_atomes_specificities params[:atome]
11
+ Genesis.build_atome(params[:atome], &bloc)
14
12
  # end
15
13
  elsif params.key?(:particle)
16
14
  if Universe.particle_list[params[:particle]]
@@ -51,12 +49,12 @@ module ObjectExtension
51
49
  # bloc.call(option)
52
50
  # end
53
51
  elsif params.key?(:molecule)
54
- molecule=params[:molecule]
52
+ molecule = params[:molecule]
55
53
  Genesis.build_molecule(molecule, &bloc)
56
54
  Universe.add_to_molecule_list(molecule)
57
55
 
58
- # elsif params.key?(:applicaton)
59
- # alert params
56
+ # elsif params.key?(:applicaton)
57
+ # alert params
60
58
 
61
59
  # molecule=params[:molecule]
62
60
  # Genesis.build_molecule(molecule, &bloc)
@@ -66,7 +64,7 @@ module ObjectExtension
66
64
 
67
65
  tool_content = Atome.instance_exec(&bloc) if bloc.is_a?(Proc)
68
66
 
69
- Universe.tools[params[:tool]]=tool_content
67
+ Universe.tools[params[:tool]] = tool_content
70
68
  # Universe.tools[params[:tool]]=bloc
71
69
 
72
70
  elsif params.key?(:template)
@@ -86,54 +84,6 @@ end
86
84
  # atome extensions
87
85
  class Object
88
86
  include ObjectExtension
89
- # def new(params, &bloc)
90
- # # Genesis = Genesis.Genesis
91
- # if params.key?(:atome)
92
- # if Universe.atome_list.include?(params[:atome])
93
- # puts "atome #{params[:atome]} already exist you can't create it"
94
- # else
95
- # Universe.add_atomes_specificities params[:atome]
96
- # Genesis.build_atome(params[:atome], &bloc)
97
- # end
98
- # elsif params.key?(:particle)
99
- # if Universe.particle_list[params[:particle]]
100
- # puts "particle #{params[:particle]} already exist you can't create it"
101
- # else
102
- # Atome.instance_variable_set("@main_#{params[:particle]}", bloc)
103
- # # render indicate if the particle needs to be rendered
104
- # # store tell the system if it need to store the particle value
105
- # # type help the system what type of type the particle will receive and store
106
- # Genesis.build_particle(params[:particle], { render: params[:render], return: params[:return],
107
- # store: params[:store], type: params[:type],
108
- # category: params[:category] }, &bloc)
109
- # end
110
- #
111
- # elsif params.key?(:sanitizer)
112
- # Genesis.build_sanitizer(params[:sanitizer], &bloc)
113
- # elsif params.key?(:pre)
114
- # Atome.instance_variable_set("@pre_#{params[:pre]}", bloc)
115
- # elsif params.key?(:post)
116
- # Atome.instance_variable_set("@post_#{params[:post]}", bloc)
117
- # elsif params.key?(:after)
118
- # Atome.instance_variable_set("@after_#{params[:after]}", bloc)
119
- # elsif params.key?(:read)
120
- # Atome.instance_variable_set("@read_#{params[:read]}", bloc)
121
- # elsif params[:renderer]
122
- # renderer_found = params[:renderer]
123
- # if params[:specific]
124
- # Universe.set_atomes_specificities(params)
125
- # params[:specific] = "#{params[:specific]}_"
126
- # end
127
- # render_method = "#{renderer_found}_#{params[:specific]}#{params[:method]}"
128
- # Genesis.build_render(render_method, &bloc)
129
- # # elsif params.key?(:callback)
130
- # # particle_targetted = params[:callback]
131
- # # Atome.define_method("#{particle_targetted}_callback", option) do
132
- # # alert option
133
- # # bloc.call(option)
134
- # # end
135
- # end
136
- # end
137
87
 
138
88
  def reorder_particles(hash_to_reorder)
139
89
  # we reorder the hash
@@ -142,7 +92,7 @@ class Object
142
92
  ordered_part = ordered_keys.map { |k| [k, hash_to_reorder[k]] }.to_h
143
93
  other_part = hash_to_reorder.reject { |k, _| ordered_keys.include?(k) }
144
94
  # merge the parts to obtain an re-ordered hash
145
- ordered_part.merge(other_part)
95
+ ordered_part.merge(other_part)
146
96
  # reordered_hash
147
97
  end
148
98
 
@@ -155,16 +105,14 @@ class Object
155
105
  end
156
106
 
157
107
  def hook(a_id)
158
- a_id=a_id.to_sym
108
+ a_id = a_id.to_sym
159
109
  Universe.atomes[a_id]
160
110
  end
161
111
 
162
112
  def grab(id_to_get)
163
- id_to_get=id_to_get.to_sym
113
+ id_to_get = id_to_get.to_sym
164
114
  return if id_to_get == false
165
- aid_to_get= Universe.atomes_ids[id_to_get]
166
- # puts id_to_get.class
167
- # alert Universe.atomes
115
+ aid_to_get = Universe.atomes_ids[id_to_get]
168
116
  aid_to_get = '' if aid_to_get.instance_of? Array
169
117
  # id_to_get = id_to_get.to_sym
170
118
 
@@ -216,9 +164,9 @@ class Object
216
164
  id
217
165
  end
218
166
 
219
- def repeater(counter, proc)
220
- instance_exec(counter, &proc) if proc.is_a?(Proc)
221
- end
167
+ # def repeater(counter, proc)
168
+ # instance_exec(counter, &proc) if proc.is_a?(Proc)
169
+ # end
222
170
 
223
171
  def repeat_callback(params, counter)
224
172
  @repeat[params].call(counter)
@@ -255,7 +203,7 @@ class Object
255
203
 
256
204
  return intervalId;
257
205
  JS
258
-
206
+ repeat_id + 1
259
207
  end
260
208
 
261
209
  def stop(params)
@@ -266,11 +214,16 @@ class Object
266
214
  JS.eval(<<~JS)
267
215
  clearInterval(#{repeater_to_stop});
268
216
  JS
217
+ elsif params.key?(:wait)
218
+ waiter_to_stop = params[:wait]
219
+ JS.eval(<<~JS)
220
+ clearTimeout(window.timeoutIds['#{waiter_to_stop}'])
221
+ JS
269
222
  else
270
- puts "La clé :repeat n'existe pas dans params"
223
+ puts "msg from stop method: the :repeat key doesn't exist"
271
224
  end
272
225
  else
273
- puts "params n'est pas un hash"
226
+ puts "msg from stop method, this params is not a Hash"
274
227
  end
275
228
  end
276
229
 
@@ -457,7 +410,6 @@ class Object
457
410
  event = Native(native_event)
458
411
  event.preventDefault
459
412
  event.stopPropagation
460
- # puts 'File drop out of the special zonne'
461
413
  end
462
414
  end
463
415
  end
@@ -475,12 +427,12 @@ class Object
475
427
  particle_list.delete(:password)
476
428
  particle_list.delete(:selection)
477
429
  infos = {}
478
- particle_list[:css]=:poil
430
+ particle_list[:css] = :poil
479
431
  particle_list.each do |particle_found|
480
432
  infos[particle_found[0]] = send(particle_found[0]) unless send(particle_found[0]).nil?
481
433
  end
482
434
  # we convert CssProxy object to hash below
483
- infos[:css]=eval(infos[:css].to_s)
435
+ infos[:css] = eval(infos[:css].to_s)
484
436
  infos
485
437
  end
486
438
 
@@ -613,8 +565,6 @@ class Object
613
565
  # convert any foreign object (think HTML) to a pseudo atome objet , that embed foreign objet
614
566
  end
615
567
 
616
-
617
-
618
568
  def touch_allow(allow)
619
569
  if allow
620
570
  # Retire l'écouteur d'événements en utilisant la fonction globale
@@ -625,7 +575,6 @@ class Object
625
575
  end
626
576
  end
627
577
 
628
-
629
578
  def allow_copy(allow)
630
579
  if allow
631
580
  # allow selection and text copy
@@ -642,7 +591,7 @@ class Object
642
591
  end
643
592
  end
644
593
 
645
- def above(item, margin=6)
594
+ def above(item, margin = 6)
646
595
  pos = item.to_px(:bottom) + item.height + margin
647
596
  if item.display == :none
648
597
  33
@@ -651,7 +600,7 @@ class Object
651
600
  end
652
601
  end
653
602
 
654
- def below(item, margin=6)
603
+ def below(item, margin = 6)
655
604
  pos = item.to_px(:top) + item.to_px(:height) + margin
656
605
  if item.display == :none
657
606
  0
@@ -661,7 +610,7 @@ class Object
661
610
 
662
611
  end
663
612
 
664
- def after(item, margin=6)
613
+ def after(item, margin = 6)
665
614
  left_f = if item.left.instance_of?(Integer)
666
615
  item.left
667
616
  else
@@ -681,7 +630,7 @@ class Object
681
630
  end
682
631
  end
683
632
 
684
- def before(item, margin=6)
633
+ def before(item, margin = 6)
685
634
  pos = item.to_px(:right) + item.width + margin
686
635
  if item.display == :none
687
636
  0
@@ -690,6 +639,130 @@ class Object
690
639
  end
691
640
  end
692
641
 
642
+ # Helper method to store task configuration in localStorage
643
+ def store_task(name, config)
644
+ JS.global[:localStorage].setItem(name, config.to_json)
645
+ end
646
+
647
+ # Helper method to retrieve task configuration from localStorage
648
+ def retrieve_task(name)
649
+ config = JS.global[:localStorage].getItem(name)
650
+ config.nil? ? nil : JSON.parse(config)
651
+ end
652
+
653
+ # Helper method to retrieve all tasks from localStorage
654
+ def retrieve_all_tasks
655
+ tasks = []
656
+ local_storage = JS.global[:localStorage]
657
+ if Atome::host == "web-opal"
658
+ local_storage.each do |key|
659
+ value = local_storage.getItem(key)
660
+ if value
661
+ value = JSON.parse(value)
662
+ tasks << { name: key, config: value }
663
+ end
664
+ end
665
+ else
666
+ length = local_storage[:length].to_i
667
+ length.times do |i|
668
+ key = local_storage.call(:key, i)
669
+ value = local_storage.call(:getItem, key)
670
+ tasks << { name: key, config: JSON.parse(value.to_s) } if value
671
+ end
672
+ end
673
+ tasks
674
+ end
675
+
676
+ # Helper method to schedule a task
677
+ def schedule_task(name, years, month, day, hours, minutes, seconds, recurrence: nil, &block)
678
+ target_time = Time.new(years, month, day, hours, minutes, seconds)
679
+ now = Time.now
680
+
681
+ if target_time < now
682
+ schedule_recurrence(name, target_time, recurrence, &block)
683
+ else
684
+ seconds_until_target = target_time - now
685
+ wait_task = wait(seconds_until_target) do
686
+ block.call
687
+ schedule_recurrence(name, target_time, recurrence, &block) if recurrence
688
+ end
689
+ store_task(name, { wait: wait_task, target_time: target_time, recurrence: recurrence })
690
+ end
691
+ end
692
+
693
+ def schedule_recurrence(name, target_time, recurrence, &block)
694
+ now = Time.now
695
+ next_time = target_time
696
+
697
+ case recurrence
698
+ when :yearly
699
+ next_time += 365 * 24 * 60 * 60 while next_time <= now
700
+ when :monthly
701
+ next_time = next_time >> 1 while next_time <= now
702
+ when :weekly
703
+ next_time += 7 * 24 * 60 * 60 while next_time <= now
704
+ when :daily
705
+ next_time += 24 * 60 * 60 while next_time <= now
706
+ when :hourly
707
+ next_time += 60 * 60 while next_time <= now
708
+ when :minutely
709
+ next_time += 60 while next_time <= now
710
+ when :secondly
711
+ next_time += 1 while next_time <= now
712
+ when Hash
713
+ if recurrence[:weekly]
714
+ wday = recurrence[:weekly]
715
+ next_time += 7 * 24 * 60 * 60 while next_time <= now
716
+ next_time += 24 * 60 * 60 until next_time.wday == wday
717
+ elsif recurrence[:monthly]
718
+ week_of_month = recurrence[:monthly][:week]
719
+ wday = recurrence[:monthly][:wday]
720
+ while next_time <= now
721
+ next_month = next_time >> 1
722
+ next_time = Time.new(next_month.year, next_month.month, 1, target_time.hour, target_time.min, target_time.sec)
723
+ next_time += 24 * 60 * 60 while next_time.wday != wday
724
+ next_time += (week_of_month - 1) * 7 * 24 * 60 * 60
725
+ end
726
+ end
727
+ else
728
+ puts "Invalid recurrence option"
729
+ return
730
+ end
731
+
732
+ seconds_until_next = next_time - Time.now
733
+ wait_task = wait(seconds_until_next) do
734
+ block.call
735
+ schedule_recurrence(name, next_time, recurrence, &block)
736
+ end
737
+ store_task(name, { wait: wait_task, target_time: next_time, recurrence: recurrence })
738
+ end
739
+
740
+ # Helper method to stop a scheduled task
741
+ def stop_task(name)
742
+ task_config = retrieve_task(name)
743
+ return unless task_config
744
+
745
+ stop({ wait: task_config['wait'] })
746
+ JS.global[:localStorage].removeItem(name)
747
+ end
748
+
749
+ # Method to relaunch all tasks from localStorage
750
+ def relaunch_all_tasks
751
+ tasks = retrieve_all_tasks
752
+
753
+ tasks.each do |task|
754
+ name = task[:name]
755
+ config = task[:config]
756
+ target_time_found = config['target_time']
757
+ target_time = Time.parse(target_time_found)
758
+ recurrence_found = config['recurrence']
759
+ next unless recurrence_found
760
+ recurrence = config['recurrence'].is_a?(Hash) ? config['recurrence'].transform_keys(&:to_sym) : config['recurrence'].to_sym
761
+ schedule_task(name, target_time.year, target_time.month, target_time.day, target_time.hour, target_time.min, target_time.sec, recurrence: recurrence) do
762
+ puts "Relaunched task #{name}(add proc here)"
763
+ end
764
+ end
765
+ end
693
766
 
694
767
  end
695
768
 
@@ -715,7 +788,7 @@ class CssProxy
715
788
  @js[@parent_key][key] = value
716
789
  @current_atome.instance_variable_set('@css', { @parent_key => { key => value } })
717
790
  @css[@parent_key] = { key => value }
718
- puts "==> Clé parente: #{@parent_key}, Clé: #{key}, Valeur: #{value}"
791
+ puts "==> parent key: #{@parent_key}, Clé: #{key}, value: #{value}"
719
792
  else
720
793
  @style[key] = value
721
794
  @js[key] = value
@@ -733,8 +806,6 @@ class CssProxy
733
806
  bloc.call(parsed)
734
807
  end
735
808
 
736
-
737
-
738
809
  end
739
810
 
740
811
 
@@ -81,12 +81,8 @@ class Genesis
81
81
  # end
82
82
 
83
83
  Atome.define_method element do |params = nil, &user_proc|
84
- # if @id
85
- # alert "======> #{self.class}"
86
84
  @history[element] ||= []
87
- # else
88
- # alert "======> #{self.inspect}"
89
- # end
85
+
90
86
  if (params || params == false) && write_auth(element)
91
87
  params = particle_sanitizer(element, params, &user_proc)
92
88
  # the line below execute the main code when creating a new particle
@@ -1,7 +1,16 @@
1
1
  # frozen_string_literal: true
2
+ class Atome
3
+ def animation_callback(proc_sub_category, value=nil)
4
+ # puts "#{p◊roc_sub_category}"
5
+ proc_found = @animate_code[proc_sub_category]
6
+ # puts proc_found
7
+ instance_exec(value,&proc_found) if proc_found.is_a?(Proc)
8
+ end
9
+ end
2
10
 
3
11
  new({ particle: :touch, category: :event, type: :hash, store: false })
4
12
  new({ sanitizer: :touch }) do |params, user_bloc|
13
+ # user_params=params.dup
5
14
  if params
6
15
  # TODO: factorise code below
7
16
  @touch ||= {}
@@ -11,6 +20,7 @@ new({ sanitizer: :touch }) do |params, user_bloc|
11
20
  user_bloc =params.delete(:code) if params[:code]
12
21
  @touch_code[params.keys[0]] = user_bloc
13
22
  option = params[params.keys[0]]
23
+ @touch={ code: user_bloc}
14
24
  params.keys[0]
15
25
  else
16
26
  case params
@@ -47,7 +57,6 @@ new({ sanitizer: :touch }) do |params, user_bloc|
47
57
  @touch = false
48
58
  params
49
59
  end
50
-
51
60
  end
52
61
  new({ particle: :play, category: :event, type: :boolean, store: false })
53
62
  new({ sanitizer: :play }) do |params, user_bloc|
@@ -94,6 +103,7 @@ new({ sanitizer: :on }) do |params, user_bloc|
94
103
  params = if params.instance_of? Hash
95
104
  @on_code[:view_resize] = user_bloc
96
105
  option = params[params.keys[0]]
106
+ @resize={ code: user_bloc}
97
107
  :resize
98
108
  else
99
109
  case params
@@ -123,6 +133,7 @@ new({ sanitizer: :drag }) do |params, user_bloc|
123
133
  user_bloc =params.delete(:code) if params[:code]
124
134
  @drag_code[params.keys[0]] = user_bloc
125
135
  option = params[params.keys[0]]
136
+ @drag={ code: user_bloc}
126
137
  params.keys[0]
127
138
  else
128
139
  case params
@@ -177,6 +188,7 @@ new({ sanitizer: :drop }) do |params, user_bloc|
177
188
  user_bloc =params.delete(:code) if params[:code]
178
189
  @drop_code[params.keys[0]] = user_bloc
179
190
  option = params[params.keys[0]]
191
+ @drop={ code: user_bloc}
180
192
  params.keys[0]
181
193
  else
182
194
  case params
@@ -215,6 +227,8 @@ new({ sanitizer: :over }) do |params, user_bloc|
215
227
  user_bloc =params.delete(:code) if params[:code]
216
228
  @over_code[params.keys[0]] = user_bloc
217
229
  option = params[params.keys[0]]
230
+ @over={ code: user_bloc}
231
+
218
232
  params.keys[0]
219
233
  else
220
234
  case params
@@ -242,9 +256,6 @@ new({ sanitizer: :over }) do |params, user_bloc|
242
256
  params
243
257
 
244
258
  end
245
- # new({ particle: :sort }) do |_value, sort_proc|
246
- # @sort_proc = sort_proc
247
- # end
248
259
  new({ particle: :targets, category: :event, type: :string })
249
260
  new({ particle: :start, category: :event, type: :boolean })
250
261
  new({ pre: :start }) do |_value, user_proc|
@@ -261,9 +272,8 @@ new({ particle: :mass, category: :event, type: :int })
261
272
  new({ particle: :damping, category: :event, type: :int })
262
273
  new({ particle: :stiffness, category: :event, type: :int })
263
274
  new({ particle: :velocity, category: :event, type: :int })
264
- new({ particle: :repeat, category: :event, type: :boolean })
265
275
  new({ particle: :ease, category: :event, type: :boolean })
266
- new(particle: :keyboard, category: :event, type: :hash, store: false)
276
+ new({ particle: :keyboard, category: :event, type: :hash, store: false })
267
277
  new({ sanitizer: :keyboard }) do |params, user_bloc|
268
278
  @keyboard ||= {}
269
279
  @keyboard_code ||= {}
@@ -277,6 +287,8 @@ new({ sanitizer: :keyboard }) do |params, user_bloc|
277
287
  @keyboard_code[params.keys[0]] = user_bloc
278
288
  option = params[params.keys[0]]
279
289
  params.keys[0]
290
+ @keyboard={ code: user_bloc}
291
+
280
292
  else
281
293
  case params
282
294
  when true
@@ -314,6 +326,8 @@ new({ sanitizer: :resize }) do |params, user_bloc|
314
326
  params = if params.instance_of? Hash
315
327
  @resize_code[:resize] = user_bloc
316
328
  option = params[params.keys[0]]
329
+ @resize={ code: user_bloc}
330
+
317
331
  :resize
318
332
  else
319
333
  case params
@@ -338,16 +352,6 @@ new({ particle: :overflow, category: :event, type: :boolean }) do |params, bloc|
338
352
  params
339
353
 
340
354
  end
341
-
342
- class Atome
343
- def animation_callback(proc_sub_category, value=nil)
344
- # puts "#{p◊roc_sub_category}"
345
- proc_found = @animate_code[proc_sub_category]
346
- # puts proc_found
347
- instance_exec(value,&proc_found) if proc_found.is_a?(Proc)
348
- end
349
- end
350
-
351
355
  new({ particle: :animate, category: :event, type: :hash }) do |params, proc|
352
356
  if params.instance_of? Hash
353
357
  params = { from: 0, to: 300, duration: 1000 }.merge(params)
@@ -364,7 +368,12 @@ new({ particle: :animate, category: :event, type: :hash }) do |params, proc|
364
368
 
365
369
  params
366
370
  end
367
-
368
- new ({ after: :animate }) do |params|
371
+ new({ after: :animate }) do |params|
369
372
  html.animate(params) unless params[:end] || params[:start]
370
373
  end
374
+
375
+
376
+ # new({ particle: :repeat, category: :event, type: :boolean })
377
+ # # new({ particle: :sort }) do |_value, sort_proc|
378
+ # # @sort_proc = sort_proc
379
+ # # end
@@ -2,7 +2,7 @@
2
2
 
3
3
  new({ particle: :renderers, category: :utility, type: :string })
4
4
  new({ particle: :code, category: :utility, type: :string, store: false }) do |params, code|
5
- @code[params]=code
5
+ @code[params] = code
6
6
  end
7
7
  # new({ particle: :run, category: :utility, type: :boolean }) do |params|
8
8
  # code_found = @code
@@ -10,9 +10,9 @@ end
10
10
  # end
11
11
 
12
12
  new({ particle: :run }) do |params, code|
13
- instance_exec(&params) if params.is_a?(Proc)
14
- code_found = @code[params]
15
- instance_exec(params, &code_found) if code_found.is_a?(Proc)
13
+ instance_exec(&params) if params.is_a?(Proc)
14
+ code_found = @code[params]
15
+ instance_exec(params, &code_found) if code_found.is_a?(Proc)
16
16
  end
17
17
 
18
18
  new({ particle: :target }) do |params|
@@ -27,10 +27,9 @@ new({ particle: :target }) do |params|
27
27
  end
28
28
  end
29
29
 
30
-
31
30
  # new({ particle: :broadcast })
32
31
 
33
- def delete_recursive(atome_id, force=false)
32
+ def delete_recursive(atome_id, force = false)
34
33
  return if grab(atome_id).tag && (grab(atome_id).tag[:persistent] || grab(atome_id).tag[:system]) unless force
35
34
 
36
35
  parent_id_found = grab(atome_id).attach
@@ -47,86 +46,95 @@ def delete_recursive(atome_id, force=false)
47
46
  end
48
47
 
49
48
  new({ particle: :delete, category: :utility, type: :boolean, render: false }) do |params|
50
- if params == true
51
49
 
52
- # We use the tag persistent to exclude color of system object and other default colors
53
- unless @tag && (@tag[:persistent] || @tag[:system])
50
+ basic_system_object = %i[view eDen black_matter intuition copy atome
51
+ user_view view_color shape_color
52
+ box_color invisible_color text_color circle_color back_selection
53
+ text_selection nil
54
+ ]
55
+
56
+ unless basic_system_object.include?(id) || id.nil?
57
+
58
+ if params == true
59
+ # We use the tag persistent to exclude color of system object and other default colors
60
+ unless @tag && (@tag[:persistent] || @tag[:system])
61
+ # if we are on a matrix we delete cells found & group found
62
+ cells.delete(true)
63
+ group.delete(true)
64
+ # now we detach the atome from it's parent
65
+ # now we init rendering
66
+ render(:delete, params)
67
+ # the machine delete the current atome from the universe
68
+ id_found = @id.to_sym
69
+ if @attach
70
+ parent_found = grab(@attach)
71
+ parent_found.attached.delete(id_found)
72
+ end
73
+ @affect&.each do |affected_atome|
74
+ affected_found = grab(affected_atome)
75
+ affected_found.apply.delete(id_found)
76
+ affected_found.refresh
77
+ end
78
+
79
+ # Universe.delete(@aid)
80
+ end
81
+ elsif params.instance_of? Hash
54
82
  # if we are on a matrix we delete cells found & group found
55
83
  cells.delete(true)
56
84
  group.delete(true)
57
- # now we detach the atome from it's parent
58
- # now we init rendering
59
- render(:delete, params)
60
- # the machine delete the current atome from the universe
61
- id_found = @id.to_sym
62
- if @attach
63
- parent_found = grab(@attach)
64
- parent_found.attached.delete(id_found)
65
- end
66
- @affect&.each do |affected_atome|
67
- affected_found = grab(affected_atome)
68
- affected_found.apply.delete(id_found)
69
- affected_found.refresh
70
- end
71
- Universe.delete(@aid)
72
- end
73
- # elsif params == :force
74
- # cells.delete(true)
75
- # group.delete(true)
76
- # # now we detach the atome from it's parent
77
- # # now we init rendering
78
- # render(:delete, params)
79
- # # the machine delete the current atome from the universe
80
- # id_found = @id.to_sym
81
- # if @attach
82
- # parent_found = grab(@attach)
83
- # parent_found.attached.delete(id_found)
84
- # end
85
- # @affect&.each do |affected_atome|
86
- # affected_found = grab(affected_atome)
87
- # affected_found.apply.delete(id_found)
88
- # affected_found.refresh
89
- # end
90
- # Universe.delete(@aid)
91
- elsif params.instance_of? Hash
92
- # if we are on a matrix we delete cells found & group found
93
- cells.delete(true)
94
- group.delete(true)
95
- if params[:recursive]
96
- unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
85
+ if params[:recursive]
86
+ unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
87
+ attached.each do |atttached_atomes|
88
+ delete_recursive(atttached_atomes)
89
+ end
90
+ # touch(:remove)
91
+ # render(:delete, params)
92
+ # Universe.delete(@aid)
93
+ end
94
+ elsif params[:force]
97
95
  attached.each do |atttached_atomes|
98
- delete_recursive(atttached_atomes)
96
+ # alert "attached : #{attached}"
97
+ delete_recursive(atttached_atomes, true)
98
+ end
99
+ # touch(:remove)
100
+ # render(:delete, params)
101
+ # Universe.delete(@aid)
102
+ else
103
+ # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
104
+ # with id my_monitor
105
+ params.each do |param, value|
106
+ atome[param][value] = nil
99
107
  end
100
- touch(:remove)
101
- render(:delete, params)
102
- Universe.delete(@aid)
103
- end
104
- elsif params[:force]
105
- attached.each do |atttached_atomes|
106
- # alert "attached : #{attached}"
107
- delete_recursive(atttached_atomes, true)
108
108
  end
109
- touch(:remove)
110
- render(:delete, params)
111
- # alert "Universe : #{Universe.atomes[@aid]}"
112
- # alert "length = #{Universe.atomes.length}"
113
- Universe.delete(@aid)
114
- # alert "Universe : #{Universe.atomes.length}"
115
109
 
110
+ elsif Universe.atome_list.include?(params)
111
+ # we check if the params passed is an atome to treat it in a different way
112
+ puts "write code here : #{apply} , #{attached}"
116
113
  else
117
- # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
118
- # with id my_monitor
119
- params.each do |param, value|
120
- atome[param][value] = nil
114
+ send(params, 0) unless params == :id
115
+ end
116
+ touch(:remove)
117
+ drag(false)
118
+ drop(false)
119
+ on(false)
120
+ keyboard(false)
121
+ resize(:remove)
122
+ overflow(:remove)
123
+
124
+ render(:delete, params)
125
+ Universe.delete(@aid)
126
+
127
+ exclusions = %i[@history @renderers @type @tag @html]
128
+
129
+ instance_variables.each do |i_var|
130
+ unless exclusions.include?(i_var)
131
+ instance_variable_set(i_var, nil)
121
132
  end
122
133
  end
123
134
 
124
- elsif Universe.atome_list.include?(params)
125
- # we check if the params passed is an atome to treat it in a different way
126
- puts "write code here : #{apply} , #{attached}"
127
- else
128
- send(params, 0) unless params == :id
135
+ instance_variable_set('@renderers', [])
129
136
  end
137
+
130
138
  end
131
139
 
132
140
  new({ particle: :clear, category: :utility, type: :boolean })
@@ -226,7 +234,7 @@ new({ particle: :duplicate, category: :utility, type: :string, store: false }) d
226
234
  end
227
235
  params[:attached] = attached_atomes
228
236
  infos_found = infos.dup
229
- keys_to_delete = [:history, :callback, :duplicate, :copy, :paste, :touch_code, :html, :attached, :aid]
237
+ keys_to_delete = %i[history callback duplicate copy paste touch_code html attached aid]
230
238
  keys_to_delete.each { |key| infos_found.delete(key) }
231
239
  new_atome_id = "#{@id}_copy_#{copy_number}".to_sym
232
240
  infos_found[:id] = new_atome_id
@@ -117,6 +117,11 @@ class Atome
117
117
 
118
118
  @initialized = {}
119
119
 
120
+
121
+ def recursive(_val)
122
+ #dummy method
123
+ end
124
+
120
125
  def help(particle, &doc)
121
126
  if doc
122
127
  Universe.set_help(particle, &doc)
@@ -149,7 +154,6 @@ class Atome
149
154
  def collapse(new_atome)
150
155
  initialized_procs = []
151
156
  initialized = Atome.initialized
152
-
153
157
  new_atome.each do |element, value|
154
158
  send(element, value)
155
159
  initialized_proc = initialized[element]
data/lib/atome/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  # return atome version
4
4
  class Atome
5
- VERSION = '0.5.7.3.2'
5
+ VERSION = '0.5.7.3.5'
6
6
  end
@@ -1303,6 +1303,7 @@ class HTML
1303
1303
  proc_content = @touch_tap.call(event) if event_validation(@touch_tap)
1304
1304
  if proc_content.instance_of? Hash
1305
1305
  proc_content.each do |k, v|
1306
+ # alert "(#{@original_atome.id}, #{k}, #{v}, #{_option})"
1306
1307
  @original_atome.send(k, v)
1307
1308
  end
1308
1309
  end
@@ -1329,8 +1330,6 @@ class HTML
1329
1330
  end
1330
1331
  end
1331
1332
  end
1332
-
1333
- # end
1334
1333
  end
1335
1334
 
1336
1335
  def touch_double(_option)
@@ -6,7 +6,7 @@ class Atome
6
6
 
7
7
  def render(element, params, &user_proc)
8
8
 
9
- render_engines = @renderers
9
+ render_engines = @renderers || []
10
10
  render_engines.each do |render_engine|
11
11
  # in case we found an exception the method call will have the form, example for color top : html_color_top
12
12
  exception_found = "#{Universe.get_atomes_specificities[type][element]}"
@@ -3,21 +3,28 @@
3
3
 
4
4
  c=circle({width: 66, height: 66})
5
5
  t1=c.text({id: :first, data: 0, left: 28})
6
- cc=circle({width: 66, height: 66, left: 0 })
7
- t2=cc.text({id: :second, data: 0, left: 28})
6
+
8
7
  first_repeater=repeat(1, repeat = 99) do |counter|
9
8
  t1.data(counter)
10
9
  end
11
10
 
12
- my_repeater=repeat(1, repeat = 9) do |counter|
13
- t2.data(counter)
14
- end
15
11
 
16
12
  c.touch(true) do
17
13
  stop({ repeat: first_repeater })
18
14
  t1.data(:stopped)
19
15
  end
20
16
 
17
+
18
+ cc=circle({width: 66, height: 66, left: 90 })
19
+ t2=cc.text({id: :second, data: 0, left: 28})
20
+
21
+ # # alert first_repeater
22
+ my_repeater=repeat(1, repeat = 9) do |counter|
23
+ t2.data(counter)
24
+ end
25
+ #
26
+
27
+ #
21
28
  cc.touch(true) do
22
29
  stop({ repeat: my_repeater })
23
30
  t2.data(:stopped)
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ ######## check
5
+
6
+ # Relaunch all tasks
7
+ relaunch_all_tasks
8
+
9
+ # Example: Schedule a task to run at a specific date and time
10
+ schedule_task('specific_time_task', 2024, 11, 12, 15, 12, 30) do
11
+ puts "Task running at the specific date and time"
12
+ end
13
+
14
+ # Example: Schedule a task to run every minute
15
+ schedule_task('every_minute_task', 2024, 05, 12, 15, 12, 3, recurrence: :minutely) do
16
+ puts "Task running every minute"
17
+ end
18
+
19
+ # Example: Schedule a task to run every Tuesday at the same time
20
+ schedule_task('weekly_tuesday_task', 2024, 11, 12, 15, 12, 30, recurrence: { weekly: 2 }) do
21
+ puts "Task running every Tuesday at the same time"
22
+ end
23
+
24
+ # Example: Schedule a task to run every second Wednesday of the month at the same time
25
+ schedule_task('second_wednesday_task', 2024, 11, 12, 15, 12, 30, recurrence: { monthly: { week: 2, wday: 3 } }) do
26
+ puts "Task running every second Wednesday of the month at the same time"
27
+ end
28
+
29
+ # Stop a task
30
+ # wait 133 do
31
+ # puts 'stop'
32
+ # stop_task('every_minute_task')
33
+ # end
@@ -1,6 +1,17 @@
1
1
  # # frozen_string_literal: true
2
2
  b = box
3
3
 
4
- wait 2 do
4
+ first_wait=wait 2 do
5
5
  b.color(:red)
6
+ end
7
+ wait 1 do
8
+ puts 'now'
9
+ stop({ wait: first_wait })
10
+ # or
11
+ # wait(:kill, first_wait)
12
+ end
13
+
14
+
15
+ wait 3 do
16
+ b.color(:green)
6
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7.3.2
4
+ version: 0.5.7.3.5
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: 2024-06-08 00:00:00.000000000 Z
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -629,6 +629,7 @@ files:
629
629
  - vendor/assets/application/examples/resize.rb
630
630
  - vendor/assets/application/examples/rotate.rb
631
631
  - vendor/assets/application/examples/run.rb
632
+ - vendor/assets/application/examples/scheduler.rb
632
633
  - vendor/assets/application/examples/security.rb
633
634
  - vendor/assets/application/examples/select_text.rb
634
635
  - vendor/assets/application/examples/selected.rb