Class: HTML
Overview
this class is aimed at html rendering
Class Method Summary collapse
- .is_descendant(ancestor, descendant) ⇒ Object
- .locate(selector, base_element = JS.global[:document][:body]) ⇒ Object
Instance Method Summary collapse
- #action(_particle, action_found, option = nil) ⇒ Object
- #add_class(class_to_add) ⇒ Object
- #add_css_to_atomic_style(css) ⇒ Object
- #add_font_to_css(params) ⇒ Object
-
#animate(animation_properties) ⇒ Object
animation below.
- #animation_frame_callback(proc_pass, play_content) ⇒ Object
- #append(child_id_found) ⇒ Object
- #append_to(parent_id_found) ⇒ Object
-
#atomized(html_object) ⇒ Object
atomisation!.
- #attr(attribute, value) ⇒ Object
- #audio(id) ⇒ Object
- #backdropFilter(property, value) ⇒ Object
- #browse(id, file) ⇒ Object
- #center(options, attach) ⇒ Object
- #check_double(id) ⇒ Object
- #close_websocket ⇒ Object
- #colorize_svg_data(data) ⇒ Object
- #connect(params, &bloc) ⇒ Object
- #convert_to_css(data) ⇒ Object
- #css_to_data(css) ⇒ Object
- #currentTime(time) ⇒ Object
- #delete(id_to_delete) ⇒ Object
- #drag_end(_option) ⇒ Object
- #drag_locked(_option) ⇒ Object
- #drag_move(_option) ⇒ Object
- #drag_remove(_opt) ⇒ Object
- #drag_restrict(option) ⇒ Object
- #drag_start(_option) ⇒ Object
- #draw(id) ⇒ Object
- #drop_activate(_option) ⇒ Object
- #drop_common(method, native_event) ⇒ Object
- #drop_deactivate(_option) ⇒ Object
- #drop_dropped(_option) ⇒ Object
- #drop_enter(_option) ⇒ Object
- #drop_leave(_option) ⇒ Object
- #drop_remove(option) ⇒ Object
- #editor(id) ⇒ Object
-
#event(action, variance, option = nil) ⇒ Object
def drag_code(params = nil) # FIXME : this method is an ugly patch when refreshing an atome twice, else it crash # and lose it’s drag drag_move(params) end.
- #event_validation(action_proc) ⇒ Object
- #extract_properties(properties_string) ⇒ Object
- #fill(params) ⇒ Object
- #filter(property, value) ⇒ Object
- #get_page_style ⇒ Object
-
#handle_atome(atome, td_element) ⇒ Object
Helper function to handle Atome objects.
- #handle_input ⇒ Object
- #hyperedit(params, usr_bloc) ⇒ Object
- #hypertext(params) ⇒ Object
- #id(id) ⇒ Object
- #image(id) ⇒ Object
-
#initialize(id_found, current_atome) ⇒ HTML
constructor
A new instance of HTML.
- #innerText(data) ⇒ Object
- #insert_cell(params) ⇒ Object
- #insert_column(params) ⇒ Object
- #insert_row(params) ⇒ Object
- #internet ⇒ Object
- #keyboard_down(_option) ⇒ Object
- #keyboard_press(_option) ⇒ Object
- #keyboard_remove(option) ⇒ Object
- #keyboard_up(_option) ⇒ Object
-
#location(loc_found) ⇒ Object
map.
- #map_pan(params) ⇒ Object
- #map_zoom(params) ⇒ Object
- #markup(new_tag, _usr_bloc) ⇒ Object
- #match(params) ⇒ Object
- #meteo(location) ⇒ Object
-
#meteo_helper(data) ⇒ Object
meteo.
- #object ⇒ Object
-
#on(property, _option) ⇒ Object
events handlers.
- #over_enter(_option) ⇒ Object
- #over_leave(_option) ⇒ Object
- #over_over(_option) ⇒ Object
- #over_remove(option) ⇒ Object
- #overflow(params, bloc) ⇒ Object
- #path(objet_path) ⇒ Object
- #raw(id) ⇒ Object
- #raw_data(html_string) ⇒ Object
- #read(id, file) ⇒ Object
- #record_audio(params) ⇒ Object
- #record_video(params) ⇒ Object
- #refresh_table(_params) ⇒ Object
- #remove(params) ⇒ Object
- #remove_class(class_to_remove) ⇒ Object
- #remove_this_drag(option) ⇒ Object
-
#remove_this_touch(option) ⇒ Object
def touch_long(_option) @element[:cursor] = ‘pointer’ @touch_long = @original_atome.instance_variable_get(‘@touch_code’) interact = JS.eval(“return interact(‘##@id’)”) # unless @touch_removed interact.on(‘hold’) do |native_event| @touch_long_event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it’s lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc..
- #resize(params, options) ⇒ Object
- #restrict_movement(restricted_x, restricted_y) ⇒ Object
- #sanitize_text(text) ⇒ Object
- #select_text(range) ⇒ Object
- #send_message(message) ⇒ Object
- #set_td_style(td) ⇒ Object
- #setup_touch_event(event_type, _option) ⇒ Object
- #shape(id) ⇒ Object
- #stop_animation ⇒ Object
- #stop_media_recorder(id) ⇒ Object
- #stop_video_preview(id) ⇒ Object
- #style(property, value = nil) ⇒ Object
- #svg(id) ⇒ Object
- #svg_data(all_datas) ⇒ Object
-
#table(data) ⇒ Object
Table manipulation.
- #table_insert(params) ⇒ Object
- #table_remove(params) ⇒ Object
- #terminal(id, cmd) ⇒ Object
- #text(id) ⇒ Object
- #textContent(data) ⇒ Object
- #touch_double(option) ⇒ Object
- #touch_down(option) ⇒ Object
- #touch_long(option) ⇒ Object
- #touch_remove(_opt) ⇒ Object
- #touch_tap(option) ⇒ Object
- #touch_up(option) ⇒ Object
- #transform(property, value = nil) ⇒ Object
- #transform_to_string_keys_and_values(hash) ⇒ Object
-
#update_data(params) ⇒ Object
this method update the data content of the atome.
- #update_svg_data(data) ⇒ Object
- #video(id) ⇒ Object
- #video_path(video_path, type = 'video/mp4') ⇒ Object
- #video_preview(id, video, audio) ⇒ Object
- #vr(id) ⇒ Object
- #vr_path(objet_path) ⇒ Object
- #write(id, file) ⇒ Object
- #www(id) ⇒ Object
Constructor Details
#initialize(id_found, current_atome) ⇒ HTML
Returns a new instance of HTML.
28 29 30 31 32 33 34 35 |
# File 'lib/renderers/html/html.rb', line 28 def initialize(id_found, current_atome) @element = JS.global[:document].getElementById(id_found.to_s) @id = id_found @original_atome = current_atome @touch_removed = {} end |
Class Method Details
.is_descendant(ancestor, descendant) ⇒ Object
24 25 26 |
# File 'lib/renderers/html/html.rb', line 24 def self.is_descendant(ancestor, descendant) JS.eval("return isDescendant('#{ancestor}', '#{descendant}')") end |
.locate(selector, base_element = JS.global[:document][:body]) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/renderers/html/html.rb', line 6 def self.locate(selector, base_element = JS.global[:document][:body]) return base_element if selector.empty? if selector.has_key?(:id) base_element.querySelector("##{selector[:id]}") elsif selector.has_key?(:parent) parent = base_element.querySelector("##{selector[:parent]}") return nil if parent.nil? parent.querySelectorAll("*").to_a elsif selector.has_key?(:html) html_element = selector[:html] return nil if html_element.nil? html_element.querySelectorAll("*").to_a end end |
Instance Method Details
#action(_particle, action_found, option = nil) ⇒ Object
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
# File 'lib/renderers/html/html.rb', line 850 def action(_particle, action_found, option = nil) if action_found == :stop currentTime(option) @element.pause elsif action_found == :pause @element.pause else currentTime(option) proc_found = @original_atome.instance_variable_get('@play_code')[action_found] play_content = @original_atome.instance_variable_get('@play') animation_frame_callback(proc_found, play_content) @element.play end end |
#add_class(class_to_add) ⇒ Object
448 449 450 451 |
# File 'lib/renderers/html/html.rb', line 448 def add_class(class_to_add) @element[:classList].add(class_to_add.to_s) self end |
#add_css_to_atomic_style(css) ⇒ Object
60 61 62 63 64 |
# File 'lib/renderers/html/html.rb', line 60 def add_css_to_atomic_style(css) style_element = JS.global[:document].getElementById('atomic_style') text_node = JS.global[:document].createTextNode(css) style_element.appendChild(text_node) end |
#add_font_to_css(params) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/renderers/html/html.rb', line 46 def add_font_to_css(params) font_path = params[:path] font_name = params[:name] str_to_eval = " var styleSheet = document.styleSheets[0];\n styleSheet.insertRule(`\n @font-face {\n font-family: '\#{font_name}';\n src: url('../medias/fonts/\#{font_path}/\#{font_name}.ttf') format('truetype');\n }`, styleSheet.cssRules.length);\n STRDELIM\n JS.eval(str_to_eval)\nend\n" |
#animate(animation_properties) ⇒ Object
animation below
1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 |
# File 'lib/renderers/html/html.rb', line 1774 def animate(animation_properties) prop = animation_properties[:particle] command = " var target_div = document.getElementById('\#{@id}');\n window.currentAnimation = popmotion.animate({\n from: \#{animation_properties[:from]},\n to: \#{animation_properties[:to]},\n duration: \#{animation_properties[:duration]},\n onUpdate: function(v) {\n atomeJsToRuby(\"grab('\#{@id}').animation_callback('\#{prop}', \"+v+\")\")\n atomeJsToRuby(\"grab('\#{@id}').\#{prop}(\"+v+\")\")\n },\n onComplete: function(v) {\n window.currentAnimation = null;\n atomeJsToRuby(\"grab('\#{@id}').animation_callback('\#{prop}_end')\")\n }\n });\n JS\n JS.eval(command)\nend\n" |
#animation_frame_callback(proc_pass, play_content) ⇒ Object
838 839 840 841 842 843 844 845 846 847 848 |
# File 'lib/renderers/html/html.rb', line 838 def animation_frame_callback(proc_pass, play_content) JS.global[:window].requestAnimationFrame(-> () { current_time = @element[:currentTime] fps = 30 current_frame = (current_time.to_f * fps).to_i @original_atome.instance_exec({ frame: current_frame, time: current_time }, &proc_pass) if proc_pass.is_a? Proc # we update play instance variable so if user ask for atome.play it will return current frame play_content[:play] = current_frame animation_frame_callback(proc_pass, play_content) }) end |
#append(child_id_found) ⇒ Object
879 880 881 882 883 |
# File 'lib/renderers/html/html.rb', line 879 def append(child_id_found) child_found = JS.global[:document].getElementById(child_id_found.to_s) @element.appendChild(child_found) self end |
#append_to(parent_id_found) ⇒ Object
866 867 868 869 870 |
# File 'lib/renderers/html/html.rb', line 866 def append_to(parent_id_found) parent_found = JS.global[:document].getElementById(parent_id_found.to_s) parent_found.appendChild(@element) self end |
#atomized(html_object) ⇒ Object
atomisation!
2097 2098 2099 |
# File 'lib/renderers/html/html.rb', line 2097 def atomized(html_object) @element = html_object end |
#attr(attribute, value) ⇒ Object
443 444 445 446 |
# File 'lib/renderers/html/html.rb', line 443 def attr(attribute, value) @element.setAttribute(attribute.to_s, value.to_s) self end |
#audio(id) ⇒ Object
585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/renderers/html/html.rb', line 585 def audio(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :audio @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') self.id(id) self end |
#backdropFilter(property, value) ⇒ Object
829 830 831 832 |
# File 'lib/renderers/html/html.rb', line 829 def backdropFilter(property, value) filter_needed = "#{property}(#{value})" @element[:style][:"-webkit-backdrop-filter"] = filter_needed end |
#browse(id, file) ⇒ Object
1750 1751 1752 1753 1754 1755 1756 |
# File 'lib/renderers/html/html.rb', line 1750 def browse(id, file) if Atome.host == 'tauri' JS.eval("browseFile('#{id}','#{file}')") else puts 'browse file in progress in server mode' end end |
#center(options, attach) ⇒ Object
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 |
# File 'lib/renderers/html/html.rb', line 2101 def center(, attach) = @parent = grab(attach) apply_centering(, @parent) return unless [:dynamic] event_handler = ->(event) do apply_centering(, @parent) end JS.global[:window].addEventListener('resize', event_handler) end |
#check_double(id) ⇒ Object
463 464 465 466 467 |
# File 'lib/renderers/html/html.rb', line 463 def check_double(id) # we remove any element if the id already exist element_to_delete = JS.global[:document].getElementById(id.to_s) delete(id) unless element_to_delete.inspect == 'null' end |
#close_websocket ⇒ Object
282 283 284 |
# File 'lib/renderers/html/html.rb', line 282 def close_websocket @websocket.close end |
#colorize_svg_data(data) ⇒ Object
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/renderers/html/html.rb', line 702 def colorize_svg_data(data) command = " let svgElement = document.getElementById(\"\#{@id}\");\n if (!svgElement) {\n return [];\n }\n var children = svgElement.children;\n var ids = [];\n for (var i = 0; i < children.length; i++) {\n var element = document.getElementById(children[i].id); // R\u00E9cup\u00E9rer l'\u00E9l\u00E9ment par son ID\n if (element) {\n element.setAttribute('fill', '\#{data}'); // Modifier l'attribut fill\n element.setAttribute('stroke', '\#{data}'); // Modifier l'attribut stroke\n }\n ids.push(children[i].id);\n }\nreturn ids\n JS\n JS.eval(command)\nend\n" |
#connect(params, &bloc) ⇒ Object
253 254 255 256 257 258 259 |
# File 'lib/renderers/html/html.rb', line 253 def connect(params, &bloc) type = params[:type] server = params[:address] JS.eval("atomeJS.connect('#{type}','#{server}')") end |
#convert_to_css(data) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/renderers/html/html.rb', line 66 def convert_to_css(data) conditions = data[:condition] apply = data[:alterations] # Convert the conditions condition_strings = [] if conditions[:max] condition_strings << "(max-width: #{conditions[:max][:width]}px)" if conditions[:max][:width] condition_strings << "(max-height: #{conditions[:max][:height]}px)" if conditions[:max][:height] end if conditions[:min] condition_strings << "(min-width: #{conditions[:min][:width]}px)" if conditions[:min][:width] condition_strings << "(min-height: #{conditions[:min][:height]}px)" if conditions[:min][:height] end operator = conditions[:operator] == :and ? 'and' : 'or' # Convert properties to apply property_strings = [] apply.each do |key, values| inner_properties = [] values.each do |property, value| if property == :color inner_properties << "background-color: #{value} !important;" else inner_properties << "#{property}: #{value}px !important;" if value.is_a?(Integer) inner_properties << "#{property}: #{value} !important;" if value.is_a?(Symbol) end end # Prefix each key with "#" property_strings << "##{key} {\n#{inner_properties.join("\n")}\n}" end # let it build css = "@media #{condition_strings.join(" #{operator} ")} {\n#{property_strings.join("\n")}\n}" add_css_to_atomic_style(css) css end |
#css_to_data(css) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/renderers/html/html.rb', line 107 def css_to_data(css) data = { :condition => {}, :apply => {} } # Extract conditions media_conditions = css.match(/@media ([^\{]+)/)[1].split(',').map(&:strip) media_conditions.each do |condition| type = condition.match(/(max|min)-/)[1].to_sym property = condition.match(/(width|height)/)[1].to_sym value = condition.match(/(\d+)/)[1].to_i data[:condition][type] ||= {} data[:condition][type][property] = value end # Extract properties to be applied css.scan(/(\w+) \{([^\}]+)\}/).each do |match| key = match[0].to_sym properties = match[1].split(';').map(&:strip).reject(&:empty?) data[:apply][key] ||= {} properties.each do |property| prop, value = property.split(':').map(&:strip) if prop == 'background-color' data[:apply][key][:color] = value.to_sym elsif value[-2..] == 'px' data[:apply][key][prop.to_sym] = value.to_i else data[:apply][key][prop.to_sym] = value.to_sym end end end data end |
#currentTime(time) ⇒ Object
834 835 836 |
# File 'lib/renderers/html/html.rb', line 834 def currentTime(time) @element[:currentTime] = time end |
#delete(id_to_delete) ⇒ Object
872 873 874 875 876 877 |
# File 'lib/renderers/html/html.rb', line 872 def delete(id_to_delete) element_to_delete = JS.global[:document].getElementById(id_to_delete.to_s) return unless element_to_delete.to_s != 'null' return unless element_to_delete element_to_delete.remove end |
#drag_end(_option) ⇒ Object
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 |
# File 'lib/renderers/html/html.rb', line 1170 def drag_end(_option) unless @drag_end_already_set interact = JS.eval("return interact('##{@id}')") interact.on('dragend') do |native_event| drag_ends = @original_atome.instance_variable_get('@drag_code')[:end] event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_ends.each do |drag_end| proc_content = drag_end.call(event) if event_validation(drag_end) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end end @drag_end_already_set = true end |
#drag_locked(_option) ⇒ Object
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 |
# File 'lib/renderers/html/html.rb', line 1195 def drag_locked(_option) unless @drag_locked_already_set interact = JS.eval("return interact('##{@id}')") interact.draggable({ drag: true, inertia: { resistance: 12, minSpeed: 200, endSpeed: 100 } }) interact.on('dragmove') do |native_event| drag_locks = @original_atome.instance_variable_get('@drag_code')[:locked] # the use of Native is only for Opal (look at lib/platform_specific/atome_wasm_extensions.rb for more infos) event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_locks.each do |drag_lock| proc_content = drag_lock.call(event) if event_validation(drag_lock) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end end @drag_locked_already_set = true end |
#drag_move(_option) ⇒ Object
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
# File 'lib/renderers/html/html.rb', line 1026 def drag_move(_option) unless @drag_move_already_set # the condition below prevent drag accumulation interact = JS.eval("return interact('##{@id}')") unless @draggable interact.draggable({ drag: true, inertia: { resistance: 12, minSpeed: 200, endSpeed: 100 }, }) unless @first_drag interact.on('dragmove') do |native_event| drag_moves = @original_atome.instance_variable_get('@drag_code')[:move] # the use of Native is only for Opal (look at lib/platform_specific/atome_wasm_extensions.rb for more infos) event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_moves.each do |drag_move| proc_content = drag_move.call(event) if event_validation(drag_move) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end Universe.allow_tool_operations = false dx = event[:dx] dy = event[:dy] x = (@original_atome.left || 0) + dx.to_f y = (@original_atome.top || 0) + dy.to_f @original_atome.left(x) @original_atome.top(y) end end end @first_drag = true @draggable = true end @drag_move_already_set = true end |
#drag_remove(_opt) ⇒ Object
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 |
# File 'lib/renderers/html/html.rb', line 1230 def drag_remove(_opt) interact = JS.eval("return interact('##{@id}')") if @original_atome.instance_variable_get('@drag_code') = @original_atome.instance_variable_get('@drag_code')[:remove] else = false end .each do |option| if option.instance_of? Array option.each do |opt| remove_this_drag(opt) end return false end @element[:style][:cursor] = 'default' @draggable = nil case option when :start remove_this_drag(:start) when :end, :stop remove_this_drag(:end) remove_this_drag(:stop) when :move remove_this_drag(:move) when :locked remove_this_drag(:locked) when :restrict remove_this_drag(:restrict) else interact.draggable(false) end end end |
#drag_restrict(option) ⇒ Object
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 |
# File 'lib/renderers/html/html.rb', line 1075 def drag_restrict(option) unless @drag_restrict_already_set interact = JS.eval("return interact('##{@id}')") interact.draggable({ drag: true, inertia: { resistance: 12, minSpeed: 200, endSpeed: 100 }, }) if option.instance_of? Hash max_left = grab(:view).to_px(:width) max_top = grab(:view).to_px(:height) min_left = 0 min_top = 0 if option[:max] max_left = option[:max][:left] || max_left max_top = option[:max][:top] || max_top else max_left max_top end if option[:min] min_left = option[:min][:left] || min_left min_top = option[:min][:top] || min_top else min_left min_top end else parent_found = grab(option) min_left = parent_found.left min_top = parent_found.top parent_width = parent_found.compute({ particle: :width })[:value] parent_height = parent_found.compute({ particle: :height })[:value] original_width = @original_atome.width original_height = @original_atome.height max_left = min_left + parent_width - original_width max_top = min_top + parent_height - original_height end interact.on('dragmove') do |native_event| drag_moves = @original_atome.instance_variable_get('@drag_code')[:restrict] # the use of Native is only for Opal (look at lib/platform_specific/atome_wasm_extensions.rb for more infos) event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_moves.each do |drag_move| proc_content = drag_move.call(event) if event_validation(drag_move) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end dx = event[:dx] dy = event[:dy] x = (@original_atome.left || 0) + dx.to_f y = (@original_atome.top || 0) + dy.to_f restricted_x = [[x, min_left].max, max_left].min restricted_y = [[y, min_top].max, max_top].min restrict_movement(restricted_x, restricted_y) end end @drag_restrict_already_set = true end |
#drag_start(_option) ⇒ Object
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 |
# File 'lib/renderers/html/html.rb', line 1148 def drag_start(_option) unless @drag_start_already_set interact = JS.eval("return interact('##{@id}')") interact.on('dragstart') do |native_event| drag_starts = @original_atome.instance_variable_get('@drag_code')[:start] event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_starts.each do |drag_start| proc_content = drag_start.call(event) if event_validation(drag_start) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end end @drag_start_already_set = true end |
#draw(id) ⇒ Object
514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/renderers/html/html.rb', line 514 def draw(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :canvas @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') id(id) self end |
#drop_activate(_option) ⇒ Object
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 |
# File 'lib/renderers/html/html.rb', line 1286 def drop_activate(_option) unless @drop_activate_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ accept: nil, # Accept any element overlap: 0.75, ondropactivate: lambda do |native_event| drop_common(:activate, native_event) end }) end @drop_activate_already_set = true end |
#drop_common(method, native_event) ⇒ Object
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 |
# File 'lib/renderers/html/html.rb', line 1269 def drop_common(method, native_event) event = Native(native_event) draggable_element = event[:relatedTarget][:id].to_s dropzone_element = event[:target][:id].to_s # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. proc_contents = @original_atome.instance_variable_get('@drop_code')[method] proc_contents.each do |proc_content| proc_content = proc_content.call({ source: draggable_element, destination: dropzone_element }) if event_validation(proc_content) return unless proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end |
#drop_deactivate(_option) ⇒ Object
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 |
# File 'lib/renderers/html/html.rb', line 1345 def drop_deactivate(_option) unless @drop_remove_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ # accept: nil, # Accept any element # FIXME : remove because os an opal bug since 1.8 reactivate when opal will be debbuged ondropdeactivate: lambda do |native_event| drop_common(:deactivate, native_event) end }) end @drop_remove_already_set = true end |
#drop_dropped(_option) ⇒ Object
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 |
# File 'lib/renderers/html/html.rb', line 1301 def drop_dropped(_option) unless @drop_dropped_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ overlap: 0.75, # FIXME : remove because os an opal bug since 1.8 reactivate when opal will be debbuged ondrop: lambda do |native_event| drop_common(:dropped, native_event) end }) end @drop_dropped_already_set = true end |
#drop_enter(_option) ⇒ Object
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 |
# File 'lib/renderers/html/html.rb', line 1316 def drop_enter(_option) unless @drop_enter_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ overlap: 0.001, # FIXME : remove because os an opal bug since 1.8 reactivate when opal will be debbuged ondragenter: lambda do |native_event| drop_common(:enter, native_event) end }) end @drop_enter_already_set = true end |
#drop_leave(_option) ⇒ Object
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 |
# File 'lib/renderers/html/html.rb', line 1330 def drop_leave(_option) unless @drop_leave_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ # FIXME : remove because os an opal bug since 1.8 reactivate when opal will be debbuged ondragleave: lambda do |native_event| drop_common(:leave, native_event) end }) end @drop_leave_already_set = true end |
#drop_remove(option) ⇒ Object
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 |
# File 'lib/renderers/html/html.rb', line 1361 def drop_remove(option) case option when :activate @original_atome.instance_variable_get('@drop_code')[:activate] = [] when :deactivate @original_atome.instance_variable_get('@drop_code')[:deactivate] = [] when :dropped @original_atome.instance_variable_get('@drop_code')[:dropped] = [] when :enter @original_atome.instance_variable_get('@drop_code')[:enter] = [] when :leave @original_atome.instance_variable_get('@drop_code')[:leave] = [] else drop_remove(:activate) drop_remove(:deactivate) drop_remove(:dropped) drop_remove(:enter) drop_remove(:leave) end end |
#editor(id) ⇒ Object
469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/renderers/html/html.rb', line 469 def editor(id) check_double(id) editor_id = "#{id}_editor" check_double(editor_id) markup_found = @original_atome.markup || :textarea @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') id(id) self end |
#event(action, variance, option = nil) ⇒ Object
def drag_code(params = nil)
# FIXME : this method is an ugly patch when refreshing an atome twice, else it crash
# and lose it's drag
drag_move(params)
end
1017 1018 1019 |
# File 'lib/renderers/html/html.rb', line 1017 def event(action, variance, option = nil) send("#{action}_#{variance}", option) end |
#event_validation(action_proc) ⇒ Object
1566 1567 1568 |
# File 'lib/renderers/html/html.rb', line 1566 def event_validation(action_proc) action_proc.is_a?(Proc) && (!Universe.edit_mode || @original_atome.tag[:system]) end |
#extract_properties(properties_string) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/renderers/html/html.rb', line 144 def extract_properties(properties_string) properties_hash = {} properties = properties_string.split(';').map(&:strip).reject(&:empty?) properties.each do |property| key, value = property.split(':').map(&:strip) properties_hash[key] = value end properties_hash end |
#fill(params) ⇒ Object
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 |
# File 'lib/renderers/html/html.rb', line 779 def fill(params) # we remove previous background elements_to_remove = @element.getElementsByClassName('background') elements_to_remove = elements_to_remove.to_a elements_to_remove.each do |child| @element.removeChild(child) end params.each do |param| background_layer = JS.global[:document].createElement("div") background_layer[:style][:transform] = "rotate(#{param[:rotate]}deg)" # Applique une rotation de 45 degrés à l'élément background_layer[:style][:position] = "absolute" if param[:position] background_layer[:style][:top] = "#{param[:position][:x]}px" background_layer[:style][:left] = "#{param[:position][:y]}px" else background_layer[:style][:top] = "0" background_layer[:style][:left] = "0" end if param[:size] background_layer[:style][:width] = "#{param[:size][:x]}px" background_layer[:style][:height] = "#{param[:size][:y]}px" else background_layer[:style][:width] = "100%" background_layer[:style][:height] = "100%" end atome_path = grab(param[:atome]).path background_layer[:style][:backgroundImage] = "url('#{atome_path}')" background_layer[:style][:backgroundRepeat] = 'repeat' background_layer[:className] = 'background' background_layer[:style][:opacity] = param[:opacity] if param[:repeat] img_width = @original_atome.width / param[:repeat][:x] img_height = @original_atome.height / param[:repeat][:y] background_layer[:style][:backgroundSize] = "#{img_width}px #{img_height}px" else background_layer[:style][:backgroundSize] = "#{param[:width]}px #{param[:height]}px" end @element.appendChild(background_layer) end end |
#filter(property, value) ⇒ Object
824 825 826 827 |
# File 'lib/renderers/html/html.rb', line 824 def filter(property, value) filter_needed = "#{property}(#{value})" @element[:style][:filter] = filter_needed end |
#get_page_style ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/renderers/html/html.rb', line 154 def get_page_style main_view = JS.global[:document].getElementById('view') main_view_content = main_view[:innerHTML].to_s = main_view_content.split(/<\/?style[^>]*>/i).select.with_index { |_, index| index.odd? } = .join('') = .split("\n") hash_result = {} inside_media = false media_hash = {} .each do |line| line = line.strip next if line.empty? || line.start_with?('/*') if inside_media if line == '}' hash_result['@media'] << media_hash inside_media = false next end selector, properties = line.split('{').map(&:strip) next unless properties&.end_with?('}') properties = properties[0...-1].strip media_hash[selector] = extract_properties(properties) elsif line.start_with?('@media') media_content = line.match(/@media\s*\(([^)]+)\)\s*{/) next unless media_content media_query = media_content[1] hash_result['@media'] = [media_query] inside_media = true else selector, properties = line.split('{').map(&:strip) next unless properties&.end_with?('}') properties = properties[0...-1].strip hash_result[selector] = extract_properties(properties) end end hash_result end |
#handle_atome(atome, td_element) ⇒ Object
Helper function to handle Atome objects
1852 1853 1854 1855 1856 1857 1858 1859 1860 |
# File 'lib/renderers/html/html.rb', line 1852 def handle_atome(atome, td_element) atome.fit(cell_height) html_element = JS.global[:document].getElementById(atome.id.to_s) td_element.appendChild(html_element) html_element[:style][:transformOrigin] = 'top left' html_element[:style][:position] = 'relative' atome.top(0) atome.left(0) end |
#handle_input ⇒ Object
1758 1759 1760 |
# File 'lib/renderers/html/html.rb', line 1758 def handle_input @original_atome.instance_variable_set('@data', @element[:innerText].to_s) end |
#hyperedit(params, usr_bloc) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/renderers/html/html.rb', line 218 def hyperedit(params, usr_bloc) html_object = JS.global[:document].getElementById(params.to_s) particles_from_style = {} # we get all the styles tag present in the page get_page_style if html_object[:className].to_s classes_found = html_object[:className].to_s.split(' ') classes_found.each do |class_found| if get_page_style[".#{class_found}"] particles_from_style = particles_from_style.merge(get_page_style[".#{class_found}"]) end end end particles_found = {} particles_found[:data] = html_object[:innerText].to_s.chomp particles_found[:markup] = html_object[:tagName].to_s style_found = html_object[:style][:cssText].to_s style_found.split(';').each do |pair| key, value = pair.split(':').map(&:strip) particles_from_style[key.to_sym] = value if key && value end particles_found = particles_found.merge(particles_from_style) usr_bloc.call(particles_found) end |
#hypertext(params) ⇒ Object
41 42 43 44 |
# File 'lib/renderers/html/html.rb', line 41 def hypertext(params) current_div = JS.global[:document].getElementById(@id.to_s) current_div[:innerHTML] = params end |
#id(id) ⇒ Object
458 459 460 461 |
# File 'lib/renderers/html/html.rb', line 458 def id(id) attr('id', id) self end |
#image(id) ⇒ Object
560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/renderers/html/html.rb', line 560 def image(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :img @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') self.id(id) self end |
#innerText(data) ⇒ Object
743 744 745 746 |
# File 'lib/renderers/html/html.rb', line 743 def innerText(data) sanitized_data = sanitize_text(data.to_s) @element[:innerText] = sanitized_data end |
#insert_cell(params) ⇒ Object
1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 |
# File 'lib/renderers/html/html.rb', line 1912 def insert_cell(params) row_index, cell_index = params[:cell] new_content = params[:content] container = JS.global[:document].getElementById(@id.to_s) table = container.querySelector('table') if table.nil? puts 'No table found in the container' return end row = table.querySelectorAll('tr')[row_index] if row.nil? puts "Row at index #{row_index} not found" return end cell = row.querySelectorAll('td')[cell_index] if cell.nil? puts "Cell at index #{cell_index} in row #{row_index} not found" return end if new_content.instance_of? Atome cell.innerHTML = '' html_element = JS.global[:document].getElementById(new_content.id.to_s) cell.appendChild(html_element) else cell[:textContent] = new_content.to_s end end |
#insert_column(params) ⇒ Object
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 |
# File 'lib/renderers/html/html.rb', line 1974 def insert_column(params) insert_at_index = params[:column] table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Table not found' return end rows = table_element.querySelectorAll('tr').to_a rows.each_with_index do |row, index| unless index == 0 new_cell = JS.global[:document].createElement('td') new_cell[:innerText] = '' set_td_style(new_cell) if insert_at_index.zero? row.insertBefore(new_cell, row.firstChild) else child_nodes = row.querySelectorAll('td').to_a if insert_at_index < child_nodes.length reference_cell = child_nodes[insert_at_index] row.insertBefore(new_cell, reference_cell) else row.appendChild(new_cell) end end end end end |
#insert_row(params) ⇒ Object
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 |
# File 'lib/renderers/html/html.rb', line 1944 def insert_row(params) insert_at_index = params[:row] table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Tableau non trouvé' return end tbody = table_element.querySelector('tbody') header_row = table_element.querySelector('thead tr') column_count = header_row ? header_row.querySelectorAll('th').to_a.length : 0 new_row = JS.global[:document].createElement('tr') column_count.times do |cell_index| td = JS.global[:document].createElement('td') set_td_style(td) new_row.appendChild(td) end if insert_at_index.zero? tbody.insertBefore(new_row, tbody.firstChild) else reference_row = tbody.querySelectorAll('tr').to_a[insert_at_index] tbody.insertBefore(new_row, reference_row) end end |
#internet ⇒ Object
1687 1688 1689 |
# File 'lib/renderers/html/html.rb', line 1687 def internet JS.eval('return navigator.onLine') end |
#keyboard_down(_option) ⇒ Object
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 |
# File 'lib/renderers/html/html.rb', line 962 def keyboard_down(_option) @keyboard_down = @original_atome.instance_variable_get('@keyboard_code')[:down] keypress_handler = ->(event) do # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. proc_content = @keyboard_down.call(event) if event_validation(@keyboard_down) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end @element.addEventListener('keydown', keypress_handler) end |
#keyboard_press(_option) ⇒ Object
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 |
# File 'lib/renderers/html/html.rb', line 943 def keyboard_press(_option) @keyboard_press = @original_atome.instance_variable_get('@keyboard_code')[:press] keypress_handler = ->(native_event) do event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. proc_content = @keyboard_press.call(event) if event_validation(@keyboard_press) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end @element.addEventListener('keypress', keypress_handler) end |
#keyboard_remove(option) ⇒ Object
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/renderers/html/html.rb', line 996 def keyboard_remove(option) case option when :down @keyboard_down = '' when :up @keyboard_up = '' when :down @keyboard_press = '' else @keyboard_down = '' @keyboard_up = '' @keyboard_press = '' end end |
#keyboard_up(_option) ⇒ Object
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 |
# File 'lib/renderers/html/html.rb', line 979 def keyboard_up(_option) @keyboard_up = @original_atome.instance_variable_get('@keyboard_code')[:up] keypress_handler = ->(event) do # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. proc_content = @keyboard_up.call(event) if event_validation(@keyboard_up) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end @element.addEventListener('keyup', keypress_handler) end |
#location(loc_found) ⇒ Object
map
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/renderers/html/html.rb', line 287 def location(loc_found) if loc_found[:longitude] && loc_found[:latitude] long_f = loc_found[:longitude] lat_f = loc_found[:latitude] js_code = " const locatorElement = document.getElementById('\#{@id}');\n if (!locatorElement._leaflet_map) {\n const map = L.map('\#{@id}').setView([51.505, -0.09], 2); // Centrer initialement sur une position par d\u00E9faut\n L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {\n attribution: '© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors'\n }).addTo(map);\n locatorElement._leaflet_map = map;\n\n if ('\#{long_f}' === 'auto' || '\#{lat_f}' === 'auto') {\n function onLocationFound(e) {\n const radius = e.accuracy / 2;\n const locationMarker = L.marker(e.latlng).addTo(map)\n .bindPopup(`You are within ${radius} meters from this point`).openPopup();\n\n // Ajouter un ID au marqueur\n locationMarker._icon.id = '\#{@id}_locator';\n \n locationMarker.on('click', function() {\n alert(`You clicked the location marker at ${e.latlng.toString()}`);\n });\n\n const locationCircle = L.circle(e.latlng, radius).addTo(map);\n map.setView(e.latlng, map.getZoom()); // Centrer la carte sur la position trouv\u00E9e en conservant le zoom actuel\n }\n\n function onLocationError(e) {\n console.log(e.message);\n }\n\n map.on('locationfound', onLocationFound);\n map.on('locationerror', onLocationError);\n\n map.locate({ setView: true }); // Tenter de localiser l'utilisateur sans modifier le zoom\n } else {\n const lat = parseFloat('\#{lat_f}');\n const long = parseFloat('\#{long_f}');\n map.setView([lat, long], map.getZoom()); // Centrer la carte sur les coordonn\u00E9es fournies en conservant le zoom actuel\n\n const locationMarker = L.marker([lat, long]).addTo(map)\n .bindPopup('This is your point').openPopup();\n\n // Ajouter un ID au marqueur\n locationMarker._icon.id = '\#{@id}_locator';\n \n locationMarker.on('click', function() {\n alert(`You clicked the location marker at [${lat}, ${long}]`);\n });\n }\n\n // Ecouter l'\u00E9v\u00E9nement 'load' de la carte pour rafra\u00EEchir l'\u00E9cran et afficher une alerte\n map.whenReady(function() {\n map.invalidateSize();\n // important setimout re-center the view else the view is incorrect (map.invalidateSize() refresh the view)\n setTimeout(function() {\n map.invalidateSize();\n }, 0001);\n });\n } else {\n const map = locatorElement._leaflet_map;\n if ('\#{long_f}' !== 'auto' && '\#{lat_f}' !== 'auto') {\n const lat = parseFloat('\#{lat_f}');\n const long = parseFloat('\#{long_f}');\n map.setView([lat, long], map.getZoom()); // Centrer la carte sur les coordonn\u00E9es fournies en conservant le zoom actuel\n\n const locationMarker = L.marker([lat, long]).addTo(map)\n .bindPopup('This is your point').openPopup();\n\n // Ajouter un ID au marqueur\n locationMarker._icon.id = '\#{@id}_locator';\n \n locationMarker.on('click', function() {\n alert(`You clicked the location marker at [${lat}, ${long}]`);\n });\n }\n\n // Ecouter l'\u00E9v\u00E9nement 'load' de la carte pour rafra\u00EEchir l'\u00E9cran et afficher une alerte\n map.whenReady(function() {\n \n setTimeout(function() {\n map.invalidateSize();\n }, 0001);\n });\n }\n\n // Ecouter l'\u00E9v\u00E9nement de redimensionnement de la fen\u00EAtre pour r\u00E9initialiser la taille de la carte et la vue\n window.addEventListener('resize', () => {\n const map = locatorElement._leaflet_map;\n setTimeout(function() {\n map.invalidateSize();\n }, 0001);\n });\n\n\n\n JAVASCRIPT\n JS.eval(js_code)\n\n end\nend\n" |
#map_pan(params) ⇒ Object
401 402 403 404 405 406 407 408 409 410 |
# File 'lib/renderers/html/html.rb', line 401 def map_pan(params) left_found = params[:left] || 0 top_found = params[:top] || 0 js_code = " const locatorElement = document.getElementById('\#{@id}');\n const map = locatorElement._leaflet_map;\n map.panBy([\#{left_found}, \#{top_found}], { animate: true });\n JAVASCRIPT\n JS.eval(js_code)\nend\n" |
#map_zoom(params) ⇒ Object
392 393 394 395 396 397 398 399 |
# File 'lib/renderers/html/html.rb', line 392 def map_zoom(params) js_code = " const locatorElement = document.getElementById('\#{@id}');\n const map = locatorElement._leaflet_map;\n map.setZoom(\#{params});\n JAVASCRIPT\n JS.eval(js_code)\nend\n" |
#markup(new_tag, _usr_bloc) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/renderers/html/html.rb', line 198 def markup(new_tag, _usr_bloc) element_id = @id.to_s js_code = " let element = document.getElementById('\#{element_id}');\n if (!element) {\n console.error(`Element with id \"${'\#{element_id}'}\" not found.`);\n return;\n }\n let newElement = document.createElement('\#{new_tag}');\n\n newElement.style.cssText = element.style.cssText;\n Array.from(element.attributes).forEach(attr => {\n newElement.setAttribute(attr.name, attr.value);\n });\n newElement.innerHTML = element.innerHTML;\n element.parentNode.replaceChild(newElement, element);\n JAVASCRIPT\n JS.eval(js_code)\nend\n" |
#match(params) ⇒ Object
248 249 250 251 |
# File 'lib/renderers/html/html.rb', line 248 def match(params) css_converted = convert_to_css(params) css_to_data(css_converted) end |
#meteo(location) ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/renderers/html/html.rb', line 417 def meteo(location) js_code = " const url = 'https://api.openweathermap.org/data/2.5/weather?q=\#{location},fr&appid=c21a75b667d6f7abb81f118dcf8d4611&units=metric';\n async function fetchWeather() {\n try {\n let response = await fetch(url);\n\n if (!response.ok) {\n throw new Error('Erreur HTTP ! statut : ' + response.status);\n }\n\n let data = await response.json();\n\n\n let jsonString = JSON.stringify(data);\n atomeJsToRuby(\"grab('\#{@id}').html.meteo_helper(\"+jsonString+\")\");\n } catch (error) {\n console.log('Error getting meteo : ' + error.message);\n }\n }\n\n fetchWeather();\n JAVASCRIPT\n JS.eval(js_code)\nend\n" |
#meteo_helper(data) ⇒ Object
meteo
413 414 415 |
# File 'lib/renderers/html/html.rb', line 413 def meteo_helper(data) grab(@id).instance_variable_get('@meteo_code')[:meteo].call(data) end |
#object ⇒ Object
37 38 39 |
# File 'lib/renderers/html/html.rb', line 37 def object @element end |
#on(property, _option) ⇒ Object
events handlers
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 |
# File 'lib/renderers/html/html.rb', line 886 def on(property, _option) property = property.to_s if property.start_with?('media:') # extract request from property media_query = property.split(':', 2).last mql = JS.global[:window].matchMedia(media_query) event_handler = ->(event) do bloc = @original_atome.instance_variable_get('@on_code')[:view_resize] proc_content = bloc.call({ matches: event[:matches] }) if event_validation(bloc) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end # add a listener to matchMedia object mql.addListener(event_handler) elsif property == 'resize' unless @on_resize_already_set event_handler = ->(event) do width = JS.global[:window][:innerWidth] height = JS.global[:window][:innerHeight] blocs = @original_atome.instance_variable_get('@on_code')[:view_resize] blocs.each do |bloc| proc_content = bloc.call({ width: width, height: height }) if event_validation(bloc) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end JS.global[:window].addEventListener('resize', event_handler) end @on_resize_already_set = true elsif property == 'remove' alert 'ok' @original_atome.instance_variable_get('@on_code')[:view_resize] = [] else event_handler = ->(event) do proc_content = bloc.call(event) if event_validation(bloc) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end @element.addEventListener(property, event_handler) end end |
#over_enter(_option) ⇒ Object
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 |
# File 'lib/renderers/html/html.rb', line 1494 def over_enter(_option) return if @over_enter_already_set @element.addEventListener('mouseenter') do |native_event| = @original_atome.instance_variable_get('@over_code')[:enter] event = Native(native_event) .each do |over_option| proc_content = over_option.call(event) if event_validation(over_option) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end @over_enter_already_set = true # unless @over_enter_already_set # over_enters = @original_atome.instance_variable_get('@over_code')[:enter] # # return unless over_enters # # over_enters.each do |over_enter| # @over_enter_callback = lambda do |event| # # we use .call instead of instance_eval because instance_eval bring the current object as context # # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # # group etc.. # proc_content = over_enter.call(event) if event_validation(over_enter) # if proc_content.instance_of? Hash # proc_content.each do |k, v| # @original_atome.send(k, v) # end # end # end # @element.addEventListener('mouseenter', @over_enter_callback) # # end # # end # @over_enter_already_set = true end |
#over_leave(_option) ⇒ Object
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 |
# File 'lib/renderers/html/html.rb', line 1534 def over_leave(_option) return if @over_leave_already_set @element.addEventListener('mouseleave') do |native_event| over_leaves = @original_atome.instance_variable_get('@over_code')[:leave] event = Native(native_event) over_leaves.each do |over_leave| proc_content = over_leave.call(event) if event_validation(over_leave) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end @over_leave_already_set = true end |
#over_over(_option) ⇒ Object
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 |
# File 'lib/renderers/html/html.rb', line 1456 def over_over(_option) return if @over_over_already_set @element.addEventListener('mouseover') do |native_event| = @original_atome.instance_variable_get('@over_code')[:flyover] event = Native(native_event) .each do |over_option| proc_content = over_option.call(event) if event_validation(over_option) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end @over_over_already_set = true # unless @over_over_already_set # interact = JS.eval("return interact('##{@id}')") # over_overs = @original_atome.instance_variable_get('@over_code')[:flyover] # # return unless over_overs # over_overs.each do |over_over| # interact.on('mouseover') do |native_event| # over_over_event = Native(native_event) # # we use .call instead of instance_eval because instance_eval bring the current object as context # # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # # group etc.. # # proc_content = over_over.call(over_over_event) if event_validation(over_over) # if proc_content.instance_of? Hash # proc_content.each do |k, v| # @original_atome.send(k, v) # end # end # end # end # end # @over_over_already_set = true end |
#over_remove(option) ⇒ Object
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 |
# File 'lib/renderers/html/html.rb', line 1551 def over_remove(option) case option when :enter @original_atome.instance_variable_get('@over_code')[:enter] = [] when :leave @original_atome.instance_variable_get('@over_code')[:leave] = [] when :over @original_atome.instance_variable_get('@over_code')[:flyover] = [] else over_remove(:enter) over_remove(:leave) over_remove(:over) end end |
#overflow(params, bloc) ⇒ Object
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 |
# File 'lib/renderers/html/html.rb', line 1436 def overflow(params, bloc) style(:overflow, params) @overflow = @original_atome.instance_variable_get('@overflow_code')[:overflow] @element.addEventListener('scroll', lambda do |native_event| scroll_top = @element[:scrollTop].to_i scroll_left = @element[:scrollLeft].to_i # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. @overflow.call({ left: scroll_left, top: scroll_top }) if event_validation(@overflow) proc_content = @overflow.call({ left: scroll_left, top: scroll_top }) if event_validation(@overflow) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end) end |
#path(objet_path) ⇒ Object
752 753 754 755 756 757 758 759 760 |
# File 'lib/renderers/html/html.rb', line 752 def path(objet_path) @element.setAttribute('src', objet_path) # below we get image to feed width and height if needed @element[:src] = objet_path @element[:onload] = lambda do |_event| @element[:width] @element[:height] end end |
#raw(id) ⇒ Object
653 654 655 656 657 658 659 660 661 |
# File 'lib/renderers/html/html.rb', line 653 def raw(id) # we remove any element if the id already exist check_double(id) @element = JS.global[:document].createElement('div') add_class('atome') self.id(id) JS.global[:document][:body].appendChild(@element) self end |
#raw_data(html_string) ⇒ Object
723 724 725 |
# File 'lib/renderers/html/html.rb', line 723 def raw_data(html_string) @element[:innerHTML] = html_string end |
#read(id, file) ⇒ Object
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 |
# File 'lib/renderers/html/html.rb', line 1713 def read(id, file) if Atome.host == 'tauri' JS.eval("readFile('#{id}','#{file}')") else A.({data: {source: file,operation: :read }, action: :file}) do |result| proc_found= @original_atome.instance_variable_get('@read_code')[:read] string_found = JSON.parse(result[:data]) string_found=string_found.gsub('\x23', '#') converted_string = string_found.gsub(/<<(\w+)\n(.*?)\n\1/m) do marker = $1 content = $2 "\"#{content.gsub(/\n/, '\\n')}\"" # Escapes newlines for JavaScript compatibility end proc_found.call(converted_string) if proc_found.is_a?(Proc) end end end |
#record_audio(params) ⇒ Object
2116 2117 2118 2119 2120 |
# File 'lib/renderers/html/html.rb', line 2116 def record_audio(params) duration = params[:duration] * 1000 name = params[:name] JS.eval("recordAudio(#{duration},'#{@id}', '#{name}')") end |
#record_video(params) ⇒ Object
2122 2123 2124 2125 2126 |
# File 'lib/renderers/html/html.rb', line 2122 def record_video(params) duration = params[:duration] * 1000 name = params[:name] JS.eval("recordVideo(#{duration},'#{@id}', '#{name}')") end |
#refresh_table(_params) ⇒ Object
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 |
# File 'lib/renderers/html/html.rb', line 1862 def refresh_table(_params) # first we need to extact all atome from the table or they will be deleted by the table refres data = @original_atome.data data.each do |row| row.each do |k, v| v.attach(:view) if v.instance_of? Atome end end table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Table not found' return end (table_element[:rows].to_a.length - 1).downto(1) do |i| table_element.deleteRow(i) end max_cells = data.map { |row| row.keys.length }.max data.each do |row| new_row = table_element.insertRow(-1) max_cells.times do |i| key = row.keys[i] value = row[key] cell = new_row.insertCell(-1) if value.instance_of? Atome html_element = JS.global[:document].getElementById(value.id.to_s) cell.appendChild(html_element) else cell[:textContent] = value.to_s end set_td_style(cell) end end end |
#remove(params) ⇒ Object
2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 |
# File 'lib/renderers/html/html.rb', line 2016 def remove(params) # TODO: FIXME: "html : must create a case here #{params} (#{@original_atome.id})" case params when Hash params.each do |k, v| case k when :row row_index = params[:row] table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Table not found' return end rows = table_element.querySelectorAll('tbody tr').to_a if row_index >= rows.length puts "row not found : #{row_index}" true end row_to_remove = rows[row_index] row_to_remove[:parentNode].removeChild(row_to_remove) rows.each_with_index do |row, i| next if i <= row_index end when :column column_index = params[:column] table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Table not found' true end rows = table_element.querySelectorAll('tbody tr').to_a rows.each do |row| cells = row.querySelectorAll('td').to_a if column_index < cells.length cell_to_remove = cells[column_index] cell_to_remove[:parentNode].removeChild(cell_to_remove) end end when :all case v when :paint style(:background, 'none') when :color # when :shadow style('box-shadow', 'none') style('text-shadow', 'none') style("filter", 'none') else # end end end else @original_atome.apply.delete(params) style(:background, 'none') style('box-shadow', 'none') style('text-shadow', 'none') style("boxShadow", 'none') style("filter", 'none') @original_atome.apply(@original_atome.apply) end end |
#remove_class(class_to_remove) ⇒ Object
453 454 455 456 |
# File 'lib/renderers/html/html.rb', line 453 def remove_class(class_to_remove) @element[:classList].remove(class_to_remove.to_s) self end |
#remove_this_drag(option) ⇒ Object
1226 1227 1228 |
# File 'lib/renderers/html/html.rb', line 1226 def remove_this_drag(option) @original_atome.instance_variable_get('@drag_code')[option] = [] if @original_atome.instance_variable_get('@drag_code') end |
#remove_this_touch(option) ⇒ Object
def touch_long(_option)
@element[:style][:cursor] = 'pointer'
@touch_long = @original_atome.instance_variable_get('@touch_code')[:long]
interact = JS.eval("return interact('##{@id}')")
# unless @touch_removed[:long]
interact.on('hold') do |native_event|
@touch_long_event = Native(native_event)
# we use .call instead of instance_eval because instance_eval bring the current object as context
# and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape ,
# group etc..
proc_content = @touch_long.call(@touch_long_event) if event_validation(@touch_long)
if proc_content.instance_of? Hash
proc_content.each do |k, v|
@original_atome.send(k, v)
end
end
end
end
1651 1652 1653 |
# File 'lib/renderers/html/html.rb', line 1651 def remove_this_touch(option) @original_atome.instance_variable_get('@touch_code')[option] = [] if @original_atome.instance_variable_get('@touch_code') end |
#resize(params, options) ⇒ Object
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 |
# File 'lib/renderers/html/html.rb', line 1383 def resize(params, ) interact = JS.eval("return interact('##{@id}')") # Désactiver explicitement le déplacement # interact.draggable(false) if params == :remove @resize = '' interact.resizable(false) else min_width = [:min][:width] || 10 min_height = [:min][:height] || 10 max_width = [:max][:width] || 3000 max_height = [:max][:height] || 3000 @resize = @original_atome.instance_variable_get('@resize_code')[:resize] interact.resizable({ edges: { left: true, right: true, top: true, bottom: true }, inertia: true, modifiers: [], listeners: { move: lambda do |native_event| Universe.allow_tool_operations = false event = Native(native_event) proc_content = @resize.call(event) if event_validation(@resize) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end x = (@element[:offsetLeft].to_i || 0) y = (@element[:offsetTop].to_i || 0) width = event[:rect][:width] height = event[:rect][:height] # Translate when resizing from any corner x += event[:deltaRect][:left].to_f y += event[:deltaRect][:top].to_f @original_atome.width width.to_i if width.to_i.between?(min_width, max_width) @original_atome.height height.to_i if height.to_i.between?(min_height, max_height) @original_atome.left(x) @original_atome.top(y) end, }, }) end end |
#restrict_movement(restricted_x, restricted_y) ⇒ Object
1021 1022 1023 1024 |
# File 'lib/renderers/html/html.rb', line 1021 def restrict_movement(restricted_x, restricted_y) @original_atome.left(restricted_x) @original_atome.top(restricted_y) end |
#sanitize_text(text) ⇒ Object
734 735 736 737 738 739 740 741 |
# File 'lib/renderers/html/html.rb', line 734 def sanitize_text(text) text.to_s .gsub('&', "\&") .gsub('<', "\<") .gsub('>', "\>") .gsub('"', '"') .gsub("'", "\'") end |
#select_text(range) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/renderers/html/html.rb', line 538 def select_text(range) # TODO : use atome color object instead of basic css color back_color = grab(:back_selection) text_color = grab(:text_selection) back_color_rgba = "rgba(#{back_color.red * 255},#{back_color.green * 255},#{back_color.blue * 255}, #{back_color.alpha})" text_color_rgba = "rgba(#{text_color.red * 255},#{text_color.green * 255},#{text_color.blue * 255}, #{text_color.alpha})" range = JS.global[:document].createRange() range.selectNodeContents(@element) selection = JS.global[:window].getSelection() selection.removeAllRanges() selection.addRange(range) @element.focus() style = JS.global[:document].createElement('style') style[:innerHTML] = "::selection { background-color: #{back_color_rgba}; color: #{text_color_rgba}; }" JS.global[:document][:head].appendChild(style) return unless @element[:innerText].to_s.length == 1 @element[:innerHTML] = '​' end |
#send_message(message) ⇒ Object
271 272 273 274 275 276 277 278 279 280 |
# File 'lib/renderers/html/html.rb', line 271 def () # FIXME : find why we have to sanitize this message when using ruby W if Atome::host == 'pure_wasm' = transform_to_string_keys_and_values() end = JSON.generate() js_safe_string = .gsub('"', '\"') JS.eval("atomeJS.ws_sender(\"#{js_safe_string}\")") end |
#set_td_style(td) ⇒ Object
1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 |
# File 'lib/renderers/html/html.rb', line 1898 def set_td_style(td) cell_height = @original_atome.component[:height] cell_width = @original_atome.component[:width] td[:style][:backgroundColor] = 'white' td[:style][:width] = "#{cell_width}px" td[:style]['min-width'] = "#{cell_width}px" td[:style]['max-width'] = "#{cell_height}px" td[:style]['min-height'] = "#{cell_height}px" td[:style]['max-height'] = "#{cell_height}px" td[:style][:height] = "#{cell_height}px" td[:style][:overflow] = 'hidden' { cell_height: cell_height, cell_width: cell_width } end |
#setup_touch_event(event_type, _option) ⇒ Object
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 |
# File 'lib/renderers/html/html.rb', line 1570 def setup_touch_event(event_type, _option) instance_variable = "@touch_#{event_type}_already_set" unless instance_variable_get(instance_variable) @element[:style][:cursor] = 'pointer' interact = JS.eval("return interact('##{@id}')") interact.on(event_type) do |native_event| touch_event = Native(native_event) touch_needed = @original_atome.instance_variable_get('@touch_code')[event_type.to_sym] touch_needed.each do |proc_found| proc_content = proc_found.call(touch_event) if event_validation(proc_found) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end end instance_variable_set(instance_variable, true) end |
#shape(id) ⇒ Object
def editor(id)
check_double(id)
editor_id = "#{id}_editor"
check_double(editor_id)
markup_found = @original_atome.markup || :div
@element_type = markup_found.to_s
@element = JS.global[:document].createElement(@element_type)
@element.setAttribute('style', 'font-size: 12px;')
JS.global[:document][:body].appendChild(@element)
add_class('atome')
id(id)
textarea = JS.global[:document].createElement('textarea')
textarea.setAttribute('id', editor_id)
wait 0.1 do
@element.appendChild(textarea)
end
self
end
502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/renderers/html/html.rb', line 502 def shape(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :div @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') id(id) self end |
#stop_animation ⇒ Object
1795 1796 1797 |
# File 'lib/renderers/html/html.rb', line 1795 def stop_animation JS.eval('if (window.currentAnimation) window.currentAnimation.stop();') end |
#stop_media_recorder(id) ⇒ Object
2136 2137 2138 |
# File 'lib/renderers/html/html.rb', line 2136 def stop_media_recorder(id) JS.eval("writeatomestore('#{id}', 'record', 'stop')") end |
#stop_video_preview(id) ⇒ Object
2128 2129 2130 |
# File 'lib/renderers/html/html.rb', line 2128 def stop_video_preview(id) JS.eval("stopPreview('#{id}')") end |
#style(property, value = nil) ⇒ Object
767 768 769 770 771 772 773 774 775 776 777 |
# File 'lib/renderers/html/html.rb', line 767 def style(property, value = nil) if value @element[:style][property] = value.to_s elsif value.nil? @element[:style][property] else # If value is explicitly set to false, remove the property command = "document.getElementById('#{@id}').style.removeProperty('#{property}')" JS.eval(command) end end |
#svg(id) ⇒ Object
663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
# File 'lib/renderers/html/html.rb', line 663 def svg(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || 'svg' @element_type = markup_found.to_s svg_ns = 'http://www.w3.org/2000/svg' @element = JS.global[:document].createElementNS(svg_ns, 'svg') JS.global[:document][:body].appendChild(@element) @element.setAttribute('viewBox', '0 0 1024 1024') @element.setAttribute('version', '1.1') add_class('atome') self.id(id) self end |
#svg_data(all_datas) ⇒ Object
678 679 680 681 682 683 684 685 686 687 688 689 690 691 |
# File 'lib/renderers/html/html.rb', line 678 def svg_data(all_datas) all_datas.each do |full_data| full_data.each do |type_passed, datas| svg_ns = 'http://www.w3.org/2000/svg' new_path = JS.global[:document].createElementNS(svg_ns.to_s, type_passed.to_s) JS.global[:document][:body].appendChild(new_path) datas.each do |property, value| new_path.setAttribute(property.to_s, value.to_s) end @element.appendChild(new_path) end end end |
#table(data) ⇒ Object
Table manipulation
1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 |
# File 'lib/renderers/html/html.rb', line 1801 def table(data) table_html = JS.global[:document].createElement('table') thead = JS.global[:document].createElement('thead') max_length = data.max_by { |row| row.keys.length }.keys.length if @original_atome.option[:header] header_row = JS.global[:document].createElement('tr') max_length.times do |i| th = JS.global[:document].createElement('th') th[:textContent] = data.map { |row| row.keys[i].to_s }.compact.first || '' header_row.appendChild(th) end thead.appendChild(header_row) end table_html.appendChild(thead) tbody = JS.global[:document].createElement('tbody') data.each_with_index do |row, _row_index| tr = JS.global[:document].createElement('tr') max_length.times do |cell_index| td = JS.global[:document].createElement('td') cell_size = set_td_style(td) cell_height = cell_size[:cell_height] cell_value = row.values[cell_index] if cell_value.instance_of? Atome cell_value.fit(cell_height) html_element = JS.global[:document].getElementById(cell_value.id.to_s) td.appendChild(html_element) html_element[:style][:transformOrigin] = 'top left' html_element[:style][:position] = 'relative' cell_value.top(0) cell_value.left(0) else td[:textContent] = cell_value.to_s end tr.appendChild(td) end tbody.appendChild(tr) end table_html.appendChild(tbody) JS.global[:document].querySelector("##{@id}").appendChild(table_html) end |
#table_insert(params) ⇒ Object
2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 |
# File 'lib/renderers/html/html.rb', line 2005 def table_insert(params) if params[:cell] insert_cell(params) elsif params[:row] insert_row(params) elsif params[:column] insert_column(params) end end |
#table_remove(params) ⇒ Object
2088 2089 2090 2091 2092 2093 2094 |
# File 'lib/renderers/html/html.rb', line 2088 def table_remove(params) if params[:row] # elsif params[:column] # end end |
#terminal(id, cmd) ⇒ Object
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 |
# File 'lib/renderers/html/html.rb', line 1693 def terminal(id, cmd) if Atome.host == 'tauri' JS.eval("terminal('#{id}','#{cmd}')") else # JS.eval("distant_terminal('#{id}','#{cmd}')") A.({data: cmd, action: :terminal}) do |result| proc_found= @original_atome.terminal_code[:terminal] string_found = result[:data] string_found=string_found.gsub('\x23', '#') converted_string = string_found.gsub(/<<(\w+)\n(.*?)\n\1/m) do marker = $1 content = $2 "\"#{content.gsub(/\n/, '\\n')}\"" # Escapes newlines for JavaScript compatibility end proc_found.call(converted_string) if proc_found.is_a?(Proc) end end end |
#text(id) ⇒ Object
526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/renderers/html/html.rb', line 526 def text(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :pre @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') id(id) self end |
#textContent(data) ⇒ Object
748 749 750 |
# File 'lib/renderers/html/html.rb', line 748 def textContent(data) @element[:textContent] = data end |
#touch_double(option) ⇒ Object
1604 1605 1606 |
# File 'lib/renderers/html/html.rb', line 1604 def touch_double(option) setup_touch_event('doubletap', option) end |
#touch_down(option) ⇒ Object
1592 1593 1594 |
# File 'lib/renderers/html/html.rb', line 1592 def touch_down(option) setup_touch_event('down', option) end |
#touch_long(option) ⇒ Object
1608 1609 1610 |
# File 'lib/renderers/html/html.rb', line 1608 def touch_long(option) setup_touch_event('hold', option) end |
#touch_remove(_opt) ⇒ Object
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 |
# File 'lib/renderers/html/html.rb', line 1655 def touch_remove(_opt) if @original_atome.instance_variable_get('@touch_code') option = @original_atome.instance_variable_get('@touch_code')[:remove] else option = false end @element[:style][:cursor] = 'default' case option when :double remove_this_touch(:double) when :down remove_this_touch(:down) when :long remove_this_touch(:long) when :tap remove_this_touch(:tap) when :touch remove_this_touch(:touch) when :up remove_this_touch(:up) else remove_this_touch(:double) remove_this_touch(:down) remove_this_touch(:long) remove_this_touch(:touch) remove_this_touch(:double) remove_this_touch(:up) end end |
#touch_tap(option) ⇒ Object
1600 1601 1602 |
# File 'lib/renderers/html/html.rb', line 1600 def touch_tap(option) setup_touch_event('tap', option) end |
#touch_up(option) ⇒ Object
1596 1597 1598 |
# File 'lib/renderers/html/html.rb', line 1596 def touch_up(option) setup_touch_event('up', option) end |
#transform(property, value = nil) ⇒ Object
762 763 764 765 |
# File 'lib/renderers/html/html.rb', line 762 def transform(property, value = nil) transform_needed = "#{property}(#{value}deg)" @element[:style][:transform] = transform_needed.to_s end |
#transform_to_string_keys_and_values(hash) ⇒ Object
261 262 263 264 265 266 267 268 269 |
# File 'lib/renderers/html/html.rb', line 261 def transform_to_string_keys_and_values(hash) hash.transform_keys(&:to_s).transform_values do |value| if value.is_a?(Hash) transform_to_string_keys_and_values(value) else value.to_s end end end |
#update_data(params) ⇒ Object
this method update the data content of the atome
1763 1764 1765 1766 1767 1768 1769 1770 1771 |
# File 'lib/renderers/html/html.rb', line 1763 def update_data(params) # we update the @data of the atome @input_listener ||= lambda { |event| handle_input } if params @element.addEventListener('input', &@input_listener) else @element.removeEventListener('input', &@input_listener) end end |
#update_svg_data(data) ⇒ Object
693 694 695 696 697 698 699 700 |
# File 'lib/renderers/html/html.rb', line 693 def update_svg_data(data) data.each do |type_passed, datas| element_to_update = JS.global[:document].getElementById(type_passed.to_s) datas.each do |property, value| element_to_update.setAttribute(property.to_s, value.to_s) end end end |
#video(id) ⇒ Object
573 574 575 576 577 578 579 580 581 582 583 |
# File 'lib/renderers/html/html.rb', line 573 def video(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :video @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') self.id(id) self end |
#video_path(video_path, type = 'video/mp4') ⇒ Object
727 728 729 730 731 732 |
# File 'lib/renderers/html/html.rb', line 727 def video_path(video_path, type = 'video/mp4') source = JS.global[:document].createElement('source') source.setAttribute('src', video_path) source.setAttribute('type', type) @element.appendChild(source) end |
#video_preview(id, video, audio) ⇒ Object
2132 2133 2134 |
# File 'lib/renderers/html/html.rb', line 2132 def video_preview(id, video, audio) JS.eval("create_preview('#{id}','#{video}','#{audio}')") end |
#vr(id) ⇒ Object
597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/renderers/html/html.rb', line 597 def vr(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :div @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') self.id(id) self end |
#vr_path(objet_path) ⇒ Object
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/renderers/html/html.rb', line 610 def vr_path(objet_path) js_code = " initWithParam('\#{objet_path}', '\#{@id}', 'method', 'params');\n JAVASCRIPT\n\n JS.eval(js_code)\n # tags = <<~HTML\n # <a-scene embedded>\n # <a-sky src=\"\#{objet_path}\" rotation=\"0 -130 0\"></a-sky>\n # <a-text font=\"kelsonsans\" value=\"Puy de Sancy, France\" width=\"6\" position=\"-2.5 0.25 -1.5\" rotation=\"0 15 0\"></a-text>\n # <!-- Hotspot -->\n # <a-sphere id=\"clickable\" color=\"#FF0000\" radius=\"0.1\" position=\"0 1 -2\"\n # event-set__mouseenter=\"_event: mouseenter; color: green\"\n # event-set__mouseleave=\"_event: mouseleave; color: red\"></a-sphere>\n # <!-- Camera with cursor to detect clicks -->\n # </a-scene>\n # HTML\n # @element[:innerHTML] = tags\n #\n # # Ajouter un \u00E9couteur d'\u00E9v\u00E9nement pour le hotspot\n # cursor = JS.global[:document].getElementById('cursor')\n # cursor.addEventListener('click', -> {\n # target = cursor.components.cursor.intersectedEl\n # if target && target.id == 'clickable'\n # alert :yes\n # end\n # })\n\nend\n" |
#write(id, file) ⇒ Object
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 |
# File 'lib/renderers/html/html.rb', line 1731 def write(id, file) if Atome.host == 'tauri' JS.eval("writeFile('#{id}','#{file[:name]}','#{file[:content]}')") else A.({data: {source: file,operation: :write }, action: :file}) do |result| proc_found= @original_atome.instance_variable_get('@write_code')[:write] string_found = JSON.parse(result[:data]) string_found=string_found.gsub('\x23', '#') converted_string = string_found.gsub(/<<(\w+)\n(.*?)\n\1/m) do marker = $1 content = $2 "\"#{content.gsub(/\n/, '\\n')}\"" # Escapes newlines for JavaScript compatibility end proc_found.call(converted_string) if proc_found.is_a?(Proc) end end end |
#www(id) ⇒ Object
640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/renderers/html/html.rb', line 640 def www(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :iframe @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') @element.setAttribute('src', 'https://www.youtube.com/embed/lLeQZ8Llkso?si=MMsGBEXELy9yBl9R') self.id(id) self end |