cyberweb 0.5.225 → 0.6.17

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of cyberweb might be problematic. Click here for more details.

Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +438 -238
  3. data/doc/README.gen +437 -237
  4. data/doc/todo/todo_for_the_cyberweb_project.md +6 -0
  5. data/examples/advanced/cursor_example/cursor_example.cgi +29 -0
  6. data/examples/advanced/draw_circle/draw_circle.cgi +13 -4
  7. data/examples/css/css_bubbles.html +8 -2
  8. data/examples/css/examples_with_borders/examples_with_borders.html +33 -0
  9. data/examples/javascript_and_jquery/copy_to_the_clipboard_example/copy_to_the_clipboard_example.html +80 -0
  10. data/images/cyberweb_theme.png +0 -0
  11. data/lib/cyberweb/base/misc.rb +67 -18
  12. data/lib/cyberweb/base_module/base_module.rb +66 -8
  13. data/lib/cyberweb/cascading_style_sheets/cursors.css +12 -5
  14. data/lib/cyberweb/cascading_style_sheets/default.css +20 -18
  15. data/lib/cyberweb/cascading_style_sheets/glow_effects.css +12 -6
  16. data/lib/cyberweb/cascading_style_sheets/misc.css +12 -1
  17. data/lib/cyberweb/generator/cgi.rb +3 -3
  18. data/lib/cyberweb/html_template/html_template.rb +172 -114
  19. data/lib/cyberweb/javascript/javascript.rb +34 -31
  20. data/lib/cyberweb/javascript_code/copy_to_the_clipboard.js +12 -0
  21. data/lib/cyberweb/jquery_module/jquery_module.rb +51 -0
  22. data/lib/cyberweb/modules/css_style.rb +27 -0
  23. data/lib/cyberweb/{favicon → modules}/favicon.rb +162 -33
  24. data/lib/cyberweb/requires/require_the_cyberweb_project.rb +6 -2
  25. data/lib/cyberweb/toplevel_methods/download_webpage.rb +16 -2
  26. data/lib/cyberweb/toplevel_methods/html_tables.rb +42 -30
  27. data/lib/cyberweb/toplevel_methods/log_directory.rb +11 -8
  28. data/lib/cyberweb/toplevel_methods/misc.rb +84 -47
  29. data/lib/cyberweb/toplevel_methods/path.rb +29 -8
  30. data/lib/cyberweb/toplevel_methods/temp_directory.rb +3 -1
  31. data/lib/cyberweb/version/version.rb +2 -2
  32. data/lib/cyberweb/web_images/map_symbol_to_image_location.rb +43 -7
  33. data/lib/cyberweb/web_object/favicon.rb +4 -106
  34. data/lib/cyberweb/web_object/html_tags.rb +133 -65
  35. data/lib/cyberweb/web_object/images.rb +20 -20
  36. data/lib/cyberweb/web_object/javascript_and_jquery.rb +39 -16
  37. data/lib/cyberweb/web_object/link.rb +18 -15
  38. data/lib/cyberweb/web_object/misc.rb +4158 -327
  39. data/lib/cyberweb/web_object/reset.rb +19 -15
  40. data/lib/cyberweb/web_object/run.rb +2 -0
  41. data/lib/cyberweb/web_object/web_object.rb +1 -3584
  42. data/lib/cyberweb/webmin/simple_forum/index.cgi +30 -0
  43. data/lib/cyberweb/webmin/simple_forum/simple_forum.rb +134 -0
  44. data/lib/cyberweb/yaml/http_status_codes.yml +3 -0
  45. data/lib/cyberweb/yaml/js_files_to_load.yml +6 -1
  46. data/test/html_template/html_template.rb +22 -3
  47. data/test/simple_tests/testing_the_javascript_component.cgi +32 -0
  48. data/test/simple_tests/testing_the_select_tag.cgi +7 -1
  49. metadata +13 -4
@@ -36,6 +36,10 @@ module Cyberweb
36
36
 
37
37
  class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
38
38
 
