lib/atome/kernel/generators/generator.rb in atome-0.4.5.4 vs lib/atome/kernel/generators/generator.rb in atome-0.4.7.0
- old
+ new
@@ -1,13 +1,13 @@
# frozen_string_literal: true
# generators
Genesis.particle_creator(:html_type)
+
Genesis.particle_creator(:html_object)
-
Genesis.atome_creator(:shape)
Genesis.atome_creator(:shadow)
# Genesis.atome_creator(:additional)
Genesis.atome_creator(:content)
@@ -40,10 +40,24 @@
params
end
Genesis.atome_creator(:shadow)
+Genesis.atome_creator(:video) do |params, &proc|
+ # todo: factorise code below
+ if params
+ default_renderer = Sanitizer.default_params[:render]
+ generated_id = params[:id] || "video_#{Universe.atomes.length}"
+ generated_render = params[:render] || default_renderer unless params[:render].instance_of? Hash
+ generated_parent = params[:parent] || id
+ default_params = { render: [generated_render], id: generated_id, type: :video, parent: [generated_parent],
+ path: './medias/videos/video_missing.mp4', left: 139, top: 333, width: 199, height: 199 }
+ params = default_params.merge(params)
+ end
+ params
+end
+
# Example below
# Genesis.atome_creator(:color) do |params|
# # puts "extra color code executed!! : #{params}"
# end
@@ -68,12 +82,11 @@
#
# Genesis.atome_creator_option(:color_getter_pre_proc) do
# # puts "optional color_getter_pre_proc\n"
# end
-Genesis.particle_creator(:id) do
-end
+Genesis.particle_creator(:id)
Genesis.particle_creator(:left)
Genesis.particle_creator(:right)
Genesis.particle_creator(:top)
Genesis.particle_creator(:bottom)
Genesis.particle_creator(:width)
@@ -84,37 +97,67 @@
Genesis.particle_creator(:alpha)
Genesis.particle_creator(:type)
Genesis.particle_creator(:smooth)
Genesis.particle_creator(:blur)
Genesis.particle_creator(:touch)
+Genesis.particle_creator(:play)
+Genesis.particle_creator(:pause)
+Genesis.particle_creator(:time)
+
# Genesis.atome_creator_option(:type_pre_render_proc) do |params|
-# # alert "it works and get #{params}"
+# # "it works and get #{params}"
# params[:value]
# end
# important exemple below how to prevent rendering
# Genesis.atome_creator_option(:top_render_proc) do |params|
# puts "====---> Hurrey no rendering : #{params}"
# end
Genesis.particle_creator(:render)
Genesis.particle_creator(:drm)
-Genesis.particle_creator(:parent)
+Genesis.particle_creator(:child)
+
+Genesis.particle_creator(:parent) do |parents|
+ parents.each do |parent|
+ #TODO : create a root atome instead of using the condition below
+ if parent != :user_view
+ grab(parent).child << id
+ end
+ end
+ parents
+end
+
Genesis.atome_creator_option(:parent_pre_render_proc) do |params|
+ current_atome = params[:atome]
unless params[:value].instance_of? Array
params[:value] = [params[:value]]
end
- params[:value]
+ current_atome.instance_variable_set("@parent", params[:value])
end
+
Genesis.particle_creator(:date)
Genesis.particle_creator(:location)
+Genesis.atome_creator_option(:id_pre_render_proc) do |params|
+ new_id = params[:value]
+ current_atome = params[:atome]
+ old_id = current_atome.id
+ current_atome.instance_variable_set('@id', new_id)
+ # we change id id the atomes hash
+ Universe.change_atome_id(old_id, new_id)
+ current_atome.html_object.id = new_id if current_atome.html_object
+
+end
+
+
# generate renderers
Genesis.generate_html_renderer(:type) do |value, atome, proc|
send("#{value}_html", value, atome, proc)
+ value
end
Genesis.generate_html_renderer(:shape) do |value, atome, proc|
id_found = id
instance_exec(&proc) if proc.is_a?(Proc)
@@ -126,11 +169,13 @@
end
Genesis.generate_html_renderer(:color) do |value, atome, proc|
instance_exec(&proc) if proc.is_a?(Proc)
@html_type = :style
- $document.head << DOM("<style atome='#{type}' id='#{id}'></style>")
+ # we remove previous unused style tag
+ $document[id].remove if $document[id]
+ $document.head << DOM("<style atome='#{type}' id='#{id}'></style>")
end
Genesis.generate_html_renderer(:red) do |value, atome, proc|
green_found = green
green_found ||= 0
@@ -171,33 +216,21 @@
blue_found = blue
blue_found ||= 0
$document[id].inner_html = "\n.#{id}{background-color: rgba(#{red_found * 255},#{green_found * 255},#{blue_found * 255},#{value})}\n"
end
-Genesis.generate_html_renderer(:drm) do |value, atome, proc|
- # instance_exec(&proc) if proc.is_a?(Proc)
-end
+Genesis.generate_html_renderer(:drm)
Genesis.generate_html_renderer(:parent) do |values, atome, proc|
instance_exec(&proc) if proc.is_a?(Proc)
values.each do |value|
- if @html_type == :style
- # we remove previous class if the are of the same type of the type
- # ex if there's a color already assign we remove it to allow the new one to be visible
- html_parent = grab(value).instance_variable_get("@html_object")
- html_parent.class_names.each do |class_name|
- if $document[class_name] && $document[class_name].attributes[:atome]
- class_to_remove = $document[class_name].attributes[:id]
- html_parent.remove_class(class_to_remove)
- end
- end
- $document[value].add_class(id)
- else
- @html_object.append_to($document[value])
- end
+ atome.html_decision(@html_type, value, id)
end
end
+
+
+
Genesis.generate_html_renderer(:id) do |value, atome, proc|
# send("#{value}_html", value, atome, proc)
end
Genesis.generate_html_renderer(:left) do |value, atome, proc|
@@ -222,15 +255,12 @@
Genesis.generate_html_renderer(:height) do |value, atome, proc|
@html_object.style[:height] = "#{value}px" unless @html_type == :style
end
-Genesis.particle_creator(:rotate) do |params, atome, &proc|
- # puts atome
- # alert :pl
- instance_exec(method_name, params, atome, &proc) if proc.is_a?(Proc)
-end
+Genesis.particle_creator(:rotate)
+
Genesis.generate_html_renderer(:rotate) do |value, atome, proc|
@html_object.style[:transform] = "rotate(#{value}deg)" unless @html_type == :style
end
Genesis.generate_html_renderer(:smooth) do |value, atome, proc|
@@ -253,48 +283,32 @@
@html_object.on :click do |e|
instance_exec(&proc) if proc.is_a?(Proc)
end
end
-#drag
-def dragCallback(page_x, page_y, x, y, current_object, proc)
- current_object.instance_variable_set('@left', x)
- current_object.instance_variable_set('@top', y)
- instance_exec(page_x, page_y, &proc) if proc.is_a?(Proc)
+Genesis.generate_html_renderer(:video) do |value, atome, proc|
+ id_found = id
+ instance_exec(&proc) if proc.is_a?(Proc)
+ DOM do
+ video({ id: id_found, autoplay: false }).atome
+ end.append_to($document[:user_view])
+ @html_object = $document[id_found]
+ @html_type = :video
end
-Genesis.particle_creator(:drag)
-
-Genesis.generate_headless_renderer(:drag) do |value, atome, user_proc|
- puts "msg from headless drag method: value is #{value} , atome class is #{atome.class}"
- instance_exec(&user_proc) if user_proc.is_a?(Proc)
-end
-
-Genesis.generate_html_renderer(:drag) do |value, atome, user_proc|
- # FIXME: we should find a s solution to pass the proc to the dragCallback toavoid the test below
- @html_drag = user_proc if user_proc
- if value == :remove
- @html_object.remove_class(:draggable)
- else
- @html_object.add_class(:draggable)
- end
-end
-
+# overflow
Genesis.particle_creator(:overflow)
Genesis.generate_html_renderer(:overflow) do |value, atome, proc|
@html_object.style[:overflow] = value unless @html_type == :style
end
Genesis.particle_creator(:bloc)
# image
Genesis.atome_creator(:image)
-Genesis.particle_creator(:path)
-Genesis.generate_html_renderer(:path) do |value, atome, proc|
- @html_object[:src] = value
-end
+
Genesis.generate_html_renderer(:image) do |value, atome, proc|
id_found = id
instance_exec(&proc) if proc.is_a?(Proc)
DOM do
img({ id: id_found }).atome
@@ -303,85 +317,201 @@
@html_type = :image
end
# text
-Genesis.atome_creator(:text)
-Genesis.particle_creator(:string)
+Genesis.atome_creator(:text) do |params|
+ # TODO: factorise code below
+ if params
+ default_renderer = Sanitizer.default_params[:render]
+ generated_id = params[:id] || "text_#{Universe.atomes.length}"
+ generated_render = params[:render] || default_renderer unless params[:render].instance_of? Hash
+ generated_parent = params[:parent] || id
-Genesis.generate_html_renderer(:string) do |value, atome, proc|
- @html_object.text = value
+ default_params = { render: [generated_render], id: generated_id, type: :text, parent: [generated_parent],
+ visual: { size: 33 }, data: "hello world", left: 39, top: 33,
+ color: { render: [generated_render], id: "color_#{generated_id}", type: :color,
+ red: 0.09, green: 1, blue: 0.12, alpha: 1 }
+ }
+ params = default_params.merge(params)
+ params
+ end
+ # params
end
+Genesis.particle_creator(:string)
+
Genesis.particle_creator(:visual)
Genesis.generate_html_renderer(:visual) do |value, atome, proc|
@html_object.style['font-size'] = "#{value[:size]}px"
end
+
Genesis.generate_html_renderer(:text) do |value, atome, proc|
id_found = id
instance_exec(&proc) if proc.is_a?(Proc)
DOM do
- div(id: id_found).atome
+ div(id: id_found).atome.text
end.append_to($document[:user_view])
@html_object = $document[id_found]
@html_type = :text
end
-
-# video
-Genesis.atome_creator(:video)
-Genesis.generate_html_renderer(:video) do |value, atome, proc|
- id_found = id
- instance_exec(&proc) if proc.is_a?(Proc)
- DOM do
- video({ id: id_found, autoplay: true }).atome
- end.append_to($document[:user_view])
- @html_object = $document[id_found]
- @html_type = :video
-end
-
-
# particles method below to allow to retrieve all particles for an atome
Genesis.particle_creator(:particles)
Genesis.atome_creator_option(:particles_getter_pre_proc) do |params|
atome_found = params[:atome]
particles_hash = {}
atome_found.instance_variables.each do |particle_found|
particle_content = atome_found.instance_variable_get(particle_found)
- particles_hash[particle_found] = particle_content
+ particles_hash[particle_found.sub('@', '')] = particle_content
end
particles_hash
end
-
# link
Genesis.particle_creator(:link)
Genesis.atome_creator_option(:link_pre_render_proc) do |params|
atome_found = params[:atome]
atome_to_link = grab(params[:value])
particles_found = atome_to_link.particles
- atome_type = particles_found.delete('@type')
+ atome_type = particles_found.delete(:type)
sanitized_particles = {}
particles_found.each do |particle_name, value|
particle_name = particle_name.gsub('@', '')
sanitized_particles[particle_name] = value
end
- sanitized_particles[:parent]=[atome_found.id]
+ sanitized_particles[:parent] = [atome_found.id]
atome_found.send(atome_type, sanitized_particles)
params[:value]
end
Genesis.atome_creator(:web)
Genesis.particle_creator(:path)
Genesis.generate_html_renderer(:path) do |value, atome, proc|
@html_object[:src] = value
end
+
Genesis.generate_html_renderer(:web) do |value, atome, proc|
id_found = id
instance_exec(&proc) if proc.is_a?(Proc)
DOM do
iframe({ id: id_found }).atome
end.append_to($document[:user_view])
@html_object = $document[id_found]
- @html_object.attributes[:allow]='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
- @html_object.attributes[:allowfullscreen]=true
+ @html_object.attributes[:allow] = 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
+ @html_object.attributes[:allowfullscreen] = true
@html_type = :web
+end
+
+Genesis.particle_creator(:data)
+
+Genesis.generate_html_renderer(:data) do |value, atome, proc|
+ # TODO: create a method for each type
+ send("#{type}_data", value)
+end
+
+Genesis.particle_creator(:code)
+Genesis.atome_creator_option(:code_pre_render_proc) do |params|
+ def get_binding
+ binding
+ end
+
+ str = params[:value][:code]
+ eval str, get_binding, __FILE__, __LINE__
+ params[:value]
+end
+Genesis.particle_creator(:on)
+
+Genesis.generate_html_renderer(:on) do |value, atome, proc|
+ @html_object.on(value) do |e|
+ instance_exec(e, &proc) if proc.is_a?(Proc)
+ end
+end
+
+Genesis.atome_creator_option(:shape_post_save_proc) do |params|
+ current_atome = params[:atome]
+ #FIXME: look why we have to look in [:value][:value] this looks suspect
+ bloc_found = params[:value][:value][:bloc]
+ current_atome.instance_exec(params, &bloc_found) if bloc_found.is_a?(Proc)
+ params
+end
+
+Genesis.atome_creator_option(:text_post_save_proc) do |params|
+ current_atome = params[:atome]
+ #FIXME: look why we have to look in [:value][:value] this looks suspect
+ bloc_found = params[:value][:value][:bloc]
+ current_atome.instance_exec(params, &bloc_found) if bloc_found.is_a?(Proc)
+ params
+end
+
+Genesis.atome_creator_option(:play_pre_render_proc) do |params|
+ params[:atome].send("play_#{params[:atome].type}", params)
+end
+
+Genesis.atome_creator_option(:pause_pre_render_proc) do |params|
+ params[:atome].send("pause_#{params[:atome].type}", params)
+ proc_found = params[:proc]
+ params[:atome].instance_exec('::call back from pause render', &proc_found) if proc_found.is_a?(Proc)
+end
+
+Genesis.generate_html_renderer(:time) do |value, atome, proc|
+ # params[:atome].html_object.currentTime= 33
+ @html_object.currentTime = value
+end
+
+#drag
+Genesis.generate_html_renderer(:drag) do |value, atome, proc|
+ alert ("this is very strange that I had a style tag please check")
+ instance_exec(&proc) if proc.is_a?(Proc)
+ @html_type = :style
+ $document.head << DOM("<style atome='#{type}' id='#{id}'></style>")
+end
+Genesis.particle_creator(:lock)
+Genesis.particle_creator(:target)
+Genesis.atome_creator(:drag) do |params|
+ # TODO: factorise code below
+ if params
+ default_renderer = Sanitizer.default_params[:render]
+ generated_id = params[:id] || "drag_#{Universe.atomes.length}"
+ generated_render = params[:render] || default_renderer unless params[:render].instance_of? Hash
+ generated_parent = params[:parent] || id
+ default_params = { render: [generated_render], id: generated_id, type: :drag, parent: [generated_parent], target: [generated_parent]
+ }
+ params = default_params.merge(params)
+ params
+ end
+ params
+end
+Genesis.particle_creator(:remove)
+Genesis.particle_creator(:fixed)
+Genesis.particle_creator(:max)
+Genesis.particle_creator(:inside)
+Genesis.atome_creator_option(:remove_pre_render_proc) do |params|
+ type_found = params[:atome].type
+ current_atome = params[:atome]
+ particle_to_remove = params[:value]
+ current_atome.send("#{type_found}_remove_#{particle_to_remove}", current_atome)
+end
+Genesis.atome_creator_option(:max_pre_render_proc) do |params|
+ current_atome = params[:atome]
+ current_atome.constraint_helper(params, current_atome, :max)
+end
+Genesis.atome_creator_option(:inside_pre_render_proc) do |params|
+ current_atome = params[:atome]
+ params[:value] = grab(params[:value]).html_object
+ current_atome.constraint_helper(params, current_atome, :max)
+end
+Genesis.atome_creator_option(:lock_pre_render_proc) do |params|
+ current_atome = params[:atome]
+ current_atome.constraint_helper(params, current_atome, :lock)
+end
+Genesis.atome_creator_option(:fixed_pre_render_proc) do |params|
+ current_atome = params[:atome]
+ current_atome.constraint_helper(params, current_atome, :fixed)
+end
+Genesis.generate_html_renderer(:target) do |targets, atome, proc|
+ targets.each do |value|
+ atome_found = grab(value)
+ # we get the id of the drag and ad add it as a html class to all children so they become draggable
+ atome_found.html_object.add_class(id)
+ end
+ html_drag_helper(atome, {})
end