lib/atome/helpers/utilities.rb in atome-0.5.3.8.8 vs lib/atome/helpers/utilities.rb in atome-0.5.4.0.9
- old
+ new
@@ -2,10 +2,41 @@
# toolbox method here
class Atome
private
+ # local server messaging
+ def self.controller_sender(message)
+ return if $host == :browser
+
+ json_msg = message.to_json
+ atome_js.JS.controller_sender(json_msg)
+
+ end
+
+ def response_listener(hashed_msg)
+ js_action = hashed_msg.JS[:action]
+ js_body = hashed_msg.JS[:body]
+ send(js_action, js_body)
+ end
+
+ def self.controller_listener
+
+ return if $host == :browser
+
+ atome_js.JS.controller_listener()
+
+ end
+
+ # def self.mode=(val)
+ # @atome_mode=val
+ # end
+ #
+ # def self.mode
+ # "@atome_mode"
+ # end
+
def collapse
@atome.each do |element, value|
send(element, value)
end
end
@@ -67,12 +98,12 @@
atome
end
end
def <<(particle)
- value = particle.value
- real_atome[property] << value
+
+ real_atome[property] << particle
end
def add_to_integer(_atome_found, _particle_found, &_user_proc)
puts "there's no interest to add anything to an integer!"
end
@@ -135,28 +166,28 @@
def refresh
collapse
end
- def collector(params = {}, &bloc)
- atome_type = :collector
- # generated_render = params[:renderers] || []
- # generated_id = params[:id] || identity_generator(atome_type)
- #
- # generated_parents = params[:parents] || [id.value]
- params = atome_common(atome_type, params)
- Batch.new({ atome_type => params }, &bloc)
- end
+ # def collector(params = {}, &bloc)
+ # atome_type = :collector
+ # # generated_render = params[:renderers] || []
+ # # generated_id = params[:id] || identity_generator(atome_type)
+ # #
+ # # generated_parents = params[:parents] || [id]
+ # params = atome_common(atome_type, params)
+ # Batch.new({ atome_type => params }, &bloc)
+ # end
def each(&proc)
value.each do |val|
instance_exec(val, &proc) if proc.is_a?(Proc)
end
end
def include?(value)
- self.value.include?(value)
+ self.include?(value)
end
def each_with_index(*args, &block)
value.each_with_index(&block)
end
@@ -165,25 +196,25 @@
if instance_of?(Atome)
value[range]
# elsif value[range].instance_of?(Atome)
# return value[range]
elsif value[range].instance_of?(Array)
- collector_object = Object.collector({})
- collected_atomes = []
- value[range].each do |atome_found|
- collected_atomes << atome_found
- end
- collector_object.data(collected_atomes)
-
- return collector_object
+ # collector_object = Object.collector({})
+ # collected_atomes = []
+ # value[range].each do |atome_found|
+ # collected_atomes << atome_found
+ # end
+ # collector_object.data(collected_atomes)
+ Batch.new(value[range])
+ # return collector_object
end
end
def []=(params, value)
# TODO : it may miss some code, see above
- self.value[params] = value
+ self[params] = value
end
def set(params)
params.each do |particle, value|
send(particle, value)
@@ -199,26 +230,41 @@
send(particle_to_remove, 0)
end
end
def materials
- # TODO: the code below need a rewrite, we must find a new algorythm to avoid all those conditions
+ # TODO: the code below need a rewrite, we must find a new algorithm to avoid all those conditions
images_found = atome[:image] || []
videos_found = atome[:video] || []
shapes_found = atome[:shape] || []
web_found = atome[:web] || []
texts_found = atome[:text] || []
images_found.concat(videos_found).concat(shapes_found).concat(web_found).concat(texts_found)
end
+
+ def physical
+ types=[:text, :image, :video, :shape, :web]
+ atomes_found=[]
+ types.each do |type|
+ ids_found = self.send(type)
+ next unless ids_found
+
+ ids_found.each do |id_found|
+ atomes_found << id_found
+ end
+ end
+ atomes_found
+ end
+
def detach_atome(atome_id_to_detach)
atome_to_detach = grab(atome_id_to_detach)
# TODO: remove the condition below and find why it try to detach an atome that doesn't exist
- if atome_to_detach
- atome_type_found = atome_to_detach.atome[:type]
- atome_id_found = atome_to_detach.atome[:id]
- @atome[atome_type_found].delete(atome_id_found)
- @atome[:attached].delete(atome_id_to_detach)
- end
+ return unless atome_to_detach
+ atome_type_found = atome_to_detach.atome[:type]
+ atome_id_found = atome_to_detach.atome[:id]
+ @atome[atome_type_found].delete(atome_id_found)
+ @atome[:attached].delete(atome_id_to_detach)
+
end
end