39
+ require 'cyberweb/jquery_module/jquery_module.rb'
40
+ require 'cyberweb/modules/favicon.rb'
41
+ require 'cyberweb/modules/css_style.rb'
42
+
39
43
  begin
40
44
  require 'rack'
41
45
  rescue LoadError; end
@@ -109,20 +113,6 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
109
113
  # ======================================================================= #
110
114
  @internal_hash = {}
111
115
  # ======================================================================= #
112
- # === :title
113
- # ======================================================================= #
114
- @internal_hash[:title] = nil
115
- # ======================================================================= #
116
- # === :body
117
- #
118
- # This variable will contain the body of the new HTML page.
119
- # ======================================================================= #
120
- @internal_hash[:body] = nil
121
- # ======================================================================= #
122
- # === :special_actions
123
- # ======================================================================= #
124
- @internal_hash[:special_actions] = nil
125
- # ======================================================================= #
126
116
  # === :body_css_style
127
117
  # ======================================================================= #
128
118
  @internal_hash[:body_css_style] = nil
@@ -139,13 +129,48 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
139
129
  # ======================================================================= #
140
130
  @internal_hash[:css_style] = nil
141
131
  # ======================================================================= #
132
+ # === :title
133
+ # ======================================================================= #
134
+ @internal_hash[:title] = nil
135
+ # ======================================================================= #
136
+ # === :body
137
+ #
138
+ # This variable will contain the body of the new HTML page.
139
+ # ======================================================================= #
140
+ @internal_hash[:body] = nil
141
+ # ======================================================================= #
142
+ # === :special_actions
143
+ # ======================================================================= #
144
+ @internal_hash[:special_actions] = nil
145
+ # ======================================================================= #
142
146
  # === :javascript_code
143
147
  # ======================================================================= #
144
148
  @internal_hash[:javascript_code] = nil
145
149
  # ======================================================================= #
150
+ # === :favicon
151
+ #
152
+ # By default we will not use a favicon.
153
+ # ======================================================================= #
154
+ @internal_hash[:favicon] = nil
155
+ # ======================================================================= #
146
156
  # === :use_jquery
147
157
  # ======================================================================= #
148
- @internal_hash[:use_jquery] = false
158
+ pull_in_the_jquery_module
159
+ @internal_hash[:use_jquery] = false # But we have to disable it.
160
+ end
161
+
162
+ # ========================================================================= #
163
+ # === css_classes?
164
+ # ========================================================================= #
165
+ def css_classes?
166
+ @internal_hash[:css_classes]
167
+ end
168
+
169
+ # ========================================================================= #
170
+ # === pull_in_the_jquery_module
171
+ # ========================================================================= #
172
+ def pull_in_the_jquery_module
173
+ extend(Cyberweb::JqueryModule)
149
174
  end
150
175
 
151
176
  # ========================================================================= #
@@ -162,13 +187,6 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
162
187
  @internal_hash[:title]
163
188
  end
164
189
 
165
- # ========================================================================= #
166
- # === use_jquery?
167
- # ========================================================================= #
168
- def use_jquery?
169
- @internal_hash[:use_jquery]
170
- end
171
-
172
190
  # ========================================================================= #
173
191
  # === html_title?
174
192
  # ========================================================================= #
@@ -185,72 +203,6 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
185
203
  @internal_hash[:body]
186
204
  end
187
205
 
