cyberweb 0.6.17 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +299 -134
  3. data/bin/images_from_this_webpage +11 -0
  4. data/doc/README.gen +276 -107
  5. data/doc/todo/todo_for_the_cyberweb_project.md +90 -90
  6. data/examples/css/day_night_toggle/day_night_toggle.html +202 -0
  7. data/examples/css/fleeing_dinosaur_animation/fleeing_dinosaur_animation.html +420 -0
  8. data/examples/css/important_style/important_style.html +35 -0
  9. data/examples/html/custom_cursor.html +1 -1
  10. data/examples/javascript_and_jquery/misc/miscallenous_javascript_examples.html +25 -0
  11. data/examples/javascript_and_jquery/roll_a_die/roll_a_die.html +48 -0
  12. data/lib/cyberweb/base/misc.rb +7 -0
  13. data/lib/cyberweb/cascading_style_sheets/div.css +2 -2
  14. data/lib/cyberweb/cascading_style_sheets/drop_shadow.css +4 -0
  15. data/lib/cyberweb/cascading_style_sheets/fonts.css +42 -30
  16. data/lib/cyberweb/cascading_style_sheets/glow_effects.css +58 -0
  17. data/lib/cyberweb/cascading_style_sheets/margin.css +254 -248
  18. data/lib/cyberweb/cascading_style_sheets/tooltip.css +73 -0
  19. data/lib/cyberweb/generator/cgi.rb +2 -1
  20. data/lib/cyberweb/javascript_code/custom_functions.js +16 -16
  21. data/lib/cyberweb/javascript_code/math.js +18 -0
  22. data/lib/cyberweb/javascript_code/simulate_a_dice.js +13 -5
  23. data/lib/cyberweb/sinatra/custom_extensions.rb +2 -2
  24. data/lib/cyberweb/toplevel_methods/misc.rb +44 -0
  25. data/lib/cyberweb/utility_scripts/create_coloured_tags.rb +1 -5
  26. data/lib/cyberweb/utility_scripts/download_balloon_css.rb +1 -5
  27. data/lib/cyberweb/utility_scripts/fix_incorrect_links_to_locally_existing_images_in_this_file.rb +5 -33
  28. data/lib/cyberweb/utility_scripts/hyperlink_all_images_from.rb +1 -5
  29. data/lib/cyberweb/utility_scripts/obtain_css_rules.rb +169 -0
  30. data/lib/cyberweb/version/version.rb +2 -2
  31. data/lib/cyberweb/web_object/html_tags.rb +12 -1
  32. data/lib/cyberweb/web_object/images.rb +534 -178
  33. data/lib/cyberweb/web_object/javascript_and_jquery.rb +9 -9
  34. data/lib/cyberweb/web_object/link.rb +102 -67
  35. data/lib/cyberweb/web_object/misc.rb +320 -518
  36. data/lib/cyberweb/yaml/js_files_to_load.yml +3 -2
  37. data/lib/cyberweb/yaml/load_these_yaml_files_by_default.yml +1 -0
  38. data/test/complex_tests/testing_style_variants/show_coloured_boxes.cgi +2 -2
  39. data/test/javascript/testing_various_javascript_related_APIs.html +17 -0
  40. data/test/simple_tests/testing_dragging_an_image.cgi +2 -0
  41. data/test/simple_tests/testing_uniform_css_rules_for_all_images.cgi +25 -0
  42. metadata +15 -5
@@ -10,182 +10,11 @@ module Cyberweb
10
10
 
11
11
  class WebObject < ::Cyberweb::Base # === Cyberweb::WebObject
12
12
 
