Top Level Namespace
Defined Under Namespace
Modules: Browser, Diamonds, Kernel
Classes: Hash, NilClass, Numeric, Object, Proc, Promise, String, Timeout
Constant Summary
collapse
- BROWSER_ENGINE =
The engine the browser is running on.
Keep in mind it uses the user agent to know, so it’s not reliable in case of spoofing.
`/MSIE|WebKit|Presto|Gecko/.exec(navigator.userAgent)[0]`.downcase rescue :unknown
Instance Method Summary
collapse
Instance Method Details
#alert(message) ⇒ Object
96
97
98
99
100
|
# File 'lib/diamonds/gems/ruby_to_js.rb', line 96
def alert message
message=message.gsub("'","\"")
teleport_to_client_view "alert '" +message+"'"
end
|
#bind_create_module ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/diamonds/apps/library.rb', line 128
def bind_create_module
Element.find("#module_creator").on :click do
number_of_modules=`$('#module_utils').attr('number_of_modules')`
id= "mon_module_nb_#{number_of_modules}"
classname= "editablecontent modules"
name= "les infos"
content=" module vide"
Element.find("#master_items").append("<div id='#{id}' class='#{classname}' name='#{name}'>#{content}</div>")
Native `$('.modules').draggable()`
number_of_modules=number_of_modules.to_i+1
number_of_modules=number_of_modules.to_s
Element.find("#module_utils").attr("number_of_modules", number_of_modules)
end
end
|
#bind_modules_list ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/diamonds/apps/library.rb', line 218
def bind_modules_list
Element.find("#modules_list").on :click do
@activeFlow.send({:action => "read_modules_list", :pass => "pass"}.to_json);
Timeout.new 1000 do
Element.find(".module_available").on :click do |evt|
module_requested= evt.current_target.html
@activeFlow.send({:action => "get_module", :pagecontent => module_requested, :currentpage => @page_adress, :pass => "pass"}.to_json);
end
end
end
end
|
#bind_modules_on_page ⇒ Object
230
231
232
233
234
235
236
237
238
239
240
|
# File 'lib/diamonds/apps/library.rb', line 230
def bind_modules_on_page
Element.find("#modules_on_page").on :click do
if @page_adress.nil?
@page_adress=""
end
@activeFlow.send({:action => "read_modules_on_page", :currentpage => @page_adress, :pass => "pass"}.to_json);
end
end
|
#bind_modules_utils ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/diamonds/apps/library.rb', line 148
def bind_modules_utils
Element.find("#module_utils").on :click do
elementexist= Element.find("#module_creator").attr :id
if elementexist.nil?
Element.find("#modulebox").append("<div id='modules_container' class='modules_container'></div>")
Element.find("#modules_container").append("<div id='module_creator' class='module_creator'>New</div>")
Element.find("#modules_container").append("<div id='modules_list' class='modules_list'>list</div>")
Element.find("#modules_container").append("<div id='modules_on_page' class='modules_on_page'>on page</div>")
Element.find("#modules_container").append("<div id='module_infos' class='module_infos'>infos</div>")
bind_create_module
bind_modules_list
bind_modules_on_page
else
Element.find("#modules_container").remove
end
end
end
|
#bind_save ⇒ Object
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/diamonds/apps/library.rb', line 191
def bind_save
Element.find("#save_page").on :click do
editablecontent = Element.find(".modules")
list_of_modules_on_page=[]
editablecontent.each do |content|
item_id= content.id.to_sym
list_of_modules_on_page << item_id
module_content= Native `get_full_object(#{item_id})`
save_module ({item_id => module_content})
end
temp_item=Element.find(".system_object")
`$( ".system_object").remove()`
page_content= Element.find("#page_content")
item_id= @page_adress
save_list_of_modules_on_page ({item_id => list_of_modules_on_page})
item_to_save=page_content.html
save_page ({item_id => item_to_save})
Element.find("#page_content").append(temp_item)
end
end
|
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/diamonds/apps/library.rb', line 168
def bind_tools
Element.find("#tools").on :click do
elementexist= Element.find("#tool_handler").attr :id
if elementexist.nil?
Element.find("#toolbox").append("<div id='tools_container' class='tools_container'></div>")
Element.find("#tools_container").append("<div id='tool_handler' class='tool_handler'></div>")
Element.find("#tool_handler").append("<div id='move_or_edit' class='move_or_edit'>mover</div>")
Element.find("#move_or_edit").on :click do
move_or_edit_fct
end
else
Element.find("#tools_container").remove
end
end
end
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/diamonds/apps/library.rb', line 94
def bindHref
Element.find("a").on :mousedown do |acontent|
@startime=gettime
end
Element.find("a").on :mouseup do |acontent|
@endtime= gettime
totaltime=@endtime-@startime
editionstate= Element.find("#authentifier").css("display")
begin
if editionstate=="block"
end
rescue
editionstate="none"
end
pass=Element.find("#passhere").text
target =acontent.current_target.attr("href")
if editionstate=="block"
if totaltime >1000
Native `window.location.href = #{target}+'?pass='+#{pass}`
end
else
Native `window.location.href = #{target}+'?pass='+#{pass}`
end
end
end
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/diamonds/gems/auto_launch_browser.rb', line 2
def browse
Thread.new {
begin
def up?(site)
uri = URI(site)
Net::HTTP.get(uri)
end
up? 'http://localhost:9292'
rescue
retry
ensure
`open http://localhost:9292`
end
}
end
|
#create_default_objet ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/diamonds/apps/library.rb', line 79
def create_default_objet
Element.find("#menubox").append("<div id='menus_container' class='menus_container'></div>")
Element.find("#menus_container").append("<div id='save_page' class='save_page'>Save</div>")
Element.find("#menus_container").append("<div id='toolbox' class='toolbox'></div>")
Element.find("#toolbox").append("<div id='tools' class='tools'>Tools List</div>")
Element.find("#menus_container").append("<div id='modulebox' class='modulebox'></div>")
Element.find("#modulebox").append("<div id='module_utils' class='module_utils'>Modules</div>")
bind_modules_utils
end
|
#ellipse(params) ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/diamonds/gems/ruby_to_js.rb', line 122
def ellipse params
type= params[:type]||'div'
objclass= params[:objclass]||'objclass'
id= params[:id]||last_ID_created
target= params[:target]||'#master_items'
position= params[:position]||'absolute'
width= params[:width]||'100px'
height= params[:height]||'100px'
top= params[:top]||'70px'
left= params[:left]||'70px'
background_color= params[:background_color]||'red'
color= params[:color]||'white'
style= params[:style]||''
text= params[:text]||'ok'
z_index=params[z_index]||'0'
border_style= params[:border_style]||'none'
border_width= params[:border_width]||'0px'
border_color= params[:border_color]||'transparent'
border_radius= params[:border_radius]||'0px'
send_this = <<HEREDOC
Element.find("#{target}").append("<style>.#{id}{position:#{position} ;z-index:#{z_index};width:#{width}; height:#{height};top:#{left};left:#{left};background-color:#{background_color};color:#{color};border-style:#{border_style};border-width:#{border_width};border-color:#{border_color};border-radius: #{border_radius};#{style};}</style>")
Element.find("#{target}").append("<#{type} id='#{id}' class='system_object #{objclass} #{id}'>#{text}</#{type}>")
HEREDOC
teleport_to_client_view send_this
end
|
#file_read(file) ⇒ Object
1
2
3
4
5
6
7
8
9
10
|
# File 'lib/diamonds/gems/io.rb', line 1
def file_read file
filetoget=file.to_s
if File.exist?(filetoget)
filetosend= File.read(filetoget)
else
filetosend= File.read("./userpages/utilpages/pagenotfound")
end
return filetosend
end
|
#file_write(file) ⇒ Object
12
13
14
|
# File 'lib/diamonds/gems/io.rb', line 12
def file_write file
end
|
#get_modules_content(tablename, column = :title) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/diamonds/gems/io.rb', line 113
def get_modules_content (tablename, column=:title)
site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3")
begin
content_found= site_DB[tablename][column][:content]
rescue
content_found=""
end
return content_found
end
|
#last_ID_created ⇒ Object
76
77
78
79
80
81
|
# File 'lib/diamonds/gems/ruby_to_js.rb', line 76
def last_ID_created
last_ID_saved= File.read("../diamonds/user_app/ID_Repository.txt")
last_ID_saved=last_ID_saved.to_i+1
File.write("../diamonds/user_app/ID_Repository.txt", last_ID_saved)
return "source_obj_#{last_ID_saved}"
end
|
#machinize(fluxToSend, current_page, message) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/diamonds/gems/server_utils.rb', line 39
def machinize(fluxToSend, current_page, message)
msg_received=case message[:action]
when "save"
content= message[:pagecontent]
pagename= message[:currentpage]
save(:pages, :title => current_page, :content => content)
when "save_list_of_modules_on_page"
content= message[:pagecontent]
pagename= message[:currentpage]
save(:pages, :title => current_page, :modules_on_page => content.join(","))
when "save_menus_on_page"
content= message[:pagecontent]
pagename= message[:currentpage]
save(:pages, :title => current_page, :menus_on_page => content)
when "save_module"
content= message[:pagecontent]
pagename= message[:currentpage]
save(:modules, :title => pagename, :content => content)
when "get_module"
content= message[:pagecontent]
module_found=get_modules_content(:modules, :title => content)
module_found="<script>$('#master_items').append('#{module_found}');$('.modules').draggable()</script>"
module_found=(module_found).to_json
@fluxToSend.send module_found
when "read_modules_list"
module_found= read_modules_list
module_found= module_found.join("</li><li class=\\'module_available\\'>")
module_found="<ul><li class=\\'module_available\\'>#{module_found}</li></ul>"
module_found="<script>$('#module_infos').html('#{module_found}')</script>"
module_found=(module_found).to_json
@fluxToSend.send module_found
when "list_modules_number"
number_found= read_modules_list.length.to_s
number_found="<script>$('#module_utils').attr('number_of_modules','#{number_found}')</script>"
number_found=(number_found).to_json
@fluxToSend.send number_found
when "read_modules_on_page"
pagename= message[:currentpage]
module_requested=read_modules_on_page(:pages, :title => pagename)
if !module_requested.nil?
module_requested=module_requested.split(",")
module_requested= module_requested.join("</li><li class=\\'module_on_page\\'>")
module_requested="<ul><li class=\\'module_on_page\\'>#{module_requested}</li></ul>"
module_requested="<script>$('#module_infos').html('#{module_requested}')</script>"
module_requested=(module_requested).to_json
@fluxToSend.send module_requested
end
else
end
end
|
#make_it_draggable ⇒ Object
302
303
304
305
306
307
308
309
|
# File 'lib/diamonds/apps/library.rb', line 302
def make_it_draggable
Native `$('.modules').draggable()`
Native `$('.editablecontent').find("img").draggable()`
Native `$('.editablecontent').find("div").not(".system_object").draggable()`
end
|
28
29
30
|
# File 'lib/diamonds/apps/library.rb', line 28
def montest
alert "mon test succeed !!!"
end
|
#quick_read(datas) ⇒ Object
67
68
69
70
|
# File 'lib/diamonds/gems/io.rb', line 67
def quick_read (datas)
datas={:title => datas}
read(:maintable, datas)
end
|
#quick_save(datas) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/diamonds/gems/io.rb', line 60
def quick_save(datas)
key, value = datas.first
title=key
content= value
save(:maintable, :title => title, :content => content)
end
|
#read_file(datas) ⇒ Object
271
272
273
274
275
276
277
278
|
# File 'lib/diamonds/apps/library.rb', line 271
def read_file (datas)
alert "ou ici"
pass= Element.find('#passhere').text
key, value = datas.first
title=key
title= value
@activeFlow.send({:action => "read", :currentpage => value, :pass => pass}.to_json);
end
|
#read_modules_list ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/diamonds/gems/io.rb', line 91
def read_modules_list
site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3")
modules_list=[]
site_DB.fetch "SELECT * from modules" do |data|
modules_list<< data[:title]
end
return modules_list
end
|
#read_modules_on_page(tablename, column = :title) ⇒ Object
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/diamonds/gems/io.rb', line 102
def read_modules_on_page (tablename, column=:title)
site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3")
begin
module_found= site_DB[tablename][column][:modules_on_page]
rescue
module_found=""
end
return module_found
end
|
#read_page(tablename, datas) ⇒ Object
72
73
74
75
76
|
# File 'lib/diamonds/gems/io.rb', line 72
def read_page(tablename, datas)
key, value = datas.first
site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3")
return current_item = site_DB[tablename][datas]
end
|
#read_ppage(fluxToSend, current_page) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/diamonds/gems/server_utils.rb', line 7
def read_ppage (fluxToSend, current_page)
@fluxToSend=fluxToSend
get_page= read_page(:pages, :title => current_page)
if get_page.nil?
pagecontent="default message to user, when empty page found"
else
pagecontent= get_page[:content]
end
requested_module_name=read_modules_on_page(:pages, :title => current_page)
if !requested_module_name.nil?
module_to_insert_on_page=requested_module_name.split(",")
else
module_to_insert_on_page=["vide"]
end
modules_content=""
module_to_insert_on_page.each do |module_to_get|
modules_content=get_modules_content(:modules, :title => module_to_get)+modules_content
end
pagecontent=pagecontent+modules_content
set_page pagecontent, "page_content", "editablecontent"
end
|
#read_sensor(datas) ⇒ Object
280
281
282
283
284
285
|
# File 'lib/diamonds/apps/library.rb', line 280
def read_sensor (datas)
pass= Element.find('#passhere').text
key, value = datas.first
title= value
@activeFlow.send({:action => "readsensor", :currentpage => value, :pass => pass}.to_json);
end
|
#remove_drag ⇒ Object
312
313
314
315
316
317
318
319
320
|
# File 'lib/diamonds/apps/library.rb', line 312
def remove_drag
make_it_draggable
Native `$('.modules').draggable('destroy')`
Native `$('.editablecontent').find('img').draggable('destroy')`
Native `$('.editablecontent').find('div').draggable('destroy')`
end
|
#save(tablename, datas) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/diamonds/gems/io.rb', line 79
def save(tablename, datas)
site_DB = Sequel.connect("sqlite://db/mysiteDB.sqlite3")
key, value = datas.first
if site_DB[tablename][key => value].nil?
site_DB[tablename].insert(datas)
else
current_item = site_DB[tablename].where(key => value)
current_item.update(datas)
end
end
|
#save_list_of_modules_on_page(datas) ⇒ Object
261
262
263
264
265
266
267
268
|
# File 'lib/diamonds/apps/library.rb', line 261
def save_list_of_modules_on_page (datas)
key, value = datas.first
title=key
content= value
@activeFlow.send({:action => "save_list_of_modules_on_page", :pagecontent => content, :currentpage => @page_adress, :pass => "pass"}.to_json);
end
|
#save_module(datas) ⇒ Object
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/diamonds/apps/library.rb', line 250
def save_module (datas)
key, value = datas.first
title=key
content= value
@activeFlow.send({:action => "save_module", :pagecontent => content, :currentpage => title, :pass => "pass"}.to_json);
end
|
#save_page(datas) ⇒ Object
242
243
244
245
246
247
248
|
# File 'lib/diamonds/apps/library.rb', line 242
def save_page (datas)
pass= Element.find('#passhere').text
key, value = datas.first
title=key
content= value
@activeFlow.send({:action => "save", :pagecontent => content, :currentpage => @page_adress, :pass => "pass"}.to_json);
end
|
#set_default_page ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/diamonds/apps/library.rb', line 32
def set_default_page
Element.find("body").append("<div id='menubox' class='menubox'></div>")
Element.find("#menubox").append("<div id='edittoggle' class='edit'>Edit</div>")
Element.find("#edittoggle").on :click do
@activeFlow.send({:action => "list_modules_number", :pass => "pass"}.to_json);
def move_or_edit_fct
if @edit_mode=="move"
@edit_mode="edit"
remove_drag
elsif @edit_mode=="edit"
@edit_mode="move"
make_it_draggable
end
end
edittoggle=Element.find(".editablecontent")
if edittoggle.has_class?("wysiwyg-editor")
if edittoggle.attr("contenteditable")=="true"
Element.find("#menus_container").remove
edittoggle.remove_attr("contenteditable")
remove_drag
elsif edittoggle.attr("contenteditable").nil?
create_default_objet
bind_save
bind_tools
make_it_draggable
edittoggle.attr("contenteditable", "true")
end
else
create_default_objet
bind_save
bind_tools
make_it_draggable
Native `editcontent()`
end
end
Native `$('#menubox').draggable()`
end
|
#set_page(content, id = time, css_class = "standard_object") ⇒ Object
34
35
36
37
|
# File 'lib/diamonds/gems/server_utils.rb', line 34
def set_page content, id=time, css_class="standard_object"
content=(content).to_json
@fluxToSend.send content
end
|
#teleport_to_client_view(message) ⇒ Object
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/diamonds/gems/ruby_to_js.rb', line 82
def teleport_to_client_view message
open("./apps/user_app.rb", 'a') { |f|
f.puts message
}
end
|
#the_big_verif ⇒ Object
164
165
166
|
# File 'lib/diamonds/gems/ruby_to_js.rb', line 164
def the_big_verif
puts "ok ok\n"*99
end
|
1
2
3
4
5
|
# File 'lib/diamonds/gems/server_utils.rb', line 1
def time
time= Time.now
return "#{time.year}_#{time.month}_#{time.day}_#{time.hour}_#{time.min}_#{time.sec}"
end
|
#timeout(params) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/diamonds/gems/ruby_to_js.rb', line 105
def timeout params
fct=params[:function]
time=params[:delay]
send_this = <<HEREDOC
Timeout.new #{time} do
#{fct}
#montest
end
HEREDOC
teleport_to_client_view send_this
end
|