188
- # ========================================================================= #
189
- # === css_classes?
190
- # ========================================================================= #
191
- def css_classes?
192
- @internal_hash[:css_classes]
193
- end
194
-
195
- # ========================================================================= #
196
- # === return_the_css_classes
197
- #
198
- # This method will identify the correct CSS class. In order for this
199
- # to work, the class must have been defined in one of the default
200
- # .css files. And these files have to be found by ruby as well -
201
- # otherwise the method will not work properly.
202
- # ========================================================================= #
203
- def return_the_css_classes
204
- css_classes = css_classes?
205
- if css_classes
206
- css_classes = [css_classes].flatten.map {|entry|
207
- if entry.include? ' '
208
- entry = entry.split(' ')
209
- end
210
- entry
211
- }.flatten
212
- _ = ''.dup
213
- css_content = ''.dup
214
- # ===================================================================== #
215
- # Obtain the various .css files next and store them in `css_content`:
216
- # ===================================================================== #
217
- Dir[project_base_dir?+'cascading_style_sheets/*.css'].each {|entry|
218
- css_content << File.read(entry)+N
219
- }
220
- css_classes.each {|this_css_class|
221
- # =================================================================== #
222
- # See: https://rubular.com/r/7LUM1vaN45GDQ6
223
- # =================================================================== #
224
- use_this_regex =
225
- /(\.#{this_css_class}).+{(.+)}$/
226
- css_content =~ use_this_regex
227
- # ================================================================= #
228
- # else, since as of December 2021, try to read in from a .css
229
- # file if this one exists.
230
- # ================================================================= #
231
- assumed_path = ::Cyberweb.project_base_directory?+
232
- 'cascading_style_sheets/'+
233
- this_css_class+'.css'
234
- if File.exist?(assumed_path)
235
- _ << File.read(assumed_path)
236
- else
237
- if $2
238
- _ << $1.to_s.ljust(15)+' { '+$2.to_s.lstrip.squeeze(' ')+' }'+N
239
- end
240
- end
241
- }
242
- if _.to_s.empty?
243
- return ''
244
- else
245
- return '<style>'+N+
246
- _.to_s+N+
247
- '</style>'+N
248
- end
249
- else
250
- ''
251
- end
252
- end
253
-
254
206
  # ========================================================================= #
255
207
  # === main_string?
256
208
  # ========================================================================= #
@@ -260,6 +212,13 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
260
212
  alias string? main_string? # === string?
261
213
  # alias to_str main_string? # === to_str # This would imply "behaves like string".
262
214
 
215
+ # ========================================================================= #
216
+ # === clear_the_main_string
217
+ # ========================================================================= #
218
+ def clear_the_main_string
219
+ @internal_hash[:main_string].clear
220
+ end
221
+
263
222
  # ========================================================================= #
264
223
  # === return_assumed_javascript
265
224
  # ========================================================================= #
@@ -274,18 +233,6 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
274
233
  return _
275
234
  end
276
235
 
277
- # ========================================================================= #
278
- # === return_css_style
279
- # ========================================================================= #
280
- def return_css_style
281
- _ = @internal_hash[:css_style]
282
- if _ and !_.empty?
283
- return "<style>\n#{_}\n</style>"
284
- else
285
- ''
286
- end
287
- end
288
-
289
236
  # ========================================================================= #
290
237
  # === parse_this_hash (parse tag)
291
238
  #
@@ -314,6 +261,15 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
314
261
  @internal_hash[:css_style] = hash.delete(:style)
315
262
  end
316
263
  # ======================================================================= #
264
+ # === :favicon
265
+ #
266
+ # This entry point exists to support favicons for the
267
+ # HtmlTemplate.
268
+ # ======================================================================= #
269
+ if hash.has_key? :favicon
270
+ @internal_hash[:favicon] = hash.delete(:favicon)
271
+ end
272
+ # ======================================================================= #
317
273
  # === :title
318
274
  # ======================================================================= #
319
275
  if hash.has_key? :title
@@ -454,16 +410,20 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
454
410
  # ===================================================================== #
455
411
  # Begin to build the HTML result next.
456
412
  # ===================================================================== #
457
- @internal_hash[:main_string] =
458
- '<!DOCTYPE html>'+N+
459
- '<html lang="en">'+N+
460
- '<head>'+N+
461
- Cyberweb.return_utf_charset+
462
- html_title?+N+
463
- return_the_css_classes+N+
464
- return_css_style+N+
465
- return_assumed_javascript+
466
- '</head>'+N.dup # The <head> tag is now closed.
413
+ _ = ''.dup
414
+ _ << '<!DOCTYPE html>'+N+
415
+ '<html lang="en">'+N+
416
+ '<head>'+N+
417
+ Cyberweb.return_utf_charset+
418
+ html_title?+N+
419
+ return_the_css_classes+N+
420
+ return_css_style+N+
421
+ return_assumed_javascript
422
+ if use_favicon?
423
+ _ << '<link rel="icon" type="image/png" href="'+use_favicon?.to_s+'"/>'+"\n"
424
+ end
425
+ _ << '</head>'+N.dup # The <head> tag is now closed.
426
+ @internal_hash[:main_string] = _
467
427
  if use_jquery?
468
428
  require 'cyberweb/toplevel_methods/jquery.rb'
469
429
  # =================================================================== #
@@ -473,11 +433,102 @@ class HtmlTemplate < ::Cyberweb::Base # === Cyberweb::HtmlTemplate
473
433
  "<!-- Adding support for jquery next: -->\n"+
474
434
  Cyberweb.return_jquery_string
475
435
  end
436
+ # ===================================================================== #
437
+ # Append onto the main String:
438
+ # ===================================================================== #
476
439
  @internal_hash[:main_string] << body_string+
477
- @internal_hash[:body].to_s+N+ # Add the body-content.
478
- '</body>'+N+
479
- '</html>'+N
440
+ @internal_hash[:body].to_s+N+ # Add the body-content.
441
+ '</body>'+N+
442
+ '</html>'+N
480
443
  end
444
+ end; alias rebuild_the_main_string generate_the_main_string # === rebuild_the_main_string
445
+
446
+ # ========================================================================= #
447
+ # === return_the_css_classes
448
+ #
449
+ # This method will identify the correct CSS class that should be used
450
+ # by the HtmlTemplate.
451
+ #
452
+ # In order for this to work, the class must have been defined in one
453
+ # of the default .css files. And these files have to be found by
454
+ # ruby as well - otherwise the method will not work properly.
455
+ # ========================================================================= #
456
+ def return_the_css_classes
457
+ css_classes = css_classes?
458
+ if css_classes
459
+ css_classes = [css_classes].flatten.map {|entry|
460
+ if entry.include? ' '
461
+ entry = entry.split(' ')
462
+ end
463
+ entry
464
+ }.flatten
465
+ _ = ''.dup
466
+ css_content = ''.dup
467
+ # ===================================================================== #
468
+ # Obtain the various .css files next and store them in `css_content`:
469
+ # ===================================================================== #
470
+ Dir["#{project_base_dir?}cascading_style_sheets/*.css"].each {|entry|
471
+ css_content << File.read(entry)+N
472
+ }
473
+ css_classes.each {|this_css_class|
474
+ # =================================================================== #
475
+ # See: https://rubular.com/r/7LUM1vaN45GDQ6
476
+ # =================================================================== #
477
+ use_this_regex =
478
+ /(\.#{this_css_class}).+{(.+)}$/
479
+ css_content =~ use_this_regex
480
+ # ================================================================= #
481
+ # else, since as of December 2021, try to read in from a .css
482
+ # file if this one exists.
483
+ # ================================================================= #
484
+ assumed_path = ::Cyberweb.project_base_directory?+
485
+ 'cascading_style_sheets/'+
486
+ this_css_class+'.css'
487
+ if File.exist?(assumed_path)
488
+ _ << File.read(assumed_path)
489
+ else
490
+ if $2
491
+ _ << $1.to_s.ljust(15)+' { '+$2.to_s.lstrip.squeeze(' ')+' }'+N
492
+ end
493
+ end
494
+ }
495
+ if _.to_s.empty?
496
+ return ''
497
+ else
498
+ return '<style>'+N+
499
+ _.to_s+N+
500
+ '</style>'+N
501
+ end
502
+ else
503
+ ''
504
+ end
505
+ end
506
+
507
+ # ========================================================================= #
508
+ # === set_favicon
509
+ # ========================================================================= #
510
+ def set_favicon(i)
511
+ i = Cyberweb::Favicon.path_of?(i)
512
+ @internal_hash[:favicon] = i
513
+ end; alias favicon= set_favicon # === favicon=
514
+
515
+ # ========================================================================= #
516
+ # === return_css_style
517
+ # ========================================================================= #
518
+ def return_css_style
519
+ _ = @internal_hash[:css_style]
520
+ if _ and !_.empty?
521
+ return Cyberweb::CssStyle.style(_)
522
+ else
523
+ ''
524
+ end
525
+ end
526
+
527
+ # ========================================================================= #
528
+ # === use_favicon?
529
+ # ========================================================================= #
530
+ def use_favicon?
531
+ @internal_hash[:favicon]
481
532
  end
482
533
 
483
534
  # ========================================================================= #
@@ -511,5 +562,12 @@ end
511
562
  end
512
563
 
513
564
  if __FILE__ == $PROGRAM_NAME
514
- puts Cyberweb::HtmlTemplate.new(ARGV)
565
+ alias e puts
566
+ html_template = Cyberweb::HtmlTemplate.new(ARGV)
567
+ html_template.clear_the_main_string
568
+ # html_template.set_favicon('https://example.com/favicon.png')
569
+ # html_template.set_favicon(:package)
570
+ html_template.set_favicon('https://i.imgur.com/GR8pcxq.png')
571
+ html_template.rebuild_the_main_string
572
+ e html_template
515
573
  end # htmltemplate abc def
@@ -200,37 +200,6 @@ module Cyberweb
200
200
  ee ::Cyberweb.return_javascript(i)
201
201
  end; self.instance_eval { alias output_this_javascript ejavascript } # === Cyberweb.output_this_javascript
202
202
 
203
- # ========================================================================= #
204
- # === Cyberweb.return_default_javascript
205
- #
206
- # This will return the javascript stuff. Since JUN 2011 we add the
207
- # fixed_path variable only if we do not start with http. Apparently
208
- # this breaks the javascript model... so I undid this in AUG 2011.
209
- #
210
- # If we redo it again, we must describe why!
211
- #
212
- # On 21 June 2014 I noticed that the W3C validator complained about
213
- # "script element between head and body". That means we need to
214
- # either place it between <head> or <body> tags, and not in between.
215
- # ========================================================================= #
216
- def self.return_default_javascript(
217
- use_this_path = ::Cyberweb.converted_path_to_data # We need the path to the DATA/ subdirectory.
218
- )
219
- array = ARRAY_DEFAULT_JAVASCRIPT_LIBRARIES
220
- _ = ''.dup # This String will be returned.
221
- array.each {|entry|
222
- _ << '<script src="'
223
- _ << use_this_path
224
- _ << 'javascript_code/'
225
- _ << entry
226
- _ << '" '
227
- _ = _.ljust(48)
228
- _ << 'type="text/javascript"></script>'
229
- _ << NL
230
- } unless ARRAY_DEFAULT_JAVASCRIPT_LIBRARIES.empty?
231
- _
232
- end
233
-
234
203
  # ========================================================================= #
235
204
  # === ejavascript
236
205
  #
@@ -253,4 +222,38 @@ module Cyberweb
253
222
  alias embed_this_javascript ejavascript # === embed_this_javascript_code
254
223
  alias javascript_code ejavascript # === javascript_code # experimental as of Nov 2014.
255
224
 
225
+ # ========================================================================= #
226
+ # === Cyberweb.return_default_javascript
227
+ #
228
+ # This will return the javascript stuff. Since as of June 2011 we add
229
+ # the fixed_path variable only if we do not start with http. Apparently
230
+ # this breaks the javascript model... so this was undone again in
231
+ # August 2011.
232
+ #
233
+ # If we redo it again, we must describe why.
234
+ #
235
+ # On 21.06.2014 I noticed that the W3C validator complained about
236
+ # "script element between head and body". That means we need to
237
+ # either place it between <head> or <body> tags, and not in between.
238
+ # ========================================================================= #
239
+ def self.return_default_javascript(
240
+ use_this_path =
241
+ # ::Cyberweb.converted_path_to_data # We need the path to the DATA/ subdirectory.
242
+ # ::Cyberweb.converted_path_to_project_base_dir
243
+ #Cyberweb.project_base_dir?
244
+ ::Cyberweb.converted_path_to_the_directory_containing_the_copied_javascript_files
245
+ )
246
+ use_this_path = use_this_path.dup
247
+ array = ARRAY_DEFAULT_JAVASCRIPT_LIBRARIES
248
+ _ = ''.dup # This String will be returned.
249
+ array.each {|entry|
250
+ full_path = "#{use_this_path}javascript_code/#{entry}".dup
251
+ _ << '<script src="'+full_path+'"'
252
+ _ = _.ljust(48)
253
+ _ << ' type="text/javascript"></script>'
254
+ _ << NL
255
+ } unless ARRAY_DEFAULT_JAVASCRIPT_LIBRARIES.empty?
256
+ _
257
+ end
258
+
256
259
  end
@@ -0,0 +1,12 @@
1
+ function copy_to_the_clipboard(id_to_use) {
2
+ // Get the text field
3
+ var x = document.getElementById(id_to_use);
4
+
5
+ x.select(); /* Select the text field */
6
+ /*
7
+ x.setSelectionRange(0, 99999); // For mobile devices
8
+ */
9
+
10
+ // Copy the text inside the text field
11
+ navigator.clipboard.writeText(x.value);
12
+ }
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Cyberweb::JqueryModule
6
+ #
7
+ # This module bundles jquery-related functionality together.
8
+ # =========================================================================== #
9
+ # require 'cyberweb/jquery_module/jquery_module.rb'
10
+ # include Cyberweb::JqueryModule
11
+ # =========================================================================== #
12
+ module Cyberweb
13
+
14
+ module JqueryModule # === Cyberweb::JqueryModule
15
+
16
+ # ========================================================================= #
17
+ # === Cyberweb::JqueryModule.extended
18
+ # ========================================================================= #
19
+ def self.extended(i)
20
+ i.enable_jquery if i.respond_to?(:enable_jquery) # Enable it automatically when extending.
21
+ # puts "#{i} was included."
22
+ end
23
+
24
+ # ========================================================================= #
25
+ # === enable_jquery
26
+ # ========================================================================= #
27
+ def disable_jquery
28
+ @internal_hash[:use_jquery] = false
29
+ end
30
+
31
+ # ========================================================================= #
32
+ # === enable_jquery
33
+ # ========================================================================= #
34
+ def enable_jquery
35
+ @internal_hash[:use_jquery] = true
36
+ end
37
+
38
+ # ========================================================================= #
39
+ # === use_jquery?
40
+ # ========================================================================= #
41
+ def use_jquery?
42
+ @internal_hash[:use_jquery]
43
+ end
44
+
45
+ end; end
46
+
47
+ if __FILE__ == $PROGRAM_NAME
48
+ object = Object.new
49
+ object.extend(Cyberweb::JqueryModule)
50
+ object.test
51
+ end # jquery_module.rb
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Cyberweb::CssStyle
6
+ # =========================================================================== #
7
+ # require 'cyberweb/modules/css_style.rb'
8
+ # Cyberweb::CssStyle.style
9
+ # include Cyberweb::CssStyle
10
+ # =========================================================================== #
11
+ module Cyberweb
12
+
13
+ module CssStyle # === Cyberweb::CssStyle
14
+
15
+ # ========================================================================= #
16
+ # === Cyberweb::CssStyle.style
17
+ #
18
+ # This method will return the <style> tag.
19
+ # ========================================================================= #
20
+ def self.style(i = '')
21
+ if i.is_a? Array
22
+ i = i.first
23
+ end
24
+ return "<style>\n#{i}\n</style>\n" # Trailing newline is mandatory.
25
+ end
26
+
27
+ end; end