13
- # ========================================================================= #
14
- # === draggable_image
15
- #
16
- # Example code how to tap into this method:
17
- #
18
- # draggable_image 'STD/USB_CONNECTION_DEVICE.png',
19
- # 'mar1em bblack1 mars3em'
20
- #
21
- # It may be more convenient to use the alias name dimg().
22
- # ========================================================================= #
23
- def draggable_image(
24
- url = '',
25
- css_class = :empty_string_or_global_css_rules_for_images,
26
- the_id = '',
27
- css_style = '',
28
- alt_text = '',
29
- &block
30
- )
31
- if the_id and the_id.empty?
32
- the_id = (
33
- 'drag_'+
34
- File.basename(url.to_s).
35
- downcase.
36
- delete_suffix(
37
- File.extname(url.to_s)
38
- )
39
- ).tr('.','_')
40
- end
41
- if the_id and !the_id.empty? and !the_id.start_with?('drag_')
42
- the_id = the_id.dup
43
- the_id.prepend('drag_')
44
- end
45
- if uses_sinatra? # Handle sinatra first.
46
- draggable_img_base64(url, css_class, css_style)
47
- else
48
- img(url, css_class, the_id, css_style, alt_text) { :draggable_attribute }
49
- end
50
- end; alias draggable_img draggable_image # === draggable_img
51
- alias dimg draggable_image # === dimg
52
- alias dimage draggable_image # === dimage
53
-
54
- # ========================================================================= #
55
- # === return_path_to_the_images_directory
56
- # ========================================================================= #
57
- def return_path_to_the_images_directory(
58
- path_to_use = relative_path?
59
- )
60
- return "#{path_to_use}data/"\
61
- "#{return_name_of_the_images_directory}/"
62
- end
63
-
64
- # ========================================================================= #
65
- # === images_css
66
- #
67
- # This method allows the user to set the same CSS rules for all
68
- # images used on a given WebObject.
69
- # ========================================================================= #
70
- def images_css(i)
71
- @internal_hash[:global_CSS_rules_for_all_images] = i
72
- end
73
-
74
- # ========================================================================= #
75
- # === img_nbr
76
- #
77
- # The fourth argument, called css_style, used to default to
78
- # "border-width:1px", but in May 2021 it was realized that this
79
- # will conflict with e. g. a css class such as "bblack3". In
80
- # this case we would want to use a border width of 3px, but
81
- # this would be ignored due to the default. Thus, the default
82
- # was removed.
83
- #
84
- # In October 2022 the second argument to this method was changed to
85
- # a Symbol.
86
- # ========================================================================= #
87
- def img_nbr(
88
- url = 'RPG/YINYANG.png',
89
- css_class = :empty_string_or_global_css_rules_for_images,
90
- the_id = '',
91
- css_style = '' # Empty default since May 2021 - see above for an explanation.
92
- )
93
- img(
94
- url,
95
- css_class,
96
- the_id,
97
- css_style
98
- )
99
- br
100
- end; alias img_br img_nbr # === img_br
101
- alias imgbr img_nbr # === imgbr
102
-
103
- # ========================================================================= #
104
- # === img (img tag, image tag)
105
- #
106
- # Keep in mind that this method has to remain quite flexible. It has
107
- # to be able to work with input such as this:
108
- #
109
- # img(
110
- # this_image.sub(Regexp.quote('/home/x/data/images/'),''),
111
- # css_class: 'bblack3',
112
- # width: '528',
113
- # height: '340',
114
- # alt: File.basename(this_image.delete_suffix(File.extname(this_image)))
115
- # )
116
- #
117
- # ========================================================================= #
118
- def img(
119
- url = 'RPG/YINYANG.png',
120
- css_class = :empty_string_or_global_css_rules_for_images,
121
- the_id = '',
122
- css_style = '',
123
- alt_text = '',
124
- &block
125
- )
126
- # ======================================================================= #
127
- # First we should obtain the corresponding <img> tag. This will be
128
- # delegated towards sg() which is an abbreviated name for
129
- # string_image():
130
- # ======================================================================= #
131
- content = sg(
132
- url, css_class, the_id, css_style, alt_text
133
- )
134
- # ======================================================================= #
135
- # === Handle blocks given to this method next
136
- # ======================================================================= #
137
- if block_given?
138
- yielded = yield
139
- # ===================================================================== #
140
- # === Handle Hashes next
141
- # ===================================================================== #
142
- if yielded.is_a? Hash
143
- # =================================================================== #
144
- # === :draggable_attribute
145
- # =================================================================== #
146
- if yielded.has_key? :draggable_attribute
147
- content = content.dup
148
- content[-1,0] = ' draggable="true"'
149
- end
150
- # =================================================================== #
151
- # === :usemap
152
- # =================================================================== #
153
- if yielded.has_key? :usemap
154
- content = content.dup
155
- content[-1,0] = ' usemap="'+yielded[:usemap].to_s+'"'
156
- end
157
- # ===================================================================== #
158
- # === Handle Symbols next
159
- # ===================================================================== #
160
- elsif yielded.is_a? Symbol
161
- case yielded # case tag
162
- # =================================================================== #
163
- # === :draggable_attribute
164
- # =================================================================== #
165
- when :draggable_attribute,
166
- :drag
167
- content = content.dup
168
- content[-1,0] = ' draggable="true"'
169
- end
170
- end
171
- end
172
- addnl(
173
- content
174
- )
175
- end; alias ig img # === ig
176
-
177
- # ========================================================================= #
178
- # === images_css_rules?
179
- # ========================================================================= #
180
- def images_css_rules?
181
- @internal_hash[:global_CSS_rules_for_all_images]
182
- end
183
-
184
13
  # ========================================================================= #
