cyberweb 0.6.17 → 0.7.9

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 (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
data/doc/README.gen CHANGED
@@ -416,11 +416,18 @@ Note that **Cyberweb.set_path()** is a shorter alias to this method;
416
416
  may be useful in IRB. Otherwise I recommend to use the longer
417
417
  method name instead, as it is more explicit.
418
418
 
419
+ For many users this API may be fairly irrelevant or even cumbersome.
420
+ In that case you should consider uploading some of your images to a
421
+ remote server and then simply link towards these images rather
422
+ than having to deal with paths to local images being a nuisance. I do
423
+ that with some of my files, e. g. referring to a FTP site. In the
424
+ long run, though, this situation will eventually improve.
425
+
419
426
  ## Images
420
427
 
421
- If an image is not existing, but used within the Cyberweb
422
- framework, then a a red border and a red text will be
423
- displayed around that (non-existing) image.
428
+ If an image is not existing, but used within the Cyberweb framework,
429
+ then a a red border and a red text will be displayed around that
430
+ (non-existing) image.
424
431
 
425
432
  This way, the user is being encouraged to fix the problem at hand.
426
433
 
@@ -429,11 +436,13 @@ fix/change this.
429
436
 
430
437
  This is why the red warning or warnings in general, can be reduced
431
438
  or disabled - have a look at the configuration file for this.
439
+ Personally I prefer a red warning, but others may not want to
440
+ have this.
432
441
 
433
- If warnings are set to verbose, then the web_object project will
434
- display the above notification for images not found. If it is set
435
- to normal or lower than that, the web_object project will not
436
- display that warning.
442
+ If <b>warnings</b> are set to verbose, then the <b>cyberweb project</b>
443
+ will display the notification mentioned above for all images that
444
+ were not found. If it is set to normal or lower than that, the
445
+ cyberweb project will <b>not</b> display that warning.
437
446
 
438
447
  ## Greek letters
439
448
 
@@ -447,13 +456,6 @@ the following command:
447
456
 
448
457
  Cyberweb.show_greek_letters
449
458
 
450
- ## Javascript-support in the Cyberweb project
451
-
452
- Have a look at the subdirectory called **javascript/**.
453
-
454
- If a new javascript-component is added, it should be registered
455
- in one of the .rb files in said directory.
456
-
457
459
  ## Commandline usage
458
460
 
459
461
  A commandline program exists, at <b>bin/cyberweb</b>.
@@ -881,18 +883,6 @@ useful for short header-entries, such as "Goals" or
881
883
  functionality purely exists due to convenience - I wanted
882
884
  to quickly generate the default id entry for a sitemap.
883
885
 
884
- ## JavaScript clock
885
-
886
- If you wish to display a small JavaScript "clock" that just
887
- shows the time, you could use this:
888
-
889
- display_clock('pad1em') { :larger_font_size }
890
-
891
- The block argument just increases the font-size a bit; it can
892
- be omitted of course, as can all arguments, too:
893
-
894
- display_clock
895
-
896
886
  ## Redirecting to another page
897
887
 
898
888
  You can combine BeautifulUrl, and Cyberweb, to redirect
@@ -1836,19 +1826,6 @@ To do this, try:
1836
1826
  e('This text should now be editable.') { :editable }
1837
1827
  }
1838
1828
 
1839
- ## Specify javascript files
1840
-
1841
- You can specify a specific javascript file via:
1842
-
1843
- w.javascript_file = '../../CODE/JS/FADER.js'
1844
- w.javascript_file = :fader
1845
-
1846
- As you can see, both a string version giving the full path, and a
1847
- Symbol shortcut, will work - provided that the Symbol was registered.
1848
-
1849
- I recommend to use the Symbol version for two reasons: first, it is
1850
- less to type. Second, it is trivial to change the path lateron.
1851
-
1852
1829
  ## Configuration
1853
1830
 
1854
1831
  All meaningful options that can be configured, can be configured
@@ -2380,32 +2357,6 @@ Valid cursors include:
2380
2357
  not-allowed
2381
2358
  no-drop
2382
2359
 
2383
- ## Removing child elements in JavaScript
2384
-
2385
- An element can be removed via JavaScript by issueing:
2386
-
2387
- this.parentNode.removeChild(this)
2388
-
2389
- ## Default parameters to functions in JavaScript
2390
-
2391
- You can use default values to functions in JavaScript.
2392
-
2393
- Example:
2394
-
2395
- function multiply(a, b = 1) {
2396
- return a * b;
2397
- }
2398
-
2399
- console.log(multiply(5, 2));
2400
- console.log(multiply(5));
2401
-
2402
- Alternatively you could also use || inside of the function
2403
- body, to simulate default values.
2404
-
2405
- It may then look like this inside of a function:
2406
-
2407
- bar = bar || "Default Value";
2408
-
2409
2360
  ## Using language-specific files as content of a webpage
2410
2361
 
2411
2362
  The typical way how I describe the main content of a web-page
@@ -2815,44 +2766,6 @@ Example in HTML:
2815
2766
 
2816
2767
  <img src='foobar.jpg' loading='lazy' alt='Alternative Text'>
2817
2768
 
2818
- ## JavaScript for-in and for-of loops:
2819
-
2820
- Just examples for each:
2821
-
2822
- for (const key in {a: 1, b: 2}) {
2823
- console.log(key);
2824
- }
2825
- // a, b
2826
-
2827
- for (const value of [1,2,3,4,5]) {
2828
- console.log(value);
2829
- }
2830
- // 1, 2, 3, 4, 5
2831
-
2832
- ## Data Types in JavaScript (ECMAScript)
2833
-
2834
- There are six simple data types:
2835
-
2836
- Undefined
2837
- Null
2838
- Boolean
2839
- Number
2840
- String
2841
- Symbol
2842
-
2843
- ## How to use the typeof() operator in JavaScript
2844
-
2845
- The typeof operator is called like this:
2846
-
2847
- let x = "some string";
2848
- typeof(x) # "string"
2849
- typeof(95) # "number"
2850
-
2851
- Note that the () for typeof() could be omitted, as typeof is
2852
- an operator and not a function - but it seems simpler to use
2853
- the () just as it is used for other functions in JavaScript
2854
- as well.
2855
-
2856
2769
  ## CSS zoom-on-hover effect
2857
2770
 
2858
2771
  This can be done like this:
@@ -4224,8 +4137,8 @@ More specifically what these **four values** mean:
4224
4137
 
4225
4138
  drop-shadow(offset-x offset-y blur-radius color)
4226
4139
 
4227
- If you make use of the **cyberweb** project then you
4228
- can use the following API:
4140
+ If you make use of the **cyberweb** project then you can use
4141
+ the following API, to generate a drop shadow:
4229
4142
 
4230
4143
  generate_drop_shadow :red, :default, 'drop_shadow_red'
4231
4144
  div('drop_shadow_red') {
@@ -4424,8 +4337,8 @@ remember that you also get a lot of flexibility that way.
4424
4337
 
4425
4338
  ## The method images_css() in class Cyberweb::WebObject
4426
4339
 
4427
- Sometimes you have several images and may want to apply the
4428
- same CSS rules to all of them.
4340
+ Sometimes you may have several images and may want to apply
4341
+ the same CSS rules to all of them.
4429
4342
 
4430
4343
  For instance, I use the CSS class <b>bblack1</b> which is
4431
4344
  equivalent to:
@@ -4446,6 +4359,10 @@ for a demo in this regard. (Not all images work; some of them
4446
4359
  are only available on my home system, but the other images
4447
4360
  should work.)
4448
4361
 
4362
+ Do note that since as of November 2022, when images_css is
4363
+ used then it will <b>always</b> be appended to every
4364
+ image tag. So only use it if you really need this functionality.
4365
+
4449
4366
  ## links.md
4450
4367
 
4451
4368
  If a file called <b>links.md</b> exists in the current working directory
@@ -4657,6 +4574,258 @@ showcasing this functionality.
4657
4574
 
4658
4575
  <img src="https://i.imgur.com/k5wFnwn.png" style="margin: 1em">
4659
4576
 
4577
+ ## class Cyberweb::ObtainCssRules
4578
+
4579
+ <b>class Cyberweb::ObtainCssRules</b> was added to quickly fetch the
4580
+ CSS rule shortcut.
4581
+
4582
+ For instance, the cyberweb gem comes with many custom CSS classes
4583
+ defined. I use these for different project.
4584
+
4585
+ One such CSS rule is this:
4586
+
4587
+ .mars1em {
4588
+ margin-left: 1em;
4589
+ margin-right: 1em;
4590
+ }
4591
+
4592
+ Now: sometimes I can not use these custom CSS rules, even though I
4593
+ want to.
4594
+
4595
+ <b>class Cyberweb::ObtainCssRules</b> fills that use case.
4596
+
4597
+ We can tell this class to fetch the body of the CSS rule at
4598
+ <b>.mars1em</b>. This will then be automatically expanded
4599
+ onto the corresponding "margin-left" and "margin-right"
4600
+ entries.
4601
+
4602
+ To require this class do:
4603
+
4604
+ require 'cyberweb/utility_scripts/obtain_css_rules.rb'
4605
+
4606
+ Furthermore, this class was also added to automatically
4607
+ make use of various shortcuts.
4608
+
4609
+ Let me demonstrate how I use this specifically.
4610
+
4611
+ In the file pidgin.rb, which is part of the roebe gem,
4612
+ I use the following:
4613
+
4614
+ default_template1 '
4615
+
4616
+ p.default {
4617
+ .mars1em;
4618
+ }
4619
+
4620
+ '
4621
+
4622
+ What does the above mean?
4623
+
4624
+ It means that the p-tag (in HTML), if it makes use of the
4625
+ CSS class called default, will use the CSS rules defined
4626
+ in the .mars1em CSS class' body.
4627
+
4628
+ So, it is <b>exactly</b> identical to the following:
4629
+
4630
+ p.default {
4631
+ margin-left: 1em;
4632
+ margin-right: 1em;
4633
+ }
4634
+
4635
+ This is a bit similar to less and SASS and similar
4636
+ shortcut-tools.
4637
+
4638
+ Within the web-app, for class WebObject, I may then
4639
+ create these paragraphs via:
4640
+
4641
+ p_default {
4642
+ e 'Hello world!'
4643
+ }
4644
+
4645
+ Note that the above does not work 100% reliably; I
4646
+ added this in <b>November 2022</b> in part to try it out.
4647
+
4648
+ At some later point in time this may be improved,
4649
+ so use with care. I recommend to be very strict when
4650
+ using the above functionality; the less complexity,
4651
+ the better usually (unless you can write more succinct
4652
+ and more expressive code, perhaps; but even then it
4653
+ is a trade-off ultimately).
4654
+
4655
+ ## Returning all images from a remote website
4656
+
4657
+ If you ever have a use case that you wish to return all
4658
+ images found on a remote website, consider using the
4659
+ following API:
4660
+
4661
+ x = Cyberweb.return_all_images_from_this_webpage('https://www.projectaon.org/en/xhtml/lw/02fotw/sect166.htm', true)
4662
+
4663
+ This would yield the following Array:
4664
+
4665
+ [
4666
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/title.png",
4667
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/brdrtpl.png",
4668
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/brdrtp.png",
4669
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/brdrtpr.png",
4670
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/brdrl.png",
4671
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/ill10.png",
4672
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/brdrr.png",
4673
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/brdrbtl.png",
4674
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/brdrbt.png",
4675
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/brdrbtr.png",
4676
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/left.png",
4677
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/toc.png",
4678
+ "https://www.projectaon.org/en/xhtml/lw/02fotw/right.png"
4679
+ ]
4680
+
4681
+ ## JavaScript support in the cyberweb project
4682
+
4683
+ ### JavaScript for-in and for-of loops:
4684
+
4685
+ Just examples for each:
4686
+
4687
+ for (const key in {a: 1, b: 2}) {
4688
+ console.log(key);
4689
+ }
4690
+ // a, b
4691
+
4692
+ for (const value of [1,2,3,4,5]) {
4693
+ console.log(value);
4694
+ }
4695
+ // 1, 2, 3, 4, 5
4696
+
4697
+ ### Javascript-support in the Cyberweb project
4698
+
4699
+ Have a look at the subdirectory called **javascript/**.
4700
+
4701
+ If a new javascript-component is added, it should be registered
4702
+ in one of the .rb files in said directory.
4703
+
4704
+ ### Data Types in JavaScript (ECMAScript)
4705
+
4706
+ There are six simple data types:
4707
+
4708
+ Undefined
4709
+ Null
4710
+ Boolean
4711
+ Number
4712
+ String
4713
+ Symbol
4714
+
4715
+ ### How to use the typeof() operator in JavaScript
4716
+
4717
+ The typeof operator is called like this:
4718
+
4719
+ let x = "some string";
4720
+ typeof(x) # "string"
4721
+ typeof(95) # "number"
4722
+
4723
+ Note that the () for typeof() could be omitted, as typeof is
4724
+ an operator and not a function - but it seems simpler to use
4725
+ the () just as it is used for other functions in JavaScript
4726
+ as well.
4727
+
4728
+ ### JavaScript clock
4729
+
4730
+ If you wish to display a small JavaScript "clock" that just
4731
+ shows the time, you could use this:
4732
+
4733
+ display_clock('pad1em') { :larger_font_size }
4734
+
4735
+ The block argument just increases the font-size a bit; it can
4736
+ be omitted of course, as can all arguments, too:
4737
+
4738
+ display_clock
4739
+
4740
+ ### Specify JavaScript files
4741
+
4742
+ You can specify a specific javascript file via:
4743
+
4744
+ w.javascript_file = '../../CODE/JS/FADER.js'
4745
+ w.javascript_file = :fader
4746
+
4747
+ As you can see, both a string version giving the full path, and a
4748
+ Symbol shortcut, will work - provided that the Symbol was registered.
4749
+
4750
+ I recommend to use the Symbol version for two reasons: first, it is
4751
+ less to type. Second, it is trivial to change the path lateron.
4752
+
4753
+ ### Removing child elements in JavaScript
4754
+
4755
+ An element can be removed via JavaScript by issueing:
4756
+
4757
+ this.parentNode.removeChild(this)
4758
+
4759
+ ### Default parameters to functions in JavaScript
4760
+
4761
+ You can use default values to functions in JavaScript.
4762
+
4763
+ Example:
4764
+
4765
+ function multiply(a, b = 1) {
4766
+ return a * b;
4767
+ }
4768
+
4769
+ console.log(multiply(5, 2));
4770
+ console.log(multiply(5));
4771
+
4772
+ Alternatively you could also use || inside of the function
4773
+ body, to simulate default values.
4774
+
4775
+ It may then look like this inside of a function:
4776
+
4777
+ bar = bar || "Default Value";
4778
+
4779
+ ### JavaScript's document.getElementById()
4780
+
4781
+ You can use JavaScript's document.getElementById() to modify
4782
+ values programmatically.
4783
+
4784
+ Example showcasing this:
4785
+
4786
+ function foobar() {
4787
+ document.getElementById("set_on_value_changed").value = "44";
4788
+ }
4789
+
4790
+ All you need to know is the ID of the target element.
4791
+
4792
+ ### Does order matter for JavaScript?
4793
+
4794
+ Script tags that are used in a webpage are executed in the order they
4795
+ appear. So, if you look at the following JavaScript code:
4796
+
4797
+ <script>
4798
+ var x = 42;
4799
+ </script>
4800
+
4801
+ <script>
4802
+ alert(x); // Will alert '3';
4803
+ </script>
4804
+
4805
+ Then first the variable x will be set, to the value of <b>42</b>.
4806
+
4807
+ Note that this also applies to when you load external .js files - first
4808
+ in, first to be evaluated. So order does indeed matter.
4809
+
4810
+ The reason I noted this down here was in the event that I may forgot
4811
+ why I decided to load some .js files before others.
4812
+
4813
+ There is, however had, also a practical consideration here: if you
4814
+ have some external .js files that take a while to load, it may be
4815
+ best to put them near the end of the page, or at the least after
4816
+ other .js files were already loaded, as it may otherwise slow
4817
+ down the loading of the webpage. This is the reason why some
4818
+ webpages recommend to put JavaScript script-tags shortly before
4819
+ the closing </body> tag rather than in the <head> section of
4820
+ the given HTML code at hand.
4821
+
4822
+ You can also use the async keyword; this means that the loading of
4823
+ the webpage will continue.
4824
+
4825
+ Example:
4826
+
4827
+ <script src="path/foobar.js" async></script>
4828
+
4660
4829
  ## Useful quotes when designing websites and web-apps
4661
4830
 
4662
4831
  The following subsection collects a few <b>interesting statements</b> -