185
14
  # === simpler_string_image (sg tag)
186
15
  #
187
- # This method has been added in September 2020 to specifically
188
- # work around the problem that the older sg() has.
16
+ # This method has been added in September 2020 to specifically work
17
+ # around the problem that the older sg() has.
189
18
  #
190
19
  # The return-value of this method MUST always be a String; it may never
191
20
  # use addnl() directly. The whole idea is to build up a <img> tag
@@ -197,22 +26,28 @@ class WebObject < ::Cyberweb::Base # === Cyberweb::WebObject
197
26
  optional_the_id = '',
198
27
  optional_css_style = '',
199
28
  alt_text = '',
200
- make_linebreak = 0,
29
+ make_linebreak = 0,
201
30
  something1 = '',
202
31
  something2 = '',
203
32
  hmmmmmmmmm = '',
204
33
  javascript = '',
205
34
  &block
206
35
  )
36
+ if optional_css_class and optional_css_class.is_a?(String) and
37
+ images_css_rules? and !images_css_rules?.empty?
38
+ optional_css_class += " #{images_css_rules?}"
39
+ end
207
40
  case optional_css_class
208
41
  # ======================================================================= #
209
42
  # === :empty_string_or_global_css_rules_for_images
43
+ #
44
+ # Make use of the global image CSS rules here.
210
45
  # ======================================================================= #
211
46
  when :empty_string_or_global_css_rules_for_images
212
- if @internal_hash[:global_CSS_rules_for_all_images].nil?
47
+ if images_css_rules?.nil?
213
48
  optional_css_class = ''
214
49
  else
215
- optional_css_class = @internal_hash[:global_CSS_rules_for_all_images]
50
+ optional_css_class = images_css_rules?
216
51
  end
217
52
  end
218
53
  yielded = nil # Dummy variable for later re-use.
@@ -299,6 +134,8 @@ class WebObject < ::Cyberweb::Base # === Cyberweb::WebObject
299
134
  case optional_the_id
300
135
  # ======================================================================= #
301
136
  # === :drag
137
+ #
138
+ # "Rescue" a specific symbol here, called :drag.
302
139
  # ======================================================================= #
303
140
  when :drag
304
141
  optional_the_id = 'drag_'+File.basename(i).downcase.delete_suffix(
@@ -354,10 +191,22 @@ class WebObject < ::Cyberweb::Base # === Cyberweb::WebObject
354
191
  may_we_prepend_the_path = false
355
192
  end
356
193
  end
357
- if may_we_prepend_the_path
194
+ # ======================================================================= #
195
+ # Next we prepend the path to the local directory. This is, however
196
+ # had, NOT the case if i begins with the substring 'http'.
197
+ # ======================================================================= #
198
+ if may_we_prepend_the_path and !i.start_with?('http')
358
199
  i = return_path_to_the_images_directory+
359
200
  i
360
201
  end
202
+ # ======================================================================= #
203
+ # Last but not least, we need to ensure that the ID is unique. If
204
+ # not then we will append some characters here.
205
+ # ======================================================================= #
206
+ if optional_the_id and !optional_the_id.empty? and is_a_duplicate_id?(optional_the_id)
207
+ optional_the_id = optional_the_id.dup if optional_the_id.frozen?
208
+ optional_the_id << '_'+random_alphabet_characters(10)
209
+ end
361
210
  return raw_image(
362
211
  i,
363
212
  optional_css_class,
@@ -371,6 +220,178 @@ class WebObject < ::Cyberweb::Base # === Cyberweb::WebObject
371
220
  alias simg simpler_string_image # === simg
372
221
  alias sg simpler_string_image # === sg
373
222
 
223
+ # ========================================================================= #
224
+ # === images_css
225
+ #
226
+ # This method allows the user to set the same CSS rules for all
227
+ # images used on a given WebObject.
228
+ # ========================================================================= #
229
+ def images_css(i)
230
+ @internal_hash[:global_CSS_rules_for_all_images] = i
231
+ end
232
+
233
+ # ========================================================================= #
234
+ # === images_css_rules?
235
+ # ========================================================================= #
236
+ def images_css_rules?
237
+ @internal_hash[:global_CSS_rules_for_all_images]
238
+ end
239
+
240
+ # ========================================================================= #
241
+ # === image (img tag, image tag)
242
+ #
243
+ # This method can be used to integrate ("embed") an image into the
244
+ # local web-page at hand. This image can either be a local image,
245
+ # or a remote one.
246
+ #
247
+ # The corresponding HTML code that governs this is the <img> tag.
248
+ # The first argument, called `url`, will become src="".
249
+ #
250
+ # It should be kept in mind that this method has to remain quite flexible.
251
+ #
252
+ # It has to be able to work with input such as this:
253
+ #
254
+ # img(
255
+ # this_image.sub(Regexp.quote('/home/x/data/images/'),''),
256
+ # css_class: 'bblack3',
257
+ # width: '528',
258
+ # height: '340',
259
+ # alt: File.basename(this_image.delete_suffix(File.extname(this_image)))
260
+ # )
261
+ #
262
+ # ========================================================================= #
263
+ def image(
264
+ url = 'RPG/YINYANG.png',
265
+ css_class = :empty_string_or_global_css_rules_for_images,
266
+ the_id = '',
267
+ css_style = '',
268
+ alt_text = '',
269
+ &block
270
+ )
271
+ # ======================================================================= #
272
+ # === Delegate towards simpler_string_image()
273
+ #
274
+ # First we should obtain the corresponding <img> tag. This will be
275
+ # delegated towards sg() which is an abbreviated name for
276
+ # string_image():
277
+ # ======================================================================= #
278
+ content = sg(
279
+ url, css_class, the_id, css_style, alt_text
280
+ )
281
+ # ======================================================================= #
282
+ # === Handle blocks given to this method next
283
+ # ======================================================================= #
284
+ if block_given?
285
+ yielded = yield
286
+ # ===================================================================== #
287
+ # === Handle Hashes next
288
+ # ===================================================================== #
289
+ if yielded.is_a? Hash
290
+ # =================================================================== #
291
+ # === :draggable_attribute
292
+ # =================================================================== #
293
+ if yielded.has_key? :draggable_attribute
294
+ content = content.dup
295
+ content[-1,0] = ' draggable="true"'
296
+ end
297
+ # =================================================================== #
298
+ # === :usemap
299
+ # =================================================================== #
300
+ if yielded.has_key? :usemap
301
+ content = content.dup
302
+ content[-1,0] = ' usemap="'+yielded[:usemap].to_s+'"'
303
+ end
304
+ # ===================================================================== #
305
+ # === Handle Symbols next
306
+ # ===================================================================== #
307
+ elsif yielded.is_a? Symbol
308
+ case yielded # case tag
309
+ # =================================================================== #
310
+ # === :draggable_attribute
311
+ # =================================================================== #
312
+ when :draggable_attribute,
313
+ :drag
314
+ content = content.dup
315
+ content[-1,0] = ' draggable="true"'
316
+ end
317
+ end
318
+ end
319
+ addnl(
320
+ content
321
+ )
322
+ end; alias img image # === img
323
+ alias ig image # === ig
324
+
325
+ # ========================================================================= #
326
+ # === draggable_image
327
+ #
328
+ # Example code how to tap into this method:
329
+ #
330
+ # draggable_image 'STD/USB_CONNECTION_DEVICE.png',
331
+ # 'mar1em bblack1 mars3em'
332
+ #
333
+ # It may be more convenient to use the alias name dimg().
334
+ # ========================================================================= #
335
+ def draggable_image(
336
+ url = '',
337
+ css_class = :empty_string_or_global_css_rules_for_images,
338
+ the_id = '',
339
+ css_style = '',
340
+ alt_text = '',
341
+ &block
342
+ )
343
+ if the_id and the_id.empty?
344
+ the_id = (
345
+ 'drag_'+
346
+ File.basename(url.to_s).
347
+ downcase.
348
+ delete_suffix(
349
+ File.extname(url.to_s)
350
+ )
351
+ ).tr('.','_')
352
+ end
353
+ if the_id and !the_id.empty? and !the_id.start_with?('drag_')
354
+ the_id = the_id.dup
355
+ the_id.prepend('drag_')
356
+ end
357
+ if uses_sinatra? # Handle sinatra first.
358
+ draggable_img_base64(url, css_class, css_style)
359
+ else # delegate towards img() next.
360
+ img(url, css_class, the_id, css_style, alt_text) { :draggable_attribute }
361
+ end
362
+ end; alias draggable_img draggable_image # === draggable_img
363
+ alias dimg draggable_image # === dimg
364
+ alias dimage draggable_image # === dimage
365
+
366
+ # ========================================================================= #
367
+ # === img_nbr
368
+ #
369
+ # The fourth argument, called css_style, used to default to
370
+ # "border-width:1px", but in May 2021 it was realized that this
371
+ # will conflict with e. g. a css class such as "bblack3". In
372
+ # this case we would want to use a border width of 3px, but
373
+ # this would be ignored due to the default. Thus, the default
374
+ # was removed.
375
+ #
376
+ # In October 2022 the second argument to this method was changed to
377
+ # a Symbol.
378
+ # ========================================================================= #
379
+ def img_nbr(
380
+ url = 'RPG/YINYANG.png',
381
+ css_class = :empty_string_or_global_css_rules_for_images,
382
+ the_id = '',
383
+ css_style = '' # Empty default since May 2021 - see above for an explanation.
384
+ )
385
+ img(
386
+ url,
387
+ css_class,
388
+ the_id,
389
+ css_style
390
+ )
391
+ br # And then the separate call towards br().
392
+ end; alias img_br img_nbr # === img_br
393
+ alias imgbr img_nbr # === imgbr
394
+
374
395
  # ========================================================================= #
375
396
  # === remote_img
376
397
  #
@@ -429,7 +450,11 @@ class WebObject < ::Cyberweb::Base # === Cyberweb::WebObject
429
450
  # === raw_image
430
451
  #
431
452
  # The first argument to this method should be the path to the file at
432
- # hand.
453
+ # hand. This can also be a remote image.
454
+ #
455
+ # Note that this method deliberately does NOT check whether the ID is
456
+ # unique or not. You have to solve this prior to calling this method
457
+ # if you wish to avoid duplicate IDs.
433
458
  # ========================================================================= #
434
459
  def raw_image(
435
460
  i = '',
@@ -720,4 +745,335 @@ class WebObject < ::Cyberweb::Base # === Cyberweb::WebObject
720
745
  )
721
746
  end
722
747
 
748
+ # ========================================================================= #
749
+ # === return_path_to_the_images_directory
750
+ # ========================================================================= #
751
+ def return_path_to_the_images_directory(
752
+ path_to_use = relative_path?
753
+ )
754
+ return "#{path_to_use}data/"\
755
+ "#{return_name_of_the_images_directory}/"
756
+ end
757
+
758
+ # ========================================================================= #
759
+ # === img_dir?
760
+ #
761
+ # This method refers to a local directory where images are kept.
762
+ #
763
+ # This is hardcoded for my home system, so it is fairly useless for other
764
+ # people.
765
+ # ========================================================================= #
766
+ def img_dir?
767
+ "#{server_base_directory?}"\
768
+ "data/"\
769
+ "#{return_name_of_the_images_directory}/"
770
+ end
771
+
772
+ # ========================================================================= #
773
+ # === return_this_base64_image
774
+ # ========================================================================= #
775
+ def return_this_base64_image(
776
+ i,
777
+ optional_css_class = '',
778
+ optional_css_id = ''
779
+ )
780
+ return ::Cyberweb.return_this_base64_image(
781
+ i,
782
+ optional_css_class,
783
+ optional_css_id
784
+ )
785
+ end
786
+
787
+ # ========================================================================= #
788
+ # === display_all_images
789
+ #
790
+ # Use this when you just want to display all images.
791
+ #
792
+ # The first argument should be the location towards the
793
+ # directory that holds all images.
794
+ # ========================================================================= #
795
+ def display_all_images(
796
+ dir = ::Cyberweb.return_pwd,
797
+ optional_css = 'bblack1'
798
+ )
799
+ if dir.is_a? Hash
800
+ dir = dir.delete(:from) if dir.has_key? :from
801
+ end
802
+ if dir.include? '$'
803
+ dir = ConvertGlobalEnv[dir]
804
+ end
805
+ unless Dir.exist? dir
806
+ e 'It seems as if the directory at `'+dir+'` does not exist.'
807
+ end
808
+ all_the_images = get_images_from(dir)
809
+ all_the_images.each {|file|
810
+ file = rds(file)
811
+ h3 file, 'slateblue'
812
+ imgbr(
813
+ file,
814
+ optional_css
815
+ )
816
+ }
817
+ end; alias display_images_from display_all_images # === display_images_from
818
+ alias display_images display_all_images # === display_images
819
+
820
+ # ========================================================================= #
821
+ # === do_use_in_dir_images
822
+ # ========================================================================= #
823
+ def do_use_in_dir_images
824
+ @config['use_in_dir_images'] = true
825
+ # ======================================================================= #
826
+ # Also keep track of the new path.
827
+ # ======================================================================= #
828
+ ::Cyberweb.set_path_to_images('')
829
+ end; alias use_in_dir_images do_use_in_dir_images # === use_in_dir_images
830
+
831
+ # ========================================================================= #
832
+ # === base64_image
833
+ #
834
+ # This is distinct to other base64-related images within the Cyberweb
835
+ # project. It will simply, and directly, add the given data.
836
+ # ========================================================================= #
837
+ def base64_image(
838
+ i, image_type_to_use = :infer
839
+ )
840
+ addnl(
841
+ return_base64_image(i, image_type_to_use)
842
+ )
843
+ end
844
+
845
+ # ========================================================================= #
846
+ # === return_base64_image
847
+ # ========================================================================= #
848
+ def return_base64_image(
849
+ i,
850
+ image_type_to_use = :infer,
851
+ optional_css_class = '',
852
+ optional_the_id = '',
853
+ optional_css_style = ''
854
+ )
855
+ case image_type_to_use
856
+ # ======================================================================= #
857
+ # === :infer
858
+ # ======================================================================= #
859
+ when :infer
860
+ image_type_to_use = File.extname(i)
861
+ if image_type_to_use.empty?
862
+ image_type_to_use = 'png' # Rescue in this case.
863
+ end
864
+ end
865
+ _ = '<img src="data:image/'+
866
+ image_type_to_use.to_s.delete('.')+
867
+ ';base64,'+i+'"'.dup
868
+ if optional_css_class
869
+ _ << css_class_or_no_class(optional_css_class)
870
+ end
871
+ if optional_the_id
872
+ _ << id_or_no_id(optional_the_id)
873
+ end
874
+ if optional_css_style
875
+ _ << css_style_or_no_style(optional_css_style)
876
+ end
877
+ _ << '>'
878
+ return _
879
+ end
880
+
881
+ # ========================================================================= #
882
+ # === local_image_or_remote_image
883
+ #
884
+ # This method can be used to add a substitute image in the event that
885
+ # a local image could not be found. Otherwise it behaves exactly like
886
+ # image() does.
887
+ # ========================================================================= #
888
+ def local_image_or_remote_image(
889
+ local_image = '',
890
+ remote_image_substitute = '', # This one should be the remote URL.
891
+ optional_css_class = '',
892
+ optional_the_id = '',
893
+ optional_css_style = '',
894
+ alt_text = '',
895
+ &block
896
+ )
897
+ # ======================================================================= #
898
+ # We first have to decide whether the image exists or whether it does
899
+ # not exist, at the specified location. If it exists then we can use
900
+ # the regular img() call; otherwise we have to use the second argument
901
+ # to this method.
902
+ # ======================================================================= #
903
+ assumed_path = rds(
904
+ path_to_the_image_directory?+
905
+ local_image
906
+ )
907
+ if File.exist?(assumed_path) and !local_image.empty?
908
+ img(
909
+ local_image,
910
+ optional_css_class,
911
+ optional_the_id,
912
+ optional_css_style,
913
+ alt_text,
914
+ &block
915
+ )
916
+ else
917
+ # ===================================================================== #
918
+ # else we use a remote URL or a rescue URL anyway.
919
+ # ===================================================================== #
920
+ remote_img(
921
+ remote_image_substitute,
922
+ {
923
+ css_class: optional_css_class,
924
+ id: optional_the_id,
925
+ css_style: optional_css_style
926
+ },
927
+ &block
928
+ # alt_text is currently not handled here.
929
+ )
930
+ end
931
+ end
932
+
933
+ # ========================================================================= #
934
+ # === embed_this_image
935
+ # ========================================================================= #
936
+ def embed_this_image(
937
+ i = 'lyxandras-das-Dorf-Nadorp.jpg',
938
+ optional_css_class = 'bblack1',
939
+ optional_the_id = ''
940
+ )
941
+ addnl(
942
+ ::Cyberweb.embed_this_image(i, optional_css_class, optional_the_id)
943
+ )
944
+ end
945
+
946
+ # ========================================================================= #
947
+ # === relative_background_image
948
+ #
949
+ # We have to build the proper path, e. g.:
950
+ #
951
+ # url(data/images/WALLPAPERS/TheCalling_AnimeWallpaper.jpg);
952
+ #
953
+ # ========================================================================= #
954
+ def relative_background_image(this_image)
955
+ _ = ('../' * n_steps_to_the_base_directory?) +
956
+ "#{name_of_img_dir?}".dup
957
+ _ << this_image
958
+ background_image = "background-image: url(#{_});" # The string to append.
959
+ # ======================================================================= #
960
+ # Next, add some default assumptions here. No repeat is ok to
961
+ # use, centered background position - not sure.
962
+ # background-position: center;
963
+ # ======================================================================= #
964
+ add_this_css_style(
965
+ 'body {
966
+ '+background_image+'
967
+ background-repeat: no-repeat;
968
+ }'
969
+ )
970
+ end
971
+
972
+ # ========================================================================= #
973
+ # === background_image=
974
+ #
975
+ # Use this method to set the background image for a page.
976
+ #
977
+ # body {background-image: url("../IMG/");}'
978
+ #
979
+ # Since as of December 2011, if you pass an argument such as 'NJOY/#RAND'
980
+ # then we use this as instruction to fetch a random entry from this
981
+ # directory.
982
+ #
983
+ # Usage Example:
984
+ #
985
+ # w.background_image = 'NJOY/#RAND'
986
+ #
987
+ # ========================================================================= #
988
+ def background_image=(
989
+ i = '/blaaa/foo.png'
990
+ )
991
+ _ = "#{name_of_img_dir?}/".dup # Hardcoded for now. Yes, I am aware that this sucks.
992
+ if i.to_s.downcase.include? '#rand' # Then get path given. Example: w.background_image = 'NJOY/#RAND'
993
+ first_part = i.split('#').first
994
+ _ << first_part
995
+ _ << get_files_from(::Cyberweb.path_to_images?).sample.to_s
996
+ else
997
+ case i
998
+ when :random
999
+ _ << Dir[::Cyberweb.path_to_images?+'NJOY/*'].sample.
1000
+ sub(/\/home\/x\/DATA\/IMG\//, '')
1001
+ else
1002
+ _ << i
1003
+ end
1004
+ end
1005
+ background_img = "background-image: url(#{::Cyberweb.path_to_images?}#{_});" # The string to append.
1006
+ # ======================================================================= #
1007
+ # Next, add some default assumptions here. No repeat is ok to
1008
+ # use, centered background position - not sure.
1009
+ # background-position: center;
1010
+ # ======================================================================= #
1011
+ add_this_css_style(
1012
+ 'body {
1013
+ '+background_img+'
1014
+ background-repeat: no-repeat;
1015
+ }'
1016
+ )
1017
+ end; alias body_background_image background_image= # === body_background_image
1018
+ alias background_image background_image= # === background_image
1019
+
1020
+ # ========================================================================= #
1021
+ # === return_the_registered_base64_images
1022
+ # ========================================================================= #
1023
+ def return_the_registered_base64_images
1024
+ ::Cyberweb.base64_images
1025
+ end
1026
+
1027
+ # ========================================================================= #
1028
+ # === disable_webimages
1029
+ #
1030
+ # We wont use the webimages if we use this method here.
1031
+ # ========================================================================= #
1032
+ def disable_webimages
1033
+ ::Cyberweb.config?['use_webimages'] = false
1034
+ end
1035
+
1036
+ # ========================================================================= #
1037
+ # === get_images
1038
+ #
1039
+ # This method will obtain all files from all subdirectories there as
1040
+ # well.
1041
+ # ========================================================================= #
1042
+ def get_images(
1043
+ from_this_dir = return_pwd
1044
+ )
1045
+ Dir["#{from_this_dir}/**/**"].select {|entry|
1046
+ ::Cyberweb.is_an_image?(entry)
1047
+ }
1048
+ end; alias get_images_from get_images # === get_images_from
1049
+ alias return_all_images_from get_images # === return_all_images_from
1050
+
1051
+ # ========================================================================= #
1052
+ # === done_image
1053
+ # ========================================================================= #
1054
+ def done_image
1055
+ sg(:done, 'marr10px')
1056
+ end
1057
+
1058
+ # ========================================================================= #
1059
+ # === draggable_string_image
1060
+ # ========================================================================= #
1061
+ def draggable_string_image(
1062
+ url = '',
1063
+ css_class = '',
1064
+ the_id = '',
1065
+ css_style = '',
1066
+ alt_text = '',
1067
+ &block
1068
+ )
1069
+ if the_id and the_id.empty?
1070
+ the_id = 'drag_'+File.basename(url).downcase.delete_suffix(File.extname(url))
1071
+ end
1072
+ if the_id and !the_id.empty? and !the_id.start_with?('drag_')
1073
+ the_id = the_id.dup
1074
+ the_id.prepend('drag_')
1075
+ end
1076
+ string_img(url, css_class, the_id, css_style, alt_text) { :draggable_attribute }
1077
+ end
1078
+
723
1079
  end; end