cyberweb 0.12.35 → 0.13.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +220 -124
  3. data/bin/cyberweb_sanitize +1 -1
  4. data/bin/images_from_this_webpage +1 -1
  5. data/doc/README.gen +209 -98
  6. data/doc/configuration/configuration.md +7 -4
  7. data/doc/todo/todo_for_the_cyberweb_project.md +123 -133
  8. data/examples/html/underlined_text_example/underlined_text_example.html +40 -0
  9. data/examples/misc/table_example.rb +19 -17
  10. data/examples/objectified/objectified_caesar_cipher.cgi +73 -0
  11. data/images/cyberweb_theme.png +0 -0
  12. data/lib/cyberweb/REST/constants.rb +1 -1
  13. data/lib/cyberweb/base/base.rb +19 -27
  14. data/lib/cyberweb/base_module/base_module/base_module.rb +31 -16
  15. data/lib/cyberweb/base_module/colours/colours.rb +0 -8
  16. data/lib/cyberweb/cascading_style_sheets/margin.css +4 -0
  17. data/lib/cyberweb/cascading_style_sheets/misc.css +15 -0
  18. data/lib/cyberweb/cgi/cookie.rb +160 -156
  19. data/lib/cyberweb/cgi/core.rb +7 -7
  20. data/lib/cyberweb/cgi/query_extension.rb +1 -1
  21. data/lib/cyberweb/cgi/session/memory_store.rb +1 -1
  22. data/lib/cyberweb/cgi/session/pstore.rb +2 -2
  23. data/lib/cyberweb/cgi/session.rb +1 -1
  24. data/lib/cyberweb/cgi/util.rb +4 -1
  25. data/lib/cyberweb/cmd/cmd.rb +12 -10
  26. data/lib/cyberweb/coloured_tags/coloured_tags.rb +1 -1
  27. data/lib/cyberweb/colours/colour_chart.rb +1 -2
  28. data/lib/cyberweb/colours/colours.rb +1 -1
  29. data/lib/cyberweb/commandline/commandline_interface.rb +1 -1
  30. data/lib/cyberweb/configuration/load_the_configuration.rb +3 -1
  31. data/lib/cyberweb/constants/http_status_codes.rb +4 -1
  32. data/lib/cyberweb/constants/misc.rb +8 -6
  33. data/lib/cyberweb/constants/registered_html_tags.rb +6 -5
  34. data/lib/cyberweb/constants/user_x.rb +7 -0
  35. data/lib/cyberweb/css_manager/css_manager.rb +5 -2
  36. data/lib/cyberweb/encoding/encoding.rb +1 -1
  37. data/lib/cyberweb/erb/test.rhtml +7 -2
  38. data/lib/cyberweb/experimental/html_template_powered_by_rack.rb +3 -1
  39. data/lib/cyberweb/foto_gallery/foto_gallery.rb +3 -0
  40. data/lib/cyberweb/generator/cgi.rb +1 -1
  41. data/lib/cyberweb/html_template/html_template.rb +383 -311
  42. data/lib/cyberweb/images/images.rb +2 -2
  43. data/lib/cyberweb/images/remove_this_substring_from_all_images.rb +5 -1
  44. data/lib/cyberweb/images/standard_images/standard_images.html +3 -4
  45. data/lib/cyberweb/information/README.md +2 -2
  46. data/lib/cyberweb/information/information.cgi +1 -1
  47. data/lib/cyberweb/javascript/dragula_collection.rb +4 -1
  48. data/lib/cyberweb/javascript/javascript_magic.rb +2 -2
  49. data/lib/cyberweb/javascript/on_click_change_opacity.rb +2 -1
  50. data/lib/cyberweb/javascript/popup.rb +8 -1
  51. data/lib/cyberweb/javascript/snoweffect.rb +5 -1
  52. data/lib/cyberweb/javascript_code/custom_functions.js +50 -32
  53. data/lib/cyberweb/objectified/html_tags/README.md +7 -9
  54. data/lib/cyberweb/objectified/html_tags/a.rb +62 -3
  55. data/lib/cyberweb/objectified/html_tags/abbr.rb +33 -3
  56. data/lib/cyberweb/objectified/html_tags/audio.rb +33 -3
  57. data/lib/cyberweb/objectified/html_tags/base.rb +661 -588
  58. data/lib/cyberweb/objectified/html_tags/blockquote.rb +33 -3
  59. data/lib/cyberweb/objectified/html_tags/body.rb +43 -3
  60. data/lib/cyberweb/objectified/html_tags/button.rb +75 -5
  61. data/lib/cyberweb/objectified/html_tags/canvas.rb +43 -3
  62. data/lib/cyberweb/objectified/html_tags/cite.rb +43 -3
  63. data/lib/cyberweb/objectified/html_tags/div.rb +70 -7
  64. data/lib/cyberweb/objectified/html_tags/embed.rb +43 -3
  65. data/lib/cyberweb/objectified/html_tags/fieldset.rb +43 -3
  66. data/lib/cyberweb/objectified/html_tags/figure.rb +43 -3
  67. data/lib/cyberweb/objectified/html_tags/form.rb +78 -3
  68. data/lib/cyberweb/objectified/html_tags/h1.rb +43 -3
  69. data/lib/cyberweb/objectified/html_tags/h2.rb +43 -3
  70. data/lib/cyberweb/objectified/html_tags/h3.rb +43 -3
  71. data/lib/cyberweb/objectified/html_tags/h4.rb +43 -3
  72. data/lib/cyberweb/objectified/html_tags/h5.rb +43 -3
  73. data/lib/cyberweb/objectified/html_tags/h6.rb +43 -3
  74. data/lib/cyberweb/objectified/html_tags/head.rb +34 -1
  75. data/lib/cyberweb/objectified/html_tags/i.rb +112 -0
  76. data/lib/cyberweb/objectified/html_tags/img.rb +65 -18
  77. data/lib/cyberweb/objectified/html_tags/input.rb +86 -2
  78. data/lib/cyberweb/objectified/html_tags/label.rb +103 -0
  79. data/lib/cyberweb/objectified/html_tags/legend.rb +129 -0
  80. data/lib/cyberweb/objectified/html_tags/li.rb +111 -0
  81. data/lib/cyberweb/objectified/html_tags/map.rb +43 -3
  82. data/lib/cyberweb/objectified/html_tags/meta.rb +13 -2
  83. data/lib/cyberweb/objectified/html_tags/nav.rb +111 -0
  84. data/lib/cyberweb/objectified/html_tags/object.rb +33 -3
  85. data/lib/cyberweb/objectified/html_tags/ol.rb +127 -0
  86. data/lib/cyberweb/objectified/html_tags/p.rb +33 -3
  87. data/lib/cyberweb/objectified/html_tags/pre.rb +41 -4
  88. data/lib/cyberweb/objectified/html_tags/progress.rb +43 -3
  89. data/lib/cyberweb/objectified/html_tags/section.rb +116 -0
  90. data/lib/cyberweb/objectified/html_tags/select.rb +34 -1
  91. data/lib/cyberweb/objectified/html_tags/span.rb +64 -5
  92. data/lib/cyberweb/objectified/html_tags/style.rb +9 -2
  93. data/lib/cyberweb/objectified/html_tags/table.rb +137 -3
  94. data/lib/cyberweb/objectified/html_tags/td.rb +135 -0
  95. data/lib/cyberweb/objectified/html_tags/textarea.rb +37 -3
  96. data/lib/cyberweb/objectified/html_tags/th.rb +114 -0
  97. data/lib/cyberweb/objectified/html_tags/thead.rb +114 -0
  98. data/lib/cyberweb/objectified/html_tags/title.rb +10 -2
  99. data/lib/cyberweb/objectified/html_tags/tr.rb +110 -0
  100. data/lib/cyberweb/objectified/html_tags/ul.rb +45 -4
  101. data/lib/cyberweb/objectified/shorter_helper_methods/shorter_helper_methods.rb +67 -46
  102. data/lib/cyberweb/oop.rb +9 -0
  103. data/lib/cyberweb/predefined_and_freeform_methods/hash_registered_extra_tags.rb +2 -0
  104. data/lib/cyberweb/predefined_and_freeform_methods/header.rb +4 -1
  105. data/lib/cyberweb/project/project.rb +0 -4
  106. data/lib/cyberweb/requires/remove_html.rb +1 -1
  107. data/lib/cyberweb/requires/require_the_cyberweb_project.rb +1 -9
  108. data/lib/cyberweb/route_handler/module/route_handler_module.rb +2 -1
  109. data/lib/cyberweb/standalone_classes/all_css_classes.rb +5 -2
  110. data/lib/cyberweb/standalone_classes/calculator.rb +3 -1
  111. data/lib/cyberweb/toplevel_methods/audio.rb +3 -1
  112. data/lib/cyberweb/toplevel_methods/csv.rb +1 -1
  113. data/lib/cyberweb/toplevel_methods/frames.rb +11 -3
  114. data/lib/cyberweb/toplevel_methods/greek_letters/greek_letters.rb +3 -0
  115. data/lib/cyberweb/toplevel_methods/hfin.rb +5 -1
  116. data/lib/cyberweb/toplevel_methods/html_tags/README.md +8 -7
  117. data/lib/cyberweb/toplevel_methods/html_tags/html_tags.rb +4211 -2827
  118. data/lib/cyberweb/toplevel_methods/html_tags/table.rb +1202 -0
  119. data/lib/cyberweb/toplevel_methods/javascript.rb +9 -1
  120. data/lib/cyberweb/toplevel_methods/jquery.rb +1 -1
  121. data/lib/cyberweb/toplevel_methods/{log_directory.rb → log_directory_and_logging.rb} +36 -1
  122. data/lib/cyberweb/toplevel_methods/params.rb +11 -11
  123. data/lib/cyberweb/toplevel_methods/random.rb +4 -3
  124. data/lib/cyberweb/toplevel_methods/registered_ids.rb +3 -0
  125. data/lib/cyberweb/toplevel_methods/return_head_start.rb +1 -3
  126. data/lib/cyberweb/toplevel_methods/return_html_start.rb +1 -3
  127. data/lib/cyberweb/toplevel_methods/sanitize_url.rb +2 -1
  128. data/lib/cyberweb/toplevel_methods/server_base_directory.rb +0 -1
  129. data/lib/cyberweb/toplevel_methods/textile.rb +2 -1
  130. data/lib/cyberweb/toplevel_methods/{misc.rb → toplevel_methods.rb} +1446 -807
  131. data/lib/cyberweb/toplevel_methods/video.rb +21 -3
  132. data/lib/cyberweb/toplevel_methods/write_what_into.rb +2 -2
  133. data/lib/cyberweb/utility_scripts/autogenerate_drop_shadow_rules/autogenerate_drop_shadow_rules.rb +2 -4
  134. data/lib/cyberweb/utility_scripts/booklet/booklet.rb +0 -4
  135. data/lib/cyberweb/utility_scripts/download_all_images_from_this_website.rb +1 -1
  136. data/lib/cyberweb/utility_scripts/{download_balloon_css.rb → download_balloon_css/download_balloon_css.rb} +1 -1
  137. data/lib/cyberweb/utility_scripts/images_to_html/images_to_html.rb +3 -0
  138. data/lib/cyberweb/utility_scripts/obtain_files_and_directories_from_this_path/obtain_files_and_directories_from_this_path.rb +184 -72
  139. data/lib/cyberweb/utility_scripts/pdf_to_html/pdf_to_html.rb +161 -65
  140. data/lib/cyberweb/version/version.rb +2 -2
  141. data/lib/cyberweb/web_images/map_symbol_to_image_location.rb +13 -2
  142. data/lib/cyberweb/web_object/web_object.rb +65 -67
  143. data/lib/cyberweb/web_scraper/scrape_this_url.rb +3 -1
  144. data/lib/cyberweb/webmin/biology_server.cgi +1 -1
  145. data/lib/cyberweb/webmin/calculator.cgi +1 -1
  146. data/lib/cyberweb/webmin/colour_chart.cgi +1 -1
  147. data/lib/cyberweb/webmin/comments.cgi +2 -2
  148. data/lib/cyberweb/webmin/constants.rb +1 -1
  149. data/lib/cyberweb/webmin/dictionary.cgi +2 -2
  150. data/lib/cyberweb/webmin/simple_forum/index.cgi +2 -2
  151. data/lib/cyberweb/webmin/sys_info.cgi +3 -3
  152. data/lib/cyberweb/webmin/webforum.cgi +1 -1
  153. data/lib/cyberweb/yaml/registered_html_tags.yml +3 -1
  154. data/test/simple_tests/testing_return_dataset_without_any_comments.rb +1 -1
  155. metadata +23 -57
  156. data/lib/cyberweb/html_tags/README.md +0 -3
  157. data/lib/cyberweb/html_tags/a.rb +0 -67
  158. data/lib/cyberweb/html_tags/accesskey.rb +0 -25
  159. data/lib/cyberweb/html_tags/blockquote.rb +0 -56
  160. data/lib/cyberweb/html_tags/body.rb +0 -14
  161. data/lib/cyberweb/html_tags/br.rb +0 -19
  162. data/lib/cyberweb/html_tags/button.rb +0 -150
  163. data/lib/cyberweb/html_tags/canvas.rb +0 -59
  164. data/lib/cyberweb/html_tags/chtml.rb +0 -14
  165. data/lib/cyberweb/html_tags/div.rb +0 -170
  166. data/lib/cyberweb/html_tags/fieldset.rb +0 -69
  167. data/lib/cyberweb/html_tags/figure.rb +0 -72
  168. data/lib/cyberweb/html_tags/form.rb +0 -203
  169. data/lib/cyberweb/html_tags/h1.rb +0 -77
  170. data/lib/cyberweb/html_tags/h2.rb +0 -81
  171. data/lib/cyberweb/html_tags/h3.rb +0 -60
  172. data/lib/cyberweb/html_tags/h4.rb +0 -66
  173. data/lib/cyberweb/html_tags/h5.rb +0 -64
  174. data/lib/cyberweb/html_tags/h6.rb +0 -60
  175. data/lib/cyberweb/html_tags/hr.rb +0 -22
  176. data/lib/cyberweb/html_tags/html_tags.rb +0 -267
  177. data/lib/cyberweb/html_tags/i.rb +0 -52
  178. data/lib/cyberweb/html_tags/img.rb +0 -294
  179. data/lib/cyberweb/html_tags/input.rb +0 -354
  180. data/lib/cyberweb/html_tags/label.rb +0 -65
  181. data/lib/cyberweb/html_tags/legend.rb +0 -56
  182. data/lib/cyberweb/html_tags/li.rb +0 -67
  183. data/lib/cyberweb/html_tags/map.rb +0 -38
  184. data/lib/cyberweb/html_tags/nav.rb +0 -63
  185. data/lib/cyberweb/html_tags/object.rb +0 -57
  186. data/lib/cyberweb/html_tags/ol.rb +0 -57
  187. data/lib/cyberweb/html_tags/option.rb +0 -64
  188. data/lib/cyberweb/html_tags/p.rb +0 -88
  189. data/lib/cyberweb/html_tags/pre.rb +0 -162
  190. data/lib/cyberweb/html_tags/section.rb +0 -33
  191. data/lib/cyberweb/html_tags/select.rb +0 -104
  192. data/lib/cyberweb/html_tags/span.rb +0 -344
  193. data/lib/cyberweb/html_tags/strong.rb +0 -42
  194. data/lib/cyberweb/html_tags/table.rb +0 -284
  195. data/lib/cyberweb/html_tags/tbody.rb +0 -26
  196. data/lib/cyberweb/html_tags/td.rb +0 -212
  197. data/lib/cyberweb/html_tags/textarea.rb +0 -173
  198. data/lib/cyberweb/html_tags/th.rb +0 -70
  199. data/lib/cyberweb/html_tags/thead.rb +0 -41
  200. data/lib/cyberweb/html_tags/tr.rb +0 -99
  201. data/lib/cyberweb/html_tags/ul.rb +0 -51
  202. data/lib/cyberweb/requires/require_html_tags_files.rb +0 -23
  203. data/lib/cyberweb/toplevel_methods/logging.rb +0 -42
  204. data/lib/cyberweb/web_base/web_base.rb +0 -33
@@ -2,12 +2,10 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- # === Cyberweb
5
+ # Different tags are used in the Cyberweb project. These generate HTML
6
+ # tags ultimately.
6
7
  #
7
- # There are different tags used in the Cyberweb project. These generate
8
- # HTML tags ultimately.
9
- #
10
- # Use this general rule when passing arguments to such tags:
8
+ # Use this general rule when passing arguments to such HTML tags:
11
9
  #
12
10
  # css_class, id, css_style
13
11
  #
@@ -21,7 +19,7 @@
21
19
  #
22
20
  # Here you can obviously be more flexible.
23
21
  # =========================================================================== #
24
- # require 'cyberweb/toplevel_methods/misc.rb'
22
+ # require 'cyberweb/toplevel_methods/toplevel_methods.rb'
25
23
  # Cyberweb.download_webpage
26
24
  # Cyberweb.remove_html(ARGV)
27
25
  # Cyberweb.html_comment(ARGV)
@@ -34,14 +32,6 @@
34
32
  module Cyberweb
35
33
 
36
34
  require 'yaml'
37
- require 'cyberweb/constants/constants.rb'
38
- require 'cyberweb/encoding/encoding.rb'
39
- require 'cyberweb/javascript/javascript.rb'
40
- require 'cyberweb/toplevel_methods/ee.rb'
41
- require 'cyberweb/toplevel_methods/is_an_image.rb'
42
- require 'cyberweb/toplevel_methods/registered_ids.rb'
43
- require 'cyberweb/toplevel_methods/server_base_directory.rb'
44
- require 'cyberweb/images/images.rb'
45
35
 
46
36
  # ========================================================================= #
47
37
  # Try to next include coderay, silently.
@@ -50,10 +40,26 @@ module Cyberweb
50
40
  require 'coderay'
51
41
  rescue LoadError; end
52
42
 
43
+ begin
44
+ require 'html_tags'
45
+ rescue LoadError; end
46
+
53
47
  begin
54
48
  require 'roebe/modules/remove_html.rb'
55
49
  rescue LoadError; end
56
50
 
51
+ require 'cyberweb/constants/constants.rb'
52
+ require 'cyberweb/encoding/encoding.rb'
53
+ require 'cyberweb/colours/colours.rb'
54
+ require 'cyberweb/javascript/javascript.rb'
55
+ require 'cyberweb/toplevel_methods/close.rb'
56
+ require 'cyberweb/toplevel_methods/ee.rb'
57
+ require 'cyberweb/toplevel_methods/is_an_image.rb'
58
+ require 'cyberweb/toplevel_methods/process_content.rb'
59
+ require 'cyberweb/toplevel_methods/registered_ids.rb'
60
+ require 'cyberweb/toplevel_methods/server_base_directory.rb'
61
+ require 'cyberweb/images/images.rb'
62
+
57
63
  # ========================================================================= #
58
64
  # === ARRAY_DEFAULT_JAVASCRIPT_LIBRARIES
59
65
  #
@@ -132,207 +138,412 @@ module Cyberweb
132
138
  end; alias return_utf return_utf_charset # === return_utf
133
139
 
134
140
  # ========================================================================= #
135
- # === Cyberweb.spinbutton
141
+ # === Cyberweb.string_s (string_s tag)
136
142
  #
137
- # In December 2023 I confirmed that this code will create a spinbutton.
143
+ # This method returns the string of a tag.
138
144
  #
139
- # Note that in HTML, this is more commonly called a "number-input".
145
+ # You can use that string lateron in your ruby programs. The difference
146
+ # towards string_tag and this method here is that string_s also gives
147
+ # back the content, whereas string_tag only gives back the complete
148
+ # <tag> in question. We will use string_tag in this method here.
140
149
  #
141
- # The following attributes can be used to specify restrictions:
150
+ # Usage example to call string_s indirectly:
142
151
  #
143
- # max: specifies the maximum value allowed
144
- # min: specifies the minimum value allowed
145
- # step: specifies the step-size
146
- # value: specifies the default value
152
+ # Cyberweb.string_s(text,'h4',css_class, the_id, css_style, javascript = ''); n
153
+ # Cyberweb.string_s("Hello world!", 'span', '','','margin-left:0.92em; padding-left:6px')
147
154
  #
148
155
  # ========================================================================= #
149
- def self.spinbutton(
150
- start_position = 0,
151
- end_position = 100,
152
- increment_size = 1,
153
- id_to_be_used = nil
156
+ def self.string_s(
157
+ content = '', # This variable keeps track of the text to be displayed.
158
+ which_tag = 'span',
159
+ css_class = '',
160
+ the_id = '',
161
+ css_style = '',
162
+ javascript_code = '',
163
+ &block
154
164
  )
155
- extra_CSS_rules = '
156
- <style>
157
- /* This will always show the spin buttons on the right side */
158
- input[type=number]::-webkit-inner-spin-button {
159
- opacity: 1
160
- }
161
- </style>
162
- '
163
- if id_to_be_used # This is the case when a id-value is provided.
164
- return extra_CSS_rules+
165
- '<input step="'+increment_size.to_s+'" id="'+id_to_be_used+'" '\
166
- 'type="number" value="'+start_position.to_s+'" min="1" max="'+end_position.to_s+'" />'
167
- else
168
- return extra_CSS_rules+
169
- '<input step="'+increment_size.to_s+'" '\
170
- 'type="number" value="'+start_position.to_s+'" min="1" max="'+end_position.to_s+'" />'
165
+ append_a_newline = true
166
+ # ======================================================================= #
167
+ # === Handle Hashes given to the_id variable
168
+ # ======================================================================= #
169
+ if the_id.is_a? Hash
170
+ if the_id.has_key? :style
171
+ css_style = the_id.delete(:style)
172
+ the_id = ''
173
+ end
171
174
  end
172
- end
173
-
174
- # ========================================================================= #
175
- # === Cyberweb.download_webpage
176
- #
177
- # The argument to this method should be a remote website.
178
- #
179
- # Usage example:
180
- #
181
- # Cyberweb.download_webpage('https://www.cardmarket.com/en/Magic/Orders/Sales/ShoppingCart')
182
- # x = Cyberweb.download_webpage('https://www.cardmarket.com/en/Magic/Orders/Sales/ShoppingCart', { http_basic_authentication: ['shev55y@inbox.ar', 'JJJieie33aeeeggkhlhgejk7878eKIEUIbeue'] })
183
- #
184
- # ========================================================================= #
185
- def self.download_webpage(
186
- remote_URL = ARGV,
187
- options = {}
188
- )
189
- require 'cyberweb/coloured_tags/coloured_tags.rb'
190
- require 'open-uri'
191
- if remote_URL.is_a? Array
192
- remote_URL = remote_URL.first
175
+ the_id = the_id.to_s.dup
176
+ # ======================================================================= #
177
+ # Work on the css_class next.
178
+ # ======================================================================= #
179
+ if css_class.is_a? Hash
180
+ if css_class.has_key? :style
181
+ css_style = css_class.delete(:style)
182
+ css_class = ''
183
+ end
184
+ # ===================================================================== #
185
+ # === :id
186
+ # ===================================================================== #
187
+ if css_class.has_key? :id
188
+ the_id = css_class.delete :id
189
+ css_class = ''
190
+ end
193
191
  end
194
- if options and options.is_a?(Hash) and options.has_key?(:http_basic_authentication)
195
- what = URI.open(remote_URL, options[:http_basic_authentication]).read
196
- else
197
- what = URI.open(remote_URL).read
192
+ if css_style.is_a? Hash
193
+ # ===================================================================== #
194
+ # === :style
195
+ # ===================================================================== #
196
+ if css_style.has_key? :style
197
+ css_style = css_style.delete(:style)
198
+ css_style = ''
199
+ end
198
200
  end
199
- remote_extension = File.extname(remote_URL)
200
- into = File.basename(remote_URL).dup+remote_extension
201
+ css_class = css_class.to_s.chomp.strip.dup # Sanitize to be on the safe side.
201
202
  # ======================================================================= #
202
- # === Handle blocks next
203
+ # Handle some Macros next:
204
+ # ======================================================================= #
205
+ css_class = sanitize_for_colours(css_class)
206
+ # ======================================================================= #
207
+ # Checking for Fixnum arguments.
208
+ # ======================================================================= #
209
+ if which_tag.is_a? Integer
210
+ case which_tag
211
+ when 1 then which_tag = 'div'
212
+ when 2 then which_tag = 'p'
213
+ when 3 then which_tag = 'span'
214
+ when 4 then which_tag = 'h1'
215
+ when 5 then which_tag = 'h2'
216
+ when 6 then which_tag = 'h3'
217
+ when 7 then which_tag = 'h4'
218
+ when 8 then which_tag = 'h5'
219
+ when 9 then which_tag = 'h6'
220
+ when 's' then which_tag = 'span'
221
+ end
222
+ end
223
+ _ = ''.dup
224
+ # ======================================================================= #
225
+ # Here follow all types that are not Fixnum Shortcuts, like 'span'
226
+ # ======================================================================= #
227
+ which_tag = which_tag.to_s.chomp
203
228
  # ======================================================================= #
229
+ # Register this tag as the one last in use.
230
+ # ======================================================================= #
231
+ set_last_tag_used(which_tag)
232
+ which_tag = which_tag.to_s.dup
204
233
  if block_given?
205
- yielded = yield
206
- case yielded
207
- # ===================================================================== #
208
- # === :be_verbose
209
- # ===================================================================== #
210
- when :be_verbose
211
- puts 'Now downloading from `'+
212
- ::Colours.steelblue(remote_URL)+
213
- '` into `'+
214
- ::Colours.royalblue(into)+'`.'
234
+ case yield
235
+ when :no_newline
236
+ append_a_newline = false
237
+ else
215
238
  end
216
239
  end
217
240
  # ======================================================================= #
218
- # Save the content into a file next.
241
+ # Open the tag next, by delegating towards HtmlTags.stag().
219
242
  # ======================================================================= #
220
- write_what_into(what, into)
243
+ html_tag_string = HtmlTags.stag(
244
+ which_tag,
245
+ css_class,
246
+ the_id,
247
+ css_style,
248
+ javascript_code,
249
+ &block
250
+ )
251
+ _ << html_tag_string
221
252
  # ======================================================================= #
222
- # And return the string and the filename that was just downloaded
223
- # as well, as Array.
253
+ # Add content of the span-tag, through string_content().
224
254
  # ======================================================================= #
225
- return [what, into]
255
+ _ << string_content(content.to_s.dup)
256
+ _ = _.to_s.dup
257
+ # ======================================================================= #
258
+ # === Append the closing tag next
259
+ #
260
+ # We will append the closing-tag next.
261
+ # ======================================================================= #
262
+ append_this_string = string_close(which_tag.to_s.dup, &block)
263
+ _ << append_this_string.to_s.dup
264
+ _ << NL.to_s.dup if append_a_newline
265
+ return _.to_s.dup
226
266
  end
227
267
 
228
268
  # ========================================================================= #
229
- # === Cyberweb.return_program_name
269
+ # === Cyberweb.extract_date
230
270
  # ========================================================================= #
231
- def self.return_program_name(i)
232
- return File.basename($PROGRAM_NAME)
271
+ def self.extract_date(
272
+ i,
273
+ regex = /\d{2}\.\d{2}\.\d{4}/
274
+ )
275
+ result = i.scan(regex).flatten.first
276
+ return result.to_s
233
277
  end
234
278
 
235
279
  # ========================================================================= #
236
- # === Cyberweb.return_utf_charset (utf tag)
237
- #
238
- # Return the proper UTF charset in the header. Note that UTF-8 is the
239
- # default charset for HTML5.
240
- #
241
- # This would return the string '<meta charset="UTF-8">'.
280
+ # === Cyberweb.string_span
242
281
  #
243
- # Note that CSS can also use an encoding charset, via something
244
- # like:
282
+ # This method will ultimately yield a <span> tag, a String object.
245
283
  #
246
- # @charset "UTF-8";
284
+ # Currently two aliases exist to this method; one of these two,
285
+ # which is Cyberweb.span(), may be subject to change or removal
286
+ # at a later time - but it may also stay. I have not decided yet.
247
287
  #
288
+ # I recommend to use the more verbose variant called
289
+ # Cyberweb.string_span() but if you want to, you can also use
290
+ # Cyberweb.span(); do so at your own risk, though.
248
291
  # ========================================================================= #
249
- def self.return_utf_charset
250
- "<meta charset=\"UTF-8\">#{NL}"
251
- end; self.instance_eval { alias return_utf return_utf_charset } # === Cyberweb.return_utf
252
- self.instance_eval { alias return_unicode_meta return_utf_charset } # === Cyberweb.return_unicode_meta
253
-
254
- # ========================================================================= #
255
- # === return_iso_8859_charset
256
- # ========================================================================= #
257
- def return_iso_8859_charset
258
- ::Cyberweb.return_iso_8859_charset
259
- end; alias return_iso return_iso_8859_charset # === return_iso
260
- alias return_iso_encoding return_iso_8859_charset # === return_iso_encoding
292
+ def self.string_span(
293
+ content = '',
294
+ css_class = Span.to_s,
295
+ the_id = '',
296
+ css_style = '',
297
+ javascript = '',
298
+ &block
299
+ )
300
+ ::Cyberweb.string_s(
301
+ content,
302
+ 'span',
303
+ css_class,
304
+ the_id,
305
+ css_style,
306
+ javascript,
307
+ &block
308
+ )
309
+ end; self.instance_eval { alias string_s2 string_span } # === Cyberweb.string_s2
310
+ self.instance_eval { alias span string_span } # === Cyberweb.span
261
311
 
262
312
  # ========================================================================= #
263
- # === Cyberweb.return_iso_8859_charset (iso tag)
313
+ # === Cyberweb.string_content
314
+ #
315
+ # This method normally only returns a string, however since as of
316
+ # 26.03.2008 we also process the input via process_content()
317
+ #
318
+ # Since 13.09.2008 we no longer use +NL here.
319
+ #
320
+ # If the input contains the special constant called SPACE then we will
321
+ # replace this with new lines.
264
322
  # ========================================================================= #
265
- def self.return_iso_8859_charset
266
- "<meta charset=\"ISO-8859-1\">#{NL}"
267
- end; self.instance_eval { alias return_iso return_iso_8859_charset } # === Cyberweb.return_iso
268
- self.instance_eval { alias return_iso_encoding return_iso_8859_charset } # === Cyberweb.return_iso_encoding
323
+ def self.string_content(i)
324
+ i = i.to_s.dup # Need to work on a copy.
325
+ i.gsub!(/SPACE/,'&nbsp;') if i.include? 'SPACE'
326
+ return ::Cyberweb.process_content(i)
327
+ end #; self.instance_eval { alias string_cont string_content } # === Cyberweb.string_cont
269
328
 
270
329
  # ========================================================================= #
271
- # === Cyberweb.arrow_right
330
+ # === Cyberweb.right_arrow
272
331
  # ========================================================================= #
273
- def self.arrow_right
274
- ''
275
- end
332
+ def self.right_arrow
333
+ '&rarr;'
334
+ end; self.instance_eval { alias rarrow? right_arrow } # === Cyberweb.rarrow?
276
335
 
277
336
  # ========================================================================= #
278
- # === Cyberweb.left_arrow
337
+ # === Cyberweb.return_time_range_based_on_this_array
338
+ #
339
+ # This method was added in February 2024 to support the pdf-to-html
340
+ # generation of static webpages showing all .pdf files in a given
341
+ # directory.
342
+ #
343
+ # This method must return an Array at all times.
344
+ #
345
+ # The method will then either return:
346
+ #
347
+ # - an Array containing the entry 'unknown'.
348
+ # - an Array containing just one year entry
349
+ # - an Array containing the start-year and the end-year
350
+ #
351
+ # Note that the third result of the above listing is the ideal
352
+ # variant. This method will strive to achieve this, in other
353
+ # words, having two members.
354
+ #
355
+ # Usage example:
356
+ #
357
+ # Cyberweb.return_time_range_based_on_this_array(["AUE_foo/22.10.2004_Ingeborg.pdf", "Bousa/ingeborg.html","20.04.1966_hey"])
358
+ #
279
359
  # ========================================================================= #
280
- def self.left_arrow
281
- '&larr;'
360
+ def self.return_time_range_based_on_this_array(i)
361
+ result = [] # This Array will be returned.
362
+ dd_mm_yyyy_regex = /\d{2}\.\d{2}\.\d{4}/
363
+ # ======================================================================= #
364
+ # Input can be like this:
365
+ #
366
+ # ["AUE_foo/22.10.2004_Ingeborg.pdf", "Bousa/ingeborg.html"]
367
+ #
368
+ # So first we select only the entries that have a dd.mm.yyyy format.
369
+ # ======================================================================= #
370
+ i.reject! {|entry|
371
+ entry !~ dd_mm_yyyy_regex
372
+ }
373
+ entries = []
374
+ i.each {|entry|
375
+ entry = entry.scan(dd_mm_yyyy_regex)
376
+ entries << entry.first.to_s.dup
377
+ }
378
+ entries.uniq!
379
+ result = entries.sort_by {|entry|
380
+ parsed_time = ::Time.parse(entry).to_s
381
+ parsed_time
382
+ }
383
+ result.map! {|entry|
384
+ if entry.include? '.'
385
+ entry = entry.split('.').last
386
+ end
387
+ entry.to_i
388
+ }
389
+ result.uniq!
390
+ # ======================================================================= #
391
+ # We only need the years, though:
392
+ # ======================================================================= #
393
+ max = result.max
394
+ min = result.min
395
+ result = [max, min].compact
396
+ return result.reverse
282
397
  end
283
398
 
284
399
  # ========================================================================= #
285
- # === Cyberweb.glob (glob tag)
286
- #
287
- # Obtain all files from a given directory.
400
+ # === Cyberweb.bruch
288
401
  #
289
- # This is essentially similar to Dir[], but we will append a '*'
290
- # character if no '*' is in our input argument.
402
+ # This is a "bruch", aka a fraction. It is written in german mostly because
403
+ # I am quite lazy.
291
404
  # ========================================================================= #
292
- def self.glob(i)
293
- i = i.to_s
294
- i << '*' unless i.include? '*'
295
- return Dir[i]
405
+ def self.bruch(a, b)
406
+ return "<sup>#{a}</sup>/<sub>#{b}</sub>"
296
407
  end
297
408
 
298
409
  # ========================================================================= #
299
- # === Cyberweb.html_comment
300
- #
301
- # Make use of a html-comment here.
302
- #
303
- # Since as of June 2021 it will append a newline by default.
410
+ # === return_meta_collection
304
411
  # ========================================================================= #
305
- def self.html_comment(
306
- i,
307
- make_newline = true
412
+ def return_meta_collection(
413
+ i = 'UTF-8'
308
414
  )
309
- _ = "<!-- #{i.to_s.rstrip} -->".dup
310
- _ << N if make_newline
311
- _
312
- end; self.instance_eval { alias return_html_comment html_comment } # === Cyberweb.return_html_comment
415
+ ::Cyberweb.return_meta_collection(i)
416
+ end
313
417
 
314
418
  # ========================================================================= #
315
- # === glob
419
+ # === Cyberweb.html_colours?
316
420
  # ========================================================================= #
317
- def glob(i)
318
- ::Cyberweb.glob(i) # We need to scope via :: here.
319
- end
421
+ def self.html_colours?
422
+ ::Colours.html_colours?
423
+ end; self.instance_eval { alias array_all_html_colours? html_colours? } # === Cyberweb.array_all_html_colours?
320
424
 
321
425
  # ========================================================================= #
322
- # === Cyberweb.create_directory
323
- #
324
- # Consistently use this method if you want to create a directory.
325
- # So far this is only used in the file img.rb
426
+ # === is_html5?
326
427
  # ========================================================================= #
327
- def self.create_directory(d)
328
- Dir.mkdir(d)
428
+ def is_html5?
429
+ ::Cyberweb.is_html5?
329
430
  end
330
431
 
331
432
  # ========================================================================= #
332
- # === Cyberweb.return_this_file
433
+ # === Cyberweb.insert_target_blank_onto_this
434
+ #
435
+ # This is an ad-hoc method - I needed to add the substring
436
+ # 'target="_blank"' to a HTML href hyperlink, a <a> tag. Note
437
+ # that input to this ad-hoc method is assumed to be a bit
438
+ # dirty sometimes, meaning we may find more than just the
439
+ # <a> tag used.
440
+ #
441
+ # Usage example and expected input and output:
442
+ #
443
+ # x = '<a href="https://www.youtube.com/watch?v=WxhjElaBRhE" id="our_id" onclick="change_the_colour_to()">'
444
+ # Cyberweb.insert_target_blank_onto_this(x)
445
+ # puts x
333
446
  #
334
- # This method can be used to display the content of a String in a
335
- # .cgi page.
447
+ # ========================================================================= #
448
+ def self.insert_target_blank_onto_this(i)
449
+ add_this = ' target="_blank"' # This is the String that we will add.
450
+ original_input = i.dup # This is our original input as-is.
451
+ work_on_a_copy = i.dup
452
+ if original_input.include?('>') # In this case we have dirty input.
453
+ splitted = original_input.split(/>/, 2)
454
+ first_element = splitted.first
455
+ # ===================================================================== #
456
+ # Find the last position of the ' ' character.
457
+ # ===================================================================== #
458
+ last_index = first_element.rindex(' ')
459
+ first_element[last_index, 0] = add_this
460
+ work_on_a_copy = splitted.join('>')
461
+ else
462
+ # ===================================================================== #
463
+ # Find the last position of the ' ' character.
464
+ # ===================================================================== #
465
+ last_index = original_input.rindex(' ')
466
+ work_on_a_copy[last_index, 0] = add_this
467
+ end
468
+ i.replace(work_on_a_copy)
469
+ return work_on_a_copy # And return it, just in case.
470
+ end
471
+
472
+ # ========================================================================= #
473
+ # === print_html_start
474
+ # ========================================================================= #
475
+ def print_html_start
476
+ ee return_html_start
477
+ end
478
+
479
+ # ========================================================================= #
480
+ # === Cyberweb.generate_simple_webpage
481
+ #
482
+ # This ad-hoc method will just generate a .html page with all images
483
+ # in this directory.
484
+ # ========================================================================= #
485
+ def self.generate_simple_webpage(
486
+ from_this_directory = Dir.pwd
487
+ )
488
+ require 'cyberweb/toplevel_methods/images.rb'
489
+ all_images = Dir["#{from_this_directory}/*"].select {|entry|
490
+ File.file?(entry) and is_this_an_image?(entry)
491
+ }
492
+ _ = "<html><head><title>Simple Webpage</title></head><body><div>\n\n".dup
493
+ _ << "<h2>All the images</h2>\n"
494
+ all_images.each {|this_image|
495
+ basename = File.basename(this_image)
496
+ _ << '<img src="'+basename+'" alt="'+basename.downcase+'">'+"\n"
497
+ }
498
+ _ << '</div></body></html>'
499
+ what = _
500
+ into = 'simple_webpage.html'
501
+ puts "Creating the file #{into} next."
502
+ write_what_into(what, into)
503
+ if is_on_roebe?
504
+ require 'open'
505
+ Open.in_browser(into)
506
+ end
507
+ end
508
+
509
+ # ========================================================================= #
510
+ # === Cyberweb.html_comment
511
+ #
512
+ # Make use of a html-comment here.
513
+ #
514
+ # Since as of June 2021 it will append a newline by default.
515
+ # ========================================================================= #
516
+ def self.html_comment(
517
+ i,
518
+ make_newline = true
519
+ )
520
+ _ = "<!-- #{i.to_s.rstrip} -->".dup
521
+ _ << N if make_newline
522
+ _
523
+ end; self.instance_eval { alias return_html_comment html_comment } # === Cyberweb.return_html_comment
524
+
525
+ # ========================================================================= #
526
+ # === glob
527
+ # ========================================================================= #
528
+ def glob(i)
529
+ ::Cyberweb.glob(i) # We need to scope via :: here.
530
+ end
531
+
532
+ # ========================================================================= #
533
+ # === Cyberweb.create_directory
534
+ #
535
+ # Consistently use this method if you want to create a directory.
536
+ # So far this is only used in the file img.rb
537
+ # ========================================================================= #
538
+ def self.create_directory(d)
539
+ Dir.mkdir(d)
540
+ end
541
+
542
+ # ========================================================================= #
543
+ # === Cyberweb.return_this_file
544
+ #
545
+ # This method can be used to display the content of a String in a
546
+ # .cgi page.
336
547
  # ========================================================================= #
337
548
  def self.return_this_file(
338
549
  this_file = :gtk
@@ -366,172 +577,354 @@ input[type=number]::-webkit-inner-spin-button {
366
577
  end
367
578
 
368
579
  # ========================================================================= #
369
- # === Cyberweb.sanitize_this_string_by_adding_a_newline_after_every_closing_HTML_tag
370
- #
371
- # The following method is an ad-hoc method - I needed to sanitize a remote
372
- # String coming from a .html page that removed all newlines. Ideally this
373
- # should be a regex, but for now we just chop away on '>'.
580
+ # === Cyberweb.download_webpage
374
581
  #
375
- # If a file is given as argument then its content will be read.
582
+ # The argument to this method should be a remote website.
376
583
  #
377
- # Usage example for a local .html file:
584
+ # Usage example:
378
585
  #
379
- # x = Cyberweb.sanitize_this_string_by_adding_a_newline_after_every_closing_HTML_tag('/Depot/j/foobar.html')
586
+ # Cyberweb.download_webpage('https://www.cardmarket.com/en/Magic/Orders/Sales/ShoppingCart')
587
+ # x = Cyberweb.download_webpage('https://www.cardmarket.com/en/Magic/Orders/Sales/ShoppingCart', { http_basic_authentication: ['shev55y@inbox.ar', 'JJJieie33aeeeggkhlhgejk7878eKIEUIbeue'] })
380
588
  #
381
589
  # ========================================================================= #
382
- def self.sanitize_this_string_by_adding_a_newline_after_every_closing_HTML_tag(
383
- i = ARGV
590
+ def self.download_webpage(
591
+ remote_URL = ARGV,
592
+ options = {}
384
593
  )
385
- if i.is_a? Array
386
- i = i.join(' ').strip
594
+ require 'cyberweb/coloured_tags/coloured_tags.rb'
595
+ require 'open-uri'
596
+ if remote_URL.is_a? Array
597
+ remote_URL = remote_URL.first
387
598
  end
388
- if i and File.file?(i)
389
- i = File.read(i) # Add support for existing files here.^
599
+ if options and options.is_a?(Hash) and options.has_key?(:http_basic_authentication)
600
+ what = URI.open(remote_URL, options[:http_basic_authentication]).read
601
+ else
602
+ what = URI.open(remote_URL).read
390
603
  end
391
- return i.gsub(/>/, ">\n")
392
- end; self.instance_eval { alias sanitizer sanitize_this_string_by_adding_a_newline_after_every_closing_HTML_tag } # === Cyberweb.sanitizer
604
+ remote_extension = File.extname(remote_URL)
605
+ into = File.basename(remote_URL).dup
606
+ into << remote_extension unless into.end_with?(remote_extension)
607
+ # ======================================================================= #
608
+ # === Handle blocks next
609
+ # ======================================================================= #
610
+ if block_given?
611
+ yielded = yield
612
+ case yielded
613
+ # ===================================================================== #
614
+ # === :be_verbose
615
+ # ===================================================================== #
616
+ when :be_verbose
617
+ puts 'Now downloading from `'+
618
+ ::Colours.steelblue(remote_URL)+
619
+ '` into `'+
620
+ ::Colours.royalblue(into)+'`.'
621
+ end
622
+ end
623
+ # ======================================================================= #
624
+ # Save the content into a file next.
625
+ # ======================================================================= #
626
+ write_what_into(what, into)
627
+ # ======================================================================= #
628
+ # And return the string and the filename that was just downloaded
629
+ # as well, as Array.
630
+ # ======================================================================= #
631
+ return [what, into]
632
+ end
393
633
 
394
634
  # ========================================================================= #
395
- # === Cyberweb.display_this_file
635
+ # === Cyberweb.cgi_header?
636
+ #
637
+ # This method will return a proper CGI header, for use in .cgi files.
396
638
  # ========================================================================= #
397
- def self.display_this_file(
398
- this_file = :gtk
639
+ def self.cgi_header?(
640
+ content_type = 'text/html;'
399
641
  )
400
- print return_this_file(this_file)
642
+ "Content-Type: #{content_type}#{EOL}"+
643
+ Cyberweb.return_utf_charset
401
644
  end
402
645
 
403
- require 'cyberweb/toplevel_methods/process_content.rb'
646
+ # ========================================================================= #
647
+ # === Cyberweb.return_program_name
648
+ # ========================================================================= #
649
+ def self.return_program_name(i)
650
+ return File.basename($PROGRAM_NAME)
651
+ end
404
652
 
405
653
  # ========================================================================= #
406
- # === Cyberweb.string_content
654
+ # === Cyberweb.return_utf_charset (utf tag)
407
655
  #
408
- # This method normally only returns a string, however since as of
409
- # 26.03.2008 we also process the input via process_content()
656
+ # Return the proper UTF charset in the header. Note that UTF-8 is the
657
+ # default charset for HTML5.
410
658
  #
411
- # Since 13.09.2008 we no longer use +NL here.
659
+ # This would return the string '<meta charset="UTF-8">'.
660
+ #
661
+ # Note that CSS can also use an encoding charset, via something
662
+ # like:
663
+ #
664
+ # @charset "UTF-8";
412
665
  #
413
- # If the input contains the special constant SPACE then we will replace
414
- # this with new lines.
415
666
  # ========================================================================= #
416
- def self.string_content(i)
417
- i = i.to_s.dup # Need to work on a copy.
418
- i.gsub!(/SPACE/,'&nbsp;') if i.include? 'SPACE'
419
- return ::Cyberweb.process_content(i)
420
- end; self.instance_eval { alias string_cont string_content } # === Cyberweb.string_cont
667
+ def self.return_utf_charset
668
+ "<meta charset=\"UTF-8\">#{NL}"
669
+ end; self.instance_eval { alias return_utf return_utf_charset } # === Cyberweb.return_utf
670
+ self.instance_eval { alias return_unicode_meta return_utf_charset } # === Cyberweb.return_unicode_meta
421
671
 
422
672
  # ========================================================================= #
423
- # === string_cont
673
+ # === return_iso_8859_charset
424
674
  # ========================================================================= #
425
- def string_cont(i)
426
- ::Cyberweb.string_cont(i)
427
- end; alias string_content string_cont # === string_content
675
+ def return_iso_8859_charset
676
+ ::Cyberweb.return_iso_8859_charset
677
+ end; alias return_iso return_iso_8859_charset # === return_iso
678
+ alias return_iso_encoding return_iso_8859_charset # === return_iso_encoding
428
679
 
429
680
  # ========================================================================= #
430
- # === Cyberweb.return_meta_collection
681
+ # === Cyberweb.return_iso_8859_charset (iso tag)
682
+ # ========================================================================= #
683
+ def self.return_iso_8859_charset
684
+ "<meta charset=\"ISO-8859-1\">#{NL}"
685
+ end; self.instance_eval { alias return_iso return_iso_8859_charset } # === Cyberweb.return_iso
686
+ self.instance_eval { alias return_iso_encoding return_iso_8859_charset } # === Cyberweb.return_iso_encoding
687
+
688
+ # ========================================================================= #
689
+ # === Cyberweb.view_source
690
+ #
691
+ # Use this method to have a little formular with a button to view the
692
+ # source code on a webpage.
693
+ #
694
+ # Note that since as of July 2011 a new convention is used here - you
695
+ # can use the input class "view_source" to modify the CSS within
696
+ # the input html.
697
+ #
698
+ # Usage example:
699
+ #
700
+ # div { view_source }
431
701
  #
432
- # Which charset and content type to use can be controlled via this
433
- # method here.
434
702
  # ========================================================================= #
435
- def self.return_meta_collection(
436
- use_this_charset = 'UTF-8'
703
+ def self.view_source(
704
+ css_class = 'wid25',
705
+ optional_id = 'view_source',
706
+ optional_css_style = ''
437
707
  )
438
- _ = ''.dup
439
- # if is_html5?
440
- # _ << return_iso_8859_charset
441
- # else
442
- case use_this_charset
443
- # ======================================================================= #
444
- # === :default
445
- # ======================================================================= #
446
- when :default,
447
- nil # Nil is also implying the default charset.
448
- use_this_charset = 'UTF-8'
449
- end
450
- case use_this_charset.downcase # We work on a downcased variant here.
451
- when 'utf-8',
452
- 'utf',
453
- 'default'
454
- _ << return_utf_charset
455
- when 'iso'
456
- _ << return_iso_encoding
457
- else # Else use a specific charset.
458
- _ << '<meta http-equiv="content-type" content="text/html; charset='+use_this_charset+'" >'+NL
708
+ button_css = 'view_source BG_White Black pad2px'
709
+ if css_class.is_a? Hash
710
+ css_class = css_class.delete :css_class
459
711
  end
460
- # ======================================================================= #
461
- # Annoy the hell out of robots:
462
- # ======================================================================= #
463
- _ << '<meta name="robots" content="noindex,nofollow,noarchive,noimageindex">'+NL
464
- return _ # Return that string finally.
465
- end
712
+ form '', '', '', optional_id, optional_css_style
713
+ ee '<input class="'+button_css+' '+css_class+'" type="button" value="View Source" '
714
+ ee 'onClick=\'window.location = "view-source:"+window.location.href\'>'
715
+ cform
716
+ end; self.instance_eval { alias vsource view_source } # === Cyberweb.vsource
466
717
 
467
718
  # ========================================================================= #
468
- # === return_meta_collection
719
+ # === view_source
469
720
  # ========================================================================= #
470
- def return_meta_collection(
471
- i = 'UTF-8'
721
+ def view_source(
722
+ a = 'wid25',
723
+ b = 'view_source',
724
+ c = ''
472
725
  )
473
- ::Cyberweb.return_meta_collection(i)
474
- end
726
+ ::Cyberweb.view_source(a,b,c)
727
+ end; alias vsource view_source # === vsource
475
728
 
476
729
  # ========================================================================= #
477
- # === Cyberweb.html_colours?
730
+ # === Cyberweb.random_favicon
478
731
  # ========================================================================= #
479
- def self.html_colours?
480
- ::Colours.html_colours?
481
- end; self.instance_eval { alias array_all_html_colours? html_colours? } # === Cyberweb.array_all_html_colours?
482
-
732
+ def self.random_favicon
733
+ ::Cyberweb::WebImages.random.gsub(
734
+ /\/home\/x\/data\/images\//, ''
735
+ )
736
+ end
737
+
483
738
  # ========================================================================= #
484
- # === is_html5?
739
+ # === Cyberweb.spacer (spacer tag, liner tag)
740
+ #
741
+ # This method will create a little spacer icon.
742
+ #
743
+ # The first argument to this method will tell us which alignment to
744
+ # use. Possible main values for this are: :middle, :left and :right.
745
+ #
746
+ # If we pass a string, then we will assume that the user wants to
747
+ # repeat this as the main token instead.
748
+ #
749
+ # You can also use it in block form as well, as in:
750
+ #
751
+ # spacer { div('s1em') { p { 'Hello World' } } }
752
+ #
485
753
  # ========================================================================= #
486
- def is_html5?
487
- ::Cyberweb.is_html5?
754
+ def self.spacer(
755
+ alignment = :middle, # Possible values are: :left, :middle, :right
756
+ extra_css_class = ''
757
+ )
758
+ use_image_spacer = true
759
+ case alignment
760
+ # ======================================================================= #
761
+ # === :center
762
+ # ======================================================================= #
763
+ when :center,
764
+ :middle,
765
+ :m,
766
+ :default,
767
+ ''
768
+ alignment = 'margin-left:auto; margin-right:auto; text-align: center;'
769
+ # ======================================================================= #
770
+ # === :left
771
+ # ======================================================================= #
772
+ when :left,
773
+ :l
774
+ alignment = 'margin-left:0; margin-right:auto; text-align: left;'
775
+ # ======================================================================= #
776
+ # === :right
777
+ # ======================================================================= #
778
+ when :right,
779
+ :r
780
+ alignment = 'margin-left:auto; margin-right:0; text-align: right;'
781
+ else
782
+ use_image_spacer = false
783
+ if alignment.is_a? Hash
784
+ if alignment.has_key? :use_this_token
785
+ alignment = alignment.delete(:use_this_token)
786
+ end
787
+ end
788
+ end
789
+ if use_image_spacer
790
+ ::Cyberweb.simg(
791
+ :spacer,
792
+ 'marb4px BLOCK '+extra_css_class,
793
+ '',
794
+ alignment
795
+ )
796
+ else
797
+ e alignment * 250
798
+ end
799
+ if block_given?
800
+ yield
801
+ if use_image_spacer
802
+ ::Cyberweb.img(
803
+ :spacer,
804
+ 'marb4px BLOCK '+extra_css_class,
805
+ '',
806
+ alignment # And repeat.
807
+ )
808
+ n
809
+ else
810
+ e alignment * 250
811
+ end
812
+ end
488
813
  end
489
814
 
490
815
  # ========================================================================= #
491
- # === Cyberweb.insert_target_blank_onto_this
492
- #
493
- # This is an ad-hoc method - I needed to add the substring
494
- # 'target="_blank"' to a HTML href hyperlink, a <a> tag. Note
495
- # that input to this ad-hoc method is assumed to be a bit
496
- # dirty sometimes, meaning we may find more than just the
497
- # <a> tag used.
816
+ # === spacer
817
+ # ========================================================================= #
818
+ def spacer(
819
+ alignment = :middle,
820
+ extra_css_class = ''
821
+ )
822
+ "#{::Cyberweb.spacer(alignment, extra_css_class)}#{N}"
823
+ end; alias trenner spacer # === trenner
824
+ alias spalter spacer # === spalter
825
+ alias space spacer # === space
826
+ alias beautiful_spacer spacer # === beautiful_spacer
827
+ alias spacer_center spacer # === spacer_center
828
+
829
+ # ========================================================================= #
830
+ # === lspacer
498
831
  #
499
- # Usage example and expected input and output:
832
+ # Wrapper towards spacer().
833
+ # ========================================================================= #
834
+ def lspacer(css = '')
835
+ spacer :left, css
836
+ end
837
+
838
+ # ========================================================================= #
839
+ # === rspacer
500
840
  #
501
- # x = '<a href="https://www.youtube.com/watch?v=WxhjElaBRhE" id="our_id" onclick="change_the_colour_to()">'
502
- # Cyberweb.insert_target_blank_onto_this(x)
503
- # puts x
841
+ # Wrapper towards spacer().
842
+ # ========================================================================= #
843
+ def rspacer(css = '')
844
+ spacer :right, css
845
+ end
846
+
847
+ # ========================================================================= #
848
+ # === Cyberweb.show_sys_info
504
849
  #
850
+ # This is the method that creates a sys-info app.
505
851
  # ========================================================================= #
506
- def self.insert_target_blank_onto_this(i)
507
- add_this = ' target="_blank"' # This is the String that we will add.
508
- original_input = i.dup # This is our original input as-is.
509
- work_on_a_copy = i.dup
510
- if original_input.include?('>') # In this case we have dirty input.
511
- splitted = original_input.split(/>/, 2)
512
- first_element = splitted.first
852
+ def self.show_sys_info
853
+ processes = `ps aux` # This may yield an US-ASCII encoded String.
854
+ # ======================================================================= #
855
+ # === Convert to the main encoding next:
856
+ # ======================================================================= #
857
+ case processes.encoding.to_s
858
+ when 'US-ASCII'
859
+ processes = processes.force_encoding(main_encoding?)
860
+ end
861
+ processes = processes.split(/\n/) if processes.is_a? String
862
+ processes.map { |proc| proc.split(/\s+/, 11).join(' | ') }
863
+ div('mars1em FS0_9em') {
864
+ div_blue {
865
+ h2 "Ruby Version: #{RUBY_VERSION}",
866
+ 'mar0px bold'
867
+ }
868
+ div {
869
+ sysinfo_header 'Environment'
870
+ div('s1em') { ENV.each { |key,value|
871
+ e "<b>#{key}</b>: #{value}" unless value.empty?
872
+ }
873
+ }
874
+ }
513
875
  # ===================================================================== #
514
- # Find the last position of the ' ' character.
876
+ # Environment Information
515
877
  # ===================================================================== #
516
- last_index = first_element.rindex(' ')
517
- first_element[last_index, 0] = add_this
518
- work_on_a_copy = splitted.join('>')
519
- else
878
+ sysinfo_header 'Environment Information'
879
+ begin
880
+ require 'environment_information'
881
+ rescue LoadError; end
882
+ _ = EnvironmentInformation.new(:do_not_run_yet) { :do_not_use_rbt }
883
+ _.set_n_tokens 68
884
+ _.disable_colours
885
+ _.be_silent
886
+ _.run
887
+ e 'Your System has the following characteristics:'
888
+ pre _.string
520
889
  # ===================================================================== #
521
- # Find the last position of the ' ' character.
890
+ # Hardware Information
522
891
  # ===================================================================== #
523
- last_index = original_input.rindex(' ')
524
- work_on_a_copy[last_index, 0] = add_this
525
- end
526
- i.replace(work_on_a_copy)
527
- return work_on_a_copy # And return it, just in case.
528
- end
892
+ sysinfo_header 'Hardware Information'
893
+ _ = HardwareInformation.new(false)
894
+ _.set_web_mode
895
+ _.disable_colours
896
+ _.run
897
+ pre _.string
898
+ my_title = %(Processes running on #{ENV['SERVER_NAME'] || `hostname`.strip})
899
+ h2 sg(:red_dot,'marr5px')+my_title
900
+ div('mars1em') {
901
+ h3 'Showing Process Information next', 'yel'
902
+ e htmlentities( processes.join("\n") ).gsub!( /\n/,"<br>\n" )
903
+ }
904
+ sysinfo_header 'Time and Date'
905
+ display_date
906
+ display_time :ruby
907
+ }
908
+ end; self.instance_eval { alias rubyinfo show_sys_info } # === Cyberweb.rubyinfo
909
+ self.instance_eval { alias display_system_information show_sys_info } # === Cyberweb.display_system_information
529
910
 
530
911
  # ========================================================================= #
531
- # === print_html_start
912
+ # === show_sys_info
532
913
  # ========================================================================= #
533
- def print_html_start
534
- ee return_html_start
914
+ def show_sys_info
915
+ ::Cyberweb.show_sys_info
916
+ end; alias rubyinfo show_sys_info # === rubyinfo
917
+ alias display_system_information show_sys_info # === display_system_information
918
+
919
+ # ========================================================================= #
920
+ # === random_image
921
+ #
922
+ # This method will return a random image.
923
+ # ========================================================================= #
924
+ def random_image
925
+ string_img(
926
+ ::Cyberweb::ARRAY_LISTING_ALL_PROJECT_IMAGES.sample
927
+ )
535
928
  end
536
929
 
537
930
  # ========================================================================= #
@@ -591,109 +984,6 @@ input[type=number]::-webkit-inner-spin-button {
591
984
  ee CONTENT_TYPE_PLAIN
592
985
  end
593
986
 
594
- # ========================================================================= #
595
- # === output_response_header
596
- # ========================================================================= #
597
- def output_response_header
598
- ee HTTP_RESPONSE_HEADER
599
- end
600
-
601
- # ========================================================================= #
602
- # === Cyberweb.generate_simple_webpage
603
- #
604
- # This ad-hoc method will just generate a .html page with all images
605
- # in this directory.
606
- # ========================================================================= #
607
- def self.generate_simple_webpage(
608
- from_this_directory = Dir.pwd
609
- )
610
- require 'cyberweb/toplevel_methods/images.rb'
611
- all_images = Dir["#{from_this_directory}/*"].select {|entry|
612
- File.file?(entry) and is_this_an_image?(entry)
613
- }
614
- _ = "<html><head><title>Simple Webpage</title></head><body><div>\n\n".dup
615
- _ << "<h2>All the images</h2>\n"
616
- all_images.each {|this_image|
617
- basename = File.basename(this_image)
618
- _ << '<img src="'+basename+'" alt="'+basename.downcase+'">'+"\n"
619
- }
620
- _ << '</div></body></html>'
621
- what = _
622
- into = 'simple_webpage.html'
623
- puts 'Creating the file '+into+' next.'
624
- write_what_into(what, into)
625
- if is_on_roebe?
626
- require 'open'
627
- Open.in_browser(into)
628
- end
629
- end
630
-
631
- # ========================================================================= #
632
- # === Cyberweb.random_favicon
633
- # ========================================================================= #
634
- def self.random_favicon
635
- ::Cyberweb::WebImages.random.gsub(
636
- /\/home\/x\/data\/images\//, ''
637
- )
638
- end
639
-
640
- # ========================================================================= #
641
- # === Cyberweb.return_meta_redirect
642
- #
643
- # You may use this method to meta-redirect html pages.
644
- # ========================================================================= #
645
- def self.return_meta_redirect(
646
- to_this_url
647
- )
648
- '<meta http-equiv="Refresh" content="1; URL="'+to_this_url.to_s+'">'
649
- end
650
-
651
- # ========================================================================= #
652
- # === return_meta_redirect
653
- #
654
- # You may use this to meta-redirect html pages.
655
- # ========================================================================= #
656
- def return_meta_redirect(to_this_url)
657
- Cyberweb.return_meta_redirect(to_this_url)
658
- end
659
-
660
- # ========================================================================= #
661
- # === Cyberweb.string_body_start (body tag)
662
- #
663
- # Just start of <body>
664
- # ========================================================================= #
665
- def self.string_body_start(
666
- css_class = '',
667
- the_id = '',
668
- css_style = '',
669
- javascript_onload = ''
670
- )
671
- # ======================================================================= #
672
- # === Overrule empty IDs
673
- #
674
- # Overrule empty id by defining an id for the body set. By default
675
- # in this case, it will be set to the name of the page in question.
676
- #
677
- # This is already done in the id_method so here we can simply set
678
- # the id to 'DEF'.
679
- # ======================================================================= #
680
- the_id = 'DEF' if the_id.empty?
681
- # delete if it is only 2 chars
682
- javascript = '' if javascript == 'js'
683
- _ = '<body'.dup
684
- _ << ::Cyberweb.return_css_class(css_class)
685
- _ << ::Cyberweb.return_the_id(the_id)
686
- _ << ::Cyberweb.return_css_style(css_style)
687
- unless javascript_onload.empty?
688
- _ << ' onload="'
689
- _ << javascript_onload
690
- _ << ';' unless _.end_with? ';'
691
- _ << '"'
692
- end
693
- _ << '>'+NL # closing tag
694
- return _
695
- end
696
-
697
987
  # ========================================================================= #
698
988
  # === body_start
699
989
  #
@@ -714,43 +1004,6 @@ input[type=number]::-webkit-inner-spin-button {
714
1004
  )
715
1005
  end
716
1006
 
717
- # ========================================================================= #
718
- # === Cyberweb.right_arrow
719
- # ========================================================================= #
720
- def self.right_arrow
721
- '&rarr;'
722
- end
723
-
724
- # ========================================================================= #
725
- # === Cyberweb.bruch
726
- #
727
- # This is a "bruch", aka a fraction. It is written in german mostly because
728
- # I am quite lazy.
729
- # ========================================================================= #
730
- def self.bruch(a, b)
731
- return "<sup>#{a}</sup>/<sub>#{b}</sub>"
732
- end
733
-
734
- # ========================================================================= #
735
- # === Cyberweb.dropdown_box
736
- #
737
- # This method will generate a <select><option> listing, a drop-down
738
- # interface. The input to this method must be an Array.
739
- # ========================================================================= #
740
- def self.dropdown_box(i)
741
- if i.is_a? Array # Ok.
742
- _ = '<select>'.dup
743
- i.each {|line|
744
- _ << string_option(line)
745
- }
746
- _ << string_close(:select)
747
- return _ # And return the result here.
748
- else
749
- raise 'The method dropdown_box() requires an Array as argument.'
750
- end
751
- end; self.instance_eval { alias www_dropdown_box dropdown_box } # === Cyberweb.www_dropdown_box
752
- self.instance_eval { alias html_dropdown_box dropdown_box } # === Cyberweb.html_dropdown_box
753
-
754
1007
  # ========================================================================= #
755
1008
  # === Cyberweb.return_the_name
756
1009
  #
@@ -816,133 +1069,21 @@ input[type=number]::-webkit-inner-spin-button {
816
1069
  end
817
1070
 
818
1071
  # ========================================================================= #
819
- # === Cyberweb.edit_configuration_file
820
- #
821
- # This method allows you to edit configuration files.
1072
+ # === Cyberweb.file_amusement_park
822
1073
  # ========================================================================= #
823
- def self.edit_configuration_file(
824
- use_this_editor = 'vim'
825
- )
826
- _ = configuration_file?
827
- puts 'Next using vim to edit'; puts
828
- puts " #{_}"
829
- puts
830
- system "#{use_this_editor} #{_}"
1074
+ def self.file_amusement_park
1075
+ "#{Cyberweb.project_base_directory?}svg/standalone/amusement_park.svg"
831
1076
  end
832
1077
 
833
1078
  # ========================================================================= #
834
- # === Cyberweb.path_to_the_internal_javascript_directory?
1079
+ # === Cyberweb.restore_stdout
1080
+ #
1081
+ # Restore normal output again through this method.
835
1082
  # ========================================================================= #
836
- def self.path_to_the_internal_javascript_directory?
837
- return "#{Cyberweb.project_base_directory?}javascript_code/"
838
- end
839
-
840
- # ========================================================================= #
841
- # === Cyberweb.return_html_code_for_the_javascript_calculator
842
- #
843
- # This is the method that will return the table that, in turn, shall
844
- # simulate a javascript-calculator.
845
- # ========================================================================= #
846
- def self.return_html_code_for_the_javascript_calculator(
847
- optional_css_class_to_use = ''
848
- )
849
- return '<table id="simple_javascript_calculator" style="border: 1px solid black" class="'+optional_css_class_to_use.to_s+'">
850
- <tr>
851
- <td align="center">
852
- <input type="text" ID="screen_for_the_simple_javascript_calculator" NAME="screen" style="width:95%; font-size: 30px"><br/>
853
- </td>
854
- </tr>
855
- <tr>
856
- <td>
857
- <input class="input_for_the_calculator" type="button" NAME="7" VALUE=" 7 " onclick="updateTextbox(7)">
858
- <input class="input_for_the_calculator" type="button" NAME="8" VALUE=" 8 " onclick="updateTextbox(8)">
859
- <input class="input_for_the_calculator" type="button" NAME="9" VALUE=" 9 " onclick="updateTextbox(9)">
860
- <input class="input_for_the_calculator" type="button" NAME="+" VALUE=" + " onclick="updateTextbox(\'+\')">
861
- <br>
862
- <input class="input_for_the_calculator" type="button" NAME="4" VALUE=" 4 " onclick="updateTextbox(4)">
863
- <input class="input_for_the_calculator" type="button" NAME="5" VALUE=" 5 " onclick="updateTextbox(5)">
864
- <input class="input_for_the_calculator" type="button" NAME="6" VALUE=" 6 " onclick="updateTextbox(6)">
865
- <input class="input_for_the_calculator" type="button" NAME="-" VALUE=" - " onclick="updateTextbox(\'-\')">
866
- <br>
867
- <input class="input_for_the_calculator" type="button" NAME="1" VALUE=" 1 " onclick="updateTextbox(1)">
868
- <input class="input_for_the_calculator" type="button" NAME="2" VALUE=" 2 " onclick="updateTextbox(2)">
869
- <input class="input_for_the_calculator" type="button" NAME="3" VALUE=" 3 " onclick="updateTextbox(3)">
870
- <input class="input_for_the_calculator" type="button" NAME="*" VALUE=" x " onclick="updateTextbox(\'*\')">
871
- <br>
872
- <input class="input_for_the_calculator" type="button" NAME="c" VALUE=" c " onclick="reset();">
873
- <input class="input_for_the_calculator" type="button" NAME="0" VALUE=" 0 " onclick="updateTextbox(0)">
874
- <input class="input_for_the_calculator" type="button" NAME="=" VALUE=" = " onclick="result();">
875
- <input class="input_for_the_calculator" type="button" NAME="/" VALUE=" / " onclick="updateTextbox(\'/\')">
876
- </td>
877
- </tr>
878
- </table>'
879
- end
880
-
881
- # ========================================================================= #
882
- # === Cyberweb.translate_html_string_into_webobject_string
883
- # ========================================================================= #
884
- def self.translate_html_string_into_webobject_string(
885
- i =
886
- '<div>
887
- <h2>Hello world!</h2>
888
-
889
- <p>This is the first paragraph.</p>
890
-
891
- <p>This is the second paragraph. It includes a bit of HTML
892
- and <b>newlines</b>.</p>
893
-
894
- </div>'
895
- )
896
- do_more_parsing = true
897
- result = ''.dup
898
- splitted = i.split("\n")
899
- splitted.each {|this_line|
900
- if this_line.include?('<') and this_line.include?('>')
901
- if do_more_parsing
902
- all_html_tags_in_this_line = return_all_html_tags_in_this_line(this_line)
903
- first_tag = all_html_tags_in_this_line.first
904
- result << first_tag.delete('<>')+" {\n"
905
- result << "ee '"
906
- else
907
- result << this_line
908
- end
909
- do_more_parsing = false
910
- end
911
- }
912
- result << "'\n}\n"
913
- return result
914
- end
915
-
916
- # ========================================================================= #
917
- # === Cyberweb.remove_html
918
- #
919
- # This method will attempt to get rid of all html found in a String.
920
- # ========================================================================= #
921
- def self.remove_html(i)
922
- if Object.const_defined?(:Roebe) and
923
- Roebe.respond_to?(:remove_html)
924
- return Roebe.remove_html(i)
925
- else
926
- i # Else return it unmodified.
927
- end
928
- end
929
-
930
- # ========================================================================= #
931
- # === Cyberweb.file_amusement_park
932
- # ========================================================================= #
933
- def self.file_amusement_park
934
- "#{Cyberweb.project_base_directory?}svg/standalone/amusement_park.svg"
935
- end
936
-
937
- # ========================================================================= #
938
- # === Cyberweb.restore_stdout
939
- #
940
- # Restore normal output again through this method.
941
- # ========================================================================= #
942
- def self.restore_stdout
943
- $stdout = STDOUT
944
- end; self.instance_eval { alias cleanup restore_stdout } # === Cyberweb.cleanup
945
- self.instance_eval { alias restore restore_stdout } # === Cyberweb.restore
1083
+ def self.restore_stdout
1084
+ $stdout = STDOUT
1085
+ end; self.instance_eval { alias cleanup restore_stdout } # === Cyberweb.cleanup
1086
+ self.instance_eval { alias restore restore_stdout } # === Cyberweb.restore
946
1087
 
947
1088
  # ========================================================================= #
948
1089
  # === Cyberweb.draw_triangle
@@ -1160,315 +1301,117 @@ and <b>newlines</b>.</p>
1160
1301
  end; self.instance_eval { alias return_title_of_this_webpage return_title_of_this_remote_webpage } # === Cyberweb.return_title_of_this_webpage
1161
1302
 
1162
1303
  # ========================================================================= #
1163
- # === Cyberweb.convert_image_to_base64
1304
+ # === Cyberweb.try_to_open_this_URL_via_the_browser
1305
+ #
1306
+ # This method simplifies working with Sinatra. The main use case for
1307
+ # this method is to show the localhost-URL, and then open this in
1308
+ # the browser directly, via the "open" gem.
1309
+ #
1310
+ # The second argument specifies which port is to be used.
1164
1311
  #
1165
1312
  # Usage example:
1166
1313
  #
1167
- # Cyberweb.convert_image_to_base64("/home/x/programming/ruby/src/cyberweb/images/cyberweb_logo.png")
1314
+ # Cyberweb.try_to_open_this_URL_via_the_browser(target, USE_THIS_PORT)
1168
1315
  #
1169
1316
  # ========================================================================= #
1170
- def self.convert_image_to_base64(this_image)
1171
- file_type = File.extname(this_image).delete('.').upcase
1172
- return `magick #{this_image} #{file_type}:- | base64`
1317
+ def self.try_to_open_this_URL_via_the_browser(
1318
+ target,
1319
+ use_this_port = '4567'
1320
+ )
1321
+ begin
1322
+ require 'open' # Pull in the gem called "open" here.
1323
+ if use_this_port # Avoid nil and false values.
1324
+ target = "http://localhost:#{use_this_port}/"
1325
+ if block_given? and (yield == :be_quiet)
1326
+ else
1327
+ puts ::Colours.sfancy(target)
1328
+ end
1329
+ Thread.new {
1330
+ Open.in_browser(target) {{ delay: '1.0 seconds' }}
1331
+ }
1332
+ end
1333
+ rescue LoadError => error
1334
+ pp error
1335
+ end
1173
1336
  end
1174
1337
 
1175
1338
  # ========================================================================= #
1176
- # === Cyberweb.return_all_html_tags_in_this_line
1339
+ # === get_ip
1340
+ #
1341
+ # This returns the ip.
1177
1342
  # ========================================================================= #
1178
- def self.return_all_html_tags_in_this_line(
1179
- i = '<p>This <a> <div><h2>ok </h2>'
1180
- )
1181
- array = []
1182
- if i.include? '<'
1183
- regex = /(<.+?>)/
1184
- array << i.scan(regex)
1185
- end
1186
- return array.flatten
1343
+ def get_ip
1344
+ ENV['REMOTE_ADDR']
1187
1345
  end
1188
1346
 
1189
1347
  # ========================================================================= #
1190
- # === Cyberweb.logo?
1348
+ # === n
1191
1349
  #
1192
- # This method will return the path to the currently used Cyberweb logo.
1350
+ # This method will simply print a newline (ee is aliased to print).
1351
+ # ========================================================================= #
1352
+ def n
1353
+ ee N
1354
+ end unless defined? n
1355
+
1356
+ # ========================================================================= #
1357
+ # === remove_html_tags (no html tags)
1193
1358
  #
1194
- # This method may return a String such as:
1359
+ # This method will simply remove all html tags from a string.
1195
1360
  #
1196
- # /home/x/programming/ruby/src/cyberweb/images/cyberweb_logo.png
1361
+ # We will make use of project RemoveHtml for this task, which
1362
+ # will be used through Cyberweb.remove_html().
1363
+ #
1364
+ # Usage example:
1365
+ #
1366
+ # Cyberweb.remove_html_tags("<span>foobar</span><br><b>test</b>")
1367
+ # "<span>foobar</span><b>test</b>".gsub(/\<.+\>/,'')
1368
+ # y = Cyberweb.remove_html_tags( x )
1369
+ # y = Cyberweb.remove_html_tags( readlines("LINUX_COMMANDS.html").join(' ') )
1370
+ # MyLogger.write_what_to(y,'/final.html')
1197
1371
  #
1198
1372
  # ========================================================================= #
1199
- def self.logo?
1200
- "#{server_base_directory?}programming/ruby/src/"\
1201
- "cybwerb/lib/cyberweb/images/cyberweb_logo.png"
1202
- end
1373
+ def remove_html_tags(input)
1374
+ ::Cyberweb.remove_html(input)
1375
+ end; alias no_html remove_html_tags # === no_html
1376
+ alias de_html remove_html_tags # === de_html
1377
+ alias strip_html remove_html_tags # === strip_html
1378
+ alias remove_html remove_html_tags # === remove_html
1203
1379
 
1204
1380
  # ========================================================================= #
1205
- # === Cyberweb.readlines
1381
+ # === pnl
1206
1382
  #
1207
- # Preferrentially use this method when you read files, because we
1208
- # will use the right encoding as we go.
1383
+ # Prints a new line.
1209
1384
  # ========================================================================= #
1210
- def self.readlines(i)
1211
- File.readlines(
1212
- i,
1213
- encoding: ::Cyberweb::Encoding::MAIN_ENCODING_TO_USE
1214
- )
1215
- end
1385
+ def pnl
1386
+ ee NL
1387
+ end; alias newline pnl # === newline
1216
1388
 
1217
1389
  # ========================================================================= #
1218
- # === readlines
1390
+ # === print_head_start
1219
1391
  # ========================================================================= #
1220
- def readlines(file)
1221
- ::Cyberweb.readlines(file)
1392
+ def print_head_start
1393
+ ee return_head_start
1222
1394
  end
1223
1395
 
1224
1396
  # ========================================================================= #
1225
- # === Cyberweb.remove_newlines
1397
+ # === print_strict_doctype
1226
1398
  #
1227
- # This simple method will get rid of newlines from the given input
1228
- # String. The argument to this method should hence be a String.
1399
+ # Print the doctype to use, by calling the method return_strict_doctype().
1229
1400
  # ========================================================================= #
1230
- def self.remove_newlines(i = '')
1231
- i.delete("\n")
1232
- end; self.instance_eval { alias remove_newline remove_newlines } # === Cyberweb.remove_newline
1233
- self.instance_eval { alias remove_newlines_from remove_newlines } # === Cyberweb.remove_newlines_from
1401
+ def print_strict_doctype
1402
+ ee return_strict_doctype
1403
+ end
1234
1404
 
1235
1405
  # ========================================================================= #
1236
- # === Cyberweb.disable_right_click
1237
- #
1238
- # This is jquery code, which can be used to disable the right-mouse button
1239
- # click. Personally I dislike it very much, but because other people may
1240
- # wish to use it, I have decided to include it as part of the cyberweb
1241
- # framework.
1242
- #
1243
- # Note that for this method to work, you must have jquery enabled prior
1244
- # to calling it, through something such as a use_jquery() directive
1245
- # or use :jquery or a similar call. Or simply set the project configuration
1246
- # setting there.
1247
- #
1248
- # Usage example:
1249
- #
1250
- # x = Cyberweb.disable_right_click(:return_it)
1406
+ # === get_all_directories_from
1251
1407
  #
1408
+ # Obtain all directories from a target path.
1252
1409
  # ========================================================================= #
1253
- def self.disable_right_click(
1254
- what_to_do_with_it = :output_it
1410
+ def get_all_directories_from(
1411
+ where = Dir.pwd,
1412
+ return_full_path = false
1255
1413
  )
1256
- result = return_javascript('$(document).ready(function(){
1257
- $(document).bind("contextmenu", function(e){
1258
- return false;
1259
- });
1260
- });'+N)
1261
- case what_to_do_with_it
1262
- # === :return
1263
- when :return,
1264
- :return_it
1265
- return result # We simple return the result in this case.
1266
- else
1267
- ee result
1268
- end
1269
- end
1270
-
1271
- # ========================================================================= #
1272
- # === disable_right_click
1273
- # ========================================================================= #
1274
- def disable_right_click
1275
- ::Cyberweb.disable_right_click
1276
- end; alias no_right_click disable_right_click # === no_right_click
1277
-
1278
- # ========================================================================= #
1279
- # === Cyberweb.colourize_ruby_code (ruby tag)
1280
- #
1281
- # Use this to colourize ruby code. Be careful when using this though and
1282
- # only use it when you (a) need it and (b) when you have ruby code in
1283
- # question.
1284
- # ========================================================================= #
1285
- def self.colourize_ruby_code(_)
1286
- _ = _.dup
1287
- _.gsub!(/class /,
1288
- '<span class="BG_Black pad1px lightgreen bold">class </span>')
1289
- _.gsub!(/require/,
1290
- '<span class="pad1px red FI bold">require</span>')
1291
- _.gsub!(/end$/,
1292
- '<span class="BG_Black pad1px red bold">end</span>')
1293
- _.gsub!(/else/,
1294
- '<span class="BG_Black pad1px red bold">else</span>')
1295
- _.gsub!(/if /,
1296
- '<span class="BG_Black pad1px red bold">if </span>')
1297
- _.gsub!(/elsif/,
1298
- '<span class="BG_Black pad1px red bold">elsif</span>')
1299
- _.gsub!(/__FILE__/,
1300
- '<span class="BG_Black pad1px pink bold">__FILE__</span>')
1301
- _.gsub!(/\$PROGRAM_NAME/,
1302
- '<span class="BG_Black pad1px lightgreen bold">$PROGRAM_NAME</span>')
1303
- _.gsub!(/class (\w+) </,'<span class="BG_Black pad1px yel bold">class</span> \\1 <')
1304
- _.gsub!(/super\(\)/,'<span class="BG_Black pad1px cyan bold">super()</span>')
1305
- _.gsub!(/#!\/System\/Executables\/ruby -w/,'<span class="BG_Black pad1px green bold">#!/System/Executables/ruby -w</span>')
1306
- _.gsub!(/def (.*)/,
1307
- '<span class="BG_Black pad1px orange bold">def </span><span class="BG_Black BO pad1px lightblue">\1</span>')
1308
- _.gsub!(/do/,
1309
- '<span class="BG_Black pad1px orange bold">do</span>')
1310
- return _
1311
- end
1312
-
1313
- # ========================================================================= #
1314
- # === Cyberweb.use_this_local_port_or_a_later_port
1315
- #
1316
- # This method can be used to scan for an open local port.
1317
- #
1318
- # It was necessary because Sinatra may often be already running
1319
- # on a localhost port.
1320
- # ========================================================================= #
1321
- def self.use_this_local_port_or_a_later_port(i = '4567')
1322
- begin
1323
- require 'roebe/toplevel_methods/open_ports.rb'
1324
- if Roebe.is_this_port_open?(i)
1325
- return i
1326
- else
1327
- # else find a fitting open port in the next 50
1328
- # ports.
1329
- upper_range = i.to_i + 50
1330
- i.to_i.upto(upper_range) {|try_this_port|
1331
- if Roebe.is_this_port_open?(try_this_port)
1332
- return try_this_port
1333
- # else # else we must continue.
1334
- # return nil
1335
- end
1336
- }
1337
- end
1338
- rescue LoadError
1339
- end
1340
- end
1341
-
1342
- # ========================================================================= #
1343
- # === Cyberweb.try_to_open_this_URL_via_the_browser
1344
- #
1345
- # This method simplifies working with Sinatra. The main use case for
1346
- # this method is to show the localhost-URL, and then open this in
1347
- # the browser directly, via the "open" gem.
1348
- #
1349
- # The second argument specifies which port is to be used.
1350
- #
1351
- # Usage example:
1352
- #
1353
- # Cyberweb.try_to_open_this_URL_via_the_browser(target, USE_THIS_PORT)
1354
- #
1355
- # ========================================================================= #
1356
- def self.try_to_open_this_URL_via_the_browser(
1357
- target,
1358
- use_this_port = '4567'
1359
- )
1360
- begin
1361
- require 'open' # Pull in the gem called "open" here.
1362
- if use_this_port # Avoid nil and false values.
1363
- target = "http://localhost:#{use_this_port}/"
1364
- if block_given? and (yield == :be_quiet)
1365
- else
1366
- puts ::Colours.sfancy(target)
1367
- end
1368
- Thread.new {
1369
- Open.in_browser(target) {{ delay: '1.0 seconds' }}
1370
- }
1371
- end
1372
- rescue LoadError => error
1373
- pp error
1374
- end
1375
- end
1376
-
1377
- # ========================================================================= #
1378
- # === Cyberweb.is_a_video_file?
1379
- #
1380
- # This method can be used to determine whether xyz is a video file or
1381
- # whether it is not.
1382
- #
1383
- # Usage example:
1384
- #
1385
- # Cyberweb.is_a_video_file?('/tmp/foobar.avi')
1386
- #
1387
- # ========================================================================= #
1388
- def self.is_a_video_file?(
1389
- this_file = 'foobar.mp4'
1390
- )
1391
- array = %w( .avi .mp4 .mkv .webm )
1392
- array.include? File.extname(this_file)
1393
- end
1394
-
1395
- # ========================================================================= #
1396
- # === get_ip
1397
- #
1398
- # This returns the ip.
1399
- # ========================================================================= #
1400
- def get_ip
1401
- ENV['REMOTE_ADDR']
1402
- end
1403
-
1404
- # ========================================================================= #
1405
- # === n
1406
- #
1407
- # This method will simply print a newline (ee is aliased to print).
1408
- # ========================================================================= #
1409
- def n
1410
- ee N
1411
- end unless defined? n
1412
-
1413
- # ========================================================================= #
1414
- # === remove_html_tags (no html tags)
1415
- #
1416
- # This method will simply remove all html tags from a string.
1417
- #
1418
- # We will make use of project RemoveHtml for this task, which
1419
- # will be used through Cyberweb.remove_html().
1420
- #
1421
- # Usage example:
1422
- #
1423
- # Cyberweb.remove_html_tags("<span>foobar</span><br><b>test</b>")
1424
- # "<span>foobar</span><b>test</b>".gsub(/\<.+\>/,'')
1425
- # y = Cyberweb.remove_html_tags( x )
1426
- # y = Cyberweb.remove_html_tags( readlines("LINUX_COMMANDS.html").join(' ') )
1427
- # MyLogger.write_what_to(y,'/final.html')
1428
- #
1429
- # ========================================================================= #
1430
- def remove_html_tags(input)
1431
- ::Cyberweb.remove_html(input)
1432
- end; alias no_html remove_html_tags # === no_html
1433
- alias de_html remove_html_tags # === de_html
1434
- alias strip_html remove_html_tags # === strip_html
1435
- alias remove_html remove_html_tags # === remove_html
1436
-
1437
- # ========================================================================= #
1438
- # === pnl
1439
- #
1440
- # Prints a new line.
1441
- # ========================================================================= #
1442
- def pnl
1443
- ee NL
1444
- end; alias newline pnl # === newline
1445
-
1446
- # ========================================================================= #
1447
- # === print_head_start
1448
- # ========================================================================= #
1449
- def print_head_start
1450
- ee return_head_start
1451
- end
1452
-
1453
- # ========================================================================= #
1454
- # === print_strict_doctype
1455
- #
1456
- # Print the doctype to use, by calling the method return_strict_doctype().
1457
- # ========================================================================= #
1458
- def print_strict_doctype
1459
- ee return_strict_doctype
1460
- end
1461
-
1462
- # ========================================================================= #
1463
- # === get_all_directories_from
1464
- #
1465
- # Obtain all directories from a target path.
1466
- # ========================================================================= #
1467
- def get_all_directories_from(
1468
- where = Dir.pwd,
1469
- return_full_path = false
1470
- )
1471
- return Dir["#{where}/*"].reject {|entry| ! File.directory? entry }
1414
+ return Dir["#{where}/*"].reject {|entry| ! File.directory? entry }
1472
1415
  end
1473
1416
 
1474
1417
  # ========================================================================= #
@@ -1885,6 +1828,697 @@ and <b>newlines</b>.</p>
1885
1828
  require COLOURED_TAGS
1886
1829
  end; load_coloured_tags
1887
1830
 
1831
+ # ========================================================================= #
1832
+ # === output_response_header
1833
+ # ========================================================================= #
1834
+ def output_response_header
1835
+ ee HTTP_RESPONSE_HEADER
1836
+ end
1837
+
1838
+ # ========================================================================= #
1839
+ # === Cyberweb.return_meta_redirect
1840
+ #
1841
+ # You may use this method to meta-redirect html pages.
1842
+ # ========================================================================= #
1843
+ def self.return_meta_redirect(
1844
+ to_this_url
1845
+ )
1846
+ '<meta http-equiv="Refresh" content="1; URL="'+to_this_url.to_s+'">'
1847
+ end
1848
+
1849
+ # ========================================================================= #
1850
+ # === return_meta_redirect
1851
+ #
1852
+ # You may use this to meta-redirect html pages.
1853
+ # ========================================================================= #
1854
+ def return_meta_redirect(to_this_url)
1855
+ Cyberweb.return_meta_redirect(to_this_url)
1856
+ end
1857
+
1858
+ # ========================================================================= #
1859
+ # === Cyberweb.string_body_start (body tag)
1860
+ #
1861
+ # Just start of <body>
1862
+ # ========================================================================= #
1863
+ def self.string_body_start(
1864
+ css_class = '',
1865
+ the_id = '',
1866
+ css_style = '',
1867
+ javascript_onload = ''
1868
+ )
1869
+ # ======================================================================= #
1870
+ # === Overrule empty IDs
1871
+ #
1872
+ # Overrule empty id by defining an id for the body set. By default
1873
+ # in this case, it will be set to the name of the page in question.
1874
+ #
1875
+ # This is already done in the id_method so here we can simply set
1876
+ # the id to 'DEF'.
1877
+ # ======================================================================= #
1878
+ the_id = 'DEF' if the_id.empty?
1879
+ # delete if it is only 2 chars
1880
+ javascript = '' if javascript == 'js'
1881
+ _ = '<body'.dup
1882
+ _ << ::Cyberweb.return_css_class(css_class)
1883
+ _ << ::Cyberweb.return_the_id(the_id)
1884
+ _ << ::Cyberweb.return_css_style(css_style)
1885
+ unless javascript_onload.empty?
1886
+ _ << ' onload="'
1887
+ _ << javascript_onload
1888
+ _ << ';' unless _.end_with? ';'
1889
+ _ << '"'
1890
+ end
1891
+ _ << '>'+NL # closing tag
1892
+ return _
1893
+ end
1894
+
1895
+ # ========================================================================= #
1896
+ # === Cyberweb.dropdown_box
1897
+ #
1898
+ # This method will generate a <select><option> listing, a drop-down
1899
+ # interface. The input to this method must be an Array.
1900
+ # ========================================================================= #
1901
+ def self.dropdown_box(i)
1902
+ if i.is_a? Array # Ok.
1903
+ _ = '<select>'.dup
1904
+ i.each {|line|
1905
+ _ << string_option(line)
1906
+ }
1907
+ _ << string_close(:select)
1908
+ return _ # And return the result here.
1909
+ else
1910
+ raise 'The method dropdown_box() requires an Array as argument.'
1911
+ end
1912
+ end; self.instance_eval { alias www_dropdown_box dropdown_box } # === Cyberweb.www_dropdown_box
1913
+ self.instance_eval { alias html_dropdown_box dropdown_box } # === Cyberweb.html_dropdown_box
1914
+
1915
+ # ========================================================================= #
1916
+ # === Cyberweb.convert_image_to_base64
1917
+ #
1918
+ # Usage example:
1919
+ #
1920
+ # Cyberweb.convert_image_to_base64("/home/x/programming/ruby/src/cyberweb/images/cyberweb_logo.png")
1921
+ #
1922
+ # ========================================================================= #
1923
+ def self.convert_image_to_base64(this_image)
1924
+ file_type = File.extname(this_image).delete('.').upcase
1925
+ return `magick #{this_image} #{file_type}:- | base64`
1926
+ end
1927
+
1928
+ # ========================================================================= #
1929
+ # === Cyberweb.return_all_html_tags_in_this_line
1930
+ # ========================================================================= #
1931
+ def self.return_all_html_tags_in_this_line(
1932
+ i = '<p>This <a> <div><h2>ok </h2>'
1933
+ )
1934
+ array = []
1935
+ if i.include? '<'
1936
+ regex = /(<.+?>)/
1937
+ array << i.scan(regex)
1938
+ end
1939
+ return array.flatten
1940
+ end
1941
+
1942
+ # ========================================================================= #
1943
+ # === Cyberweb.logo?
1944
+ #
1945
+ # This method will return the path to the currently used Cyberweb logo.
1946
+ #
1947
+ # This method may return a String such as:
1948
+ #
1949
+ # /home/x/programming/ruby/src/cyberweb/images/cyberweb_logo.png
1950
+ #
1951
+ # ========================================================================= #
1952
+ def self.logo?
1953
+ "#{server_base_directory?}programming/ruby/src/"\
1954
+ "cybwerb/lib/cyberweb/images/cyberweb_logo.png"
1955
+ end
1956
+
1957
+ # ========================================================================= #
1958
+ # === Cyberweb.readlines
1959
+ #
1960
+ # Preferrentially use this method when you read files, because we
1961
+ # will use the right encoding as we go.
1962
+ # ========================================================================= #
1963
+ def self.readlines(i)
1964
+ File.readlines(
1965
+ i,
1966
+ encoding: ::Cyberweb::Encoding::MAIN_ENCODING_TO_USE
1967
+ )
1968
+ end
1969
+
1970
+ # ========================================================================= #
1971
+ # === readlines
1972
+ # ========================================================================= #
1973
+ def readlines(file)
1974
+ ::Cyberweb.readlines(file)
1975
+ end
1976
+
1977
+ # ========================================================================= #
1978
+ # === Cyberweb.remove_newlines
1979
+ #
1980
+ # This simple method will get rid of newlines from the given input
1981
+ # String. The argument to this method should hence be a String.
1982
+ # ========================================================================= #
1983
+ def self.remove_newlines(i = '')
1984
+ i.delete("\n")
1985
+ end; self.instance_eval { alias remove_newline remove_newlines } # === Cyberweb.remove_newline
1986
+ self.instance_eval { alias remove_newlines_from remove_newlines } # === Cyberweb.remove_newlines_from
1987
+
1988
+ # ========================================================================= #
1989
+ # === Cyberweb.disable_right_click
1990
+ #
1991
+ # This is jquery code, which can be used to disable the right-mouse button
1992
+ # click. Personally I dislike it very much, but because other people may
1993
+ # wish to use it, I have decided to include it as part of the cyberweb
1994
+ # framework.
1995
+ #
1996
+ # Note that for this method to work, you must have jquery enabled prior
1997
+ # to calling it, through something such as a use_jquery() directive
1998
+ # or use :jquery or a similar call. Or simply set the project configuration
1999
+ # setting there.
2000
+ #
2001
+ # Usage example:
2002
+ #
2003
+ # x = Cyberweb.disable_right_click(:return_it)
2004
+ #
2005
+ # ========================================================================= #
2006
+ def self.disable_right_click(
2007
+ what_to_do_with_it = :output_it
2008
+ )
2009
+ result = return_javascript('$(document).ready(function(){
2010
+ $(document).bind("contextmenu", function(e){
2011
+ return false;
2012
+ });
2013
+ });'+N)
2014
+ case what_to_do_with_it
2015
+ # === :return
2016
+ when :return,
2017
+ :return_it
2018
+ return result # We simple return the result in this case.
2019
+ else
2020
+ ee result
2021
+ end
2022
+ end
2023
+
2024
+ # ========================================================================= #
2025
+ # === disable_right_click
2026
+ # ========================================================================= #
2027
+ def disable_right_click
2028
+ ::Cyberweb.disable_right_click
2029
+ end; alias no_right_click disable_right_click # === no_right_click
2030
+
2031
+ # ========================================================================= #
2032
+ # === Cyberweb.colourize_ruby_code (ruby tag)
2033
+ #
2034
+ # Use this to colourize ruby code. Be careful when using this though and
2035
+ # only use it when you (a) need it and (b) when you have ruby code in
2036
+ # question.
2037
+ # ========================================================================= #
2038
+ def self.colourize_ruby_code(_)
2039
+ _ = _.dup
2040
+ _.gsub!(/class /,
2041
+ '<span class="BG_Black pad1px lightgreen bold">class </span>')
2042
+ _.gsub!(/require/,
2043
+ '<span class="pad1px red FI bold">require</span>')
2044
+ _.gsub!(/end$/,
2045
+ '<span class="BG_Black pad1px red bold">end</span>')
2046
+ _.gsub!(/else/,
2047
+ '<span class="BG_Black pad1px red bold">else</span>')
2048
+ _.gsub!(/if /,
2049
+ '<span class="BG_Black pad1px red bold">if </span>')
2050
+ _.gsub!(/elsif/,
2051
+ '<span class="BG_Black pad1px red bold">elsif</span>')
2052
+ _.gsub!(/__FILE__/,
2053
+ '<span class="BG_Black pad1px pink bold">__FILE__</span>')
2054
+ _.gsub!(/\$PROGRAM_NAME/,
2055
+ '<span class="BG_Black pad1px lightgreen bold">$PROGRAM_NAME</span>')
2056
+ _.gsub!(/class (\w+) </,'<span class="BG_Black pad1px yel bold">class</span> \\1 <')
2057
+ _.gsub!(/super\(\)/,'<span class="BG_Black pad1px cyan bold">super()</span>')
2058
+ _.gsub!(/#!\/System\/Executables\/ruby -w/,'<span class="BG_Black pad1px green bold">#!/System/Executables/ruby -w</span>')
2059
+ _.gsub!(/def (.*)/,
2060
+ '<span class="BG_Black pad1px orange bold">def </span><span class="BG_Black BO pad1px lightblue">\1</span>')
2061
+ _.gsub!(/do/,
2062
+ '<span class="BG_Black pad1px orange bold">do</span>')
2063
+ return _
2064
+ end
2065
+
2066
+ # ========================================================================= #
2067
+ # === Cyberweb.use_this_local_port_or_a_later_port
2068
+ #
2069
+ # This method can be used to scan for an open local port.
2070
+ #
2071
+ # It was necessary because Sinatra may often be already running
2072
+ # on a localhost port.
2073
+ # ========================================================================= #
2074
+ def self.use_this_local_port_or_a_later_port(i = '4567')
2075
+ begin
2076
+ require 'roebe/toplevel_methods/open_ports.rb'
2077
+ if Roebe.is_this_port_open?(i)
2078
+ return i
2079
+ else
2080
+ # else find a fitting open port in the next 50
2081
+ # ports.
2082
+ upper_range = i.to_i + 50
2083
+ i.to_i.upto(upper_range) {|try_this_port|
2084
+ if Roebe.is_this_port_open?(try_this_port)
2085
+ return try_this_port
2086
+ # else # else we must continue.
2087
+ # return nil
2088
+ end
2089
+ }
2090
+ end
2091
+ rescue LoadError
2092
+ end
2093
+ end
2094
+
2095
+ # ========================================================================= #
2096
+ # === Cyberweb.sanitize_this_string_by_adding_a_newline_after_every_closing_HTML_tag
2097
+ #
2098
+ # The following method is an ad-hoc method - I needed to sanitize a remote
2099
+ # String coming from a .html page that removed all newlines. Ideally this
2100
+ # should be a regex, but for now we just chop away on '>'.
2101
+ #
2102
+ # If a file is given as argument then its content will be read.
2103
+ #
2104
+ # Usage example for a local .html file:
2105
+ #
2106
+ # x = Cyberweb.sanitize_this_string_by_adding_a_newline_after_every_closing_HTML_tag('/Depot/j/foobar.html')
2107
+ #
2108
+ # ========================================================================= #
2109
+ def self.sanitize_this_string_by_adding_a_newline_after_every_closing_HTML_tag(
2110
+ i = ARGV
2111
+ )
2112
+ if i.is_a? Array
2113
+ i = i.join(' ').strip
2114
+ end
2115
+ if i and File.file?(i)
2116
+ i = File.read(i) # Add support for existing files here.^
2117
+ end
2118
+ return i.gsub(/>/, ">\n")
2119
+ end; self.instance_eval { alias sanitizer sanitize_this_string_by_adding_a_newline_after_every_closing_HTML_tag } # === Cyberweb.sanitizer
2120
+
2121
+ # ========================================================================= #
2122
+ # === Cyberweb.display_this_file
2123
+ # ========================================================================= #
2124
+ def self.display_this_file(
2125
+ this_file = :gtk
2126
+ )
2127
+ print return_this_file(this_file)
2128
+ end
2129
+
2130
+ # ========================================================================= #
2131
+ # === Cyberweb.edit_configuration_file
2132
+ #
2133
+ # This method allows you to edit configuration files.
2134
+ # ========================================================================= #
2135
+ def self.edit_configuration_file(
2136
+ use_this_editor = 'vim'
2137
+ )
2138
+ _ = configuration_file?
2139
+ puts 'Next using vim to edit'; puts
2140
+ puts " #{_}"
2141
+ puts
2142
+ system "#{use_this_editor} #{_}"
2143
+ end
2144
+
2145
+ # ========================================================================= #
2146
+ # === Cyberweb.path_to_the_internal_javascript_directory?
2147
+ # ========================================================================= #
2148
+ def self.path_to_the_internal_javascript_directory?
2149
+ return "#{Cyberweb.project_base_directory?}javascript_code/"
2150
+ end
2151
+
2152
+ # ========================================================================= #
2153
+ # === Cyberweb.return_html_code_for_the_javascript_calculator
2154
+ #
2155
+ # This is the method that will return the table that, in turn, shall
2156
+ # simulate a javascript-calculator.
2157
+ # ========================================================================= #
2158
+ def self.return_html_code_for_the_javascript_calculator(
2159
+ optional_css_class_to_use = ''
2160
+ )
2161
+ return '<table id="simple_javascript_calculator" style="border: 1px solid black" class="'+optional_css_class_to_use.to_s+'">
2162
+ <tr>
2163
+ <td align="center">
2164
+ <input type="text" ID="screen_for_the_simple_javascript_calculator" NAME="screen" style="width:95%; font-size: 30px"><br/>
2165
+ </td>
2166
+ </tr>
2167
+ <tr>
2168
+ <td>
2169
+ <input class="input_for_the_calculator" type="button" NAME="7" VALUE=" 7 " onclick="updateTextbox(7)">
2170
+ <input class="input_for_the_calculator" type="button" NAME="8" VALUE=" 8 " onclick="updateTextbox(8)">
2171
+ <input class="input_for_the_calculator" type="button" NAME="9" VALUE=" 9 " onclick="updateTextbox(9)">
2172
+ <input class="input_for_the_calculator" type="button" NAME="+" VALUE=" + " onclick="updateTextbox(\'+\')">
2173
+ <br>
2174
+ <input class="input_for_the_calculator" type="button" NAME="4" VALUE=" 4 " onclick="updateTextbox(4)">
2175
+ <input class="input_for_the_calculator" type="button" NAME="5" VALUE=" 5 " onclick="updateTextbox(5)">
2176
+ <input class="input_for_the_calculator" type="button" NAME="6" VALUE=" 6 " onclick="updateTextbox(6)">
2177
+ <input class="input_for_the_calculator" type="button" NAME="-" VALUE=" - " onclick="updateTextbox(\'-\')">
2178
+ <br>
2179
+ <input class="input_for_the_calculator" type="button" NAME="1" VALUE=" 1 " onclick="updateTextbox(1)">
2180
+ <input class="input_for_the_calculator" type="button" NAME="2" VALUE=" 2 " onclick="updateTextbox(2)">
2181
+ <input class="input_for_the_calculator" type="button" NAME="3" VALUE=" 3 " onclick="updateTextbox(3)">
2182
+ <input class="input_for_the_calculator" type="button" NAME="*" VALUE=" x " onclick="updateTextbox(\'*\')">
2183
+ <br>
2184
+ <input class="input_for_the_calculator" type="button" NAME="c" VALUE=" c " onclick="reset();">
2185
+ <input class="input_for_the_calculator" type="button" NAME="0" VALUE=" 0 " onclick="updateTextbox(0)">
2186
+ <input class="input_for_the_calculator" type="button" NAME="=" VALUE=" = " onclick="result();">
2187
+ <input class="input_for_the_calculator" type="button" NAME="/" VALUE=" / " onclick="updateTextbox(\'/\')">
2188
+ </td>
2189
+ </tr>
2190
+ </table>'
2191
+ end
2192
+
2193
+ # ========================================================================= #
2194
+ # === Cyberweb.translate_html_string_into_webobject_string
2195
+ # ========================================================================= #
2196
+ def self.translate_html_string_into_webobject_string(
2197
+ i =
2198
+ '<div>
2199
+ <h2>Hello world!</h2>
2200
+
2201
+ <p>This is the first paragraph.</p>
2202
+
2203
+ <p>This is the second paragraph. It includes a bit of HTML
2204
+ and <b>newlines</b>.</p>
2205
+
2206
+ </div>'
2207
+ )
2208
+ do_more_parsing = true
2209
+ result = ''.dup
2210
+ splitted = i.split("\n")
2211
+ splitted.each {|this_line|
2212
+ if this_line.include?('<') and this_line.include?('>')
2213
+ if do_more_parsing
2214
+ all_html_tags_in_this_line = return_all_html_tags_in_this_line(this_line)
2215
+ first_tag = all_html_tags_in_this_line.first
2216
+ result << first_tag.delete('<>')+" {\n"
2217
+ result << "ee '"
2218
+ else
2219
+ result << this_line
2220
+ end
2221
+ do_more_parsing = false
2222
+ end
2223
+ }
2224
+ result << "'\n}\n"
2225
+ return result
2226
+ end
2227
+
2228
+ # ========================================================================= #
2229
+ # === Cyberweb.remove_html
2230
+ #
2231
+ # This method will attempt to get rid of all html found in a String.
2232
+ # ========================================================================= #
2233
+ def self.remove_html(i)
2234
+ if Object.const_defined?(:Roebe) and
2235
+ Roebe.respond_to?(:remove_html)
2236
+ return Roebe.remove_html(i)
2237
+ else
2238
+ i # Else return it unmodified.
2239
+ end
2240
+ end
2241
+
2242
+ # ========================================================================= #
2243
+ # === string_cont
2244
+ # ========================================================================= #
2245
+ def string_cont(i)
2246
+ ::Cyberweb.string_cont(i)
2247
+ end; alias string_content string_cont # === string_content
2248
+
2249
+ # ========================================================================= #
2250
+ # === Cyberweb.return_meta_collection
2251
+ #
2252
+ # Which charset and content type to use can be controlled via this
2253
+ # method here.
2254
+ # ========================================================================= #
2255
+ def self.return_meta_collection(
2256
+ use_this_charset = 'UTF-8'
2257
+ )
2258
+ _ = ''.dup
2259
+ # if is_html5?
2260
+ # _ << return_iso_8859_charset
2261
+ # else
2262
+ case use_this_charset
2263
+ # ======================================================================= #
2264
+ # === :default
2265
+ # ======================================================================= #
2266
+ when :default,
2267
+ nil # Nil is also implying the default charset.
2268
+ use_this_charset = 'UTF-8'
2269
+ end
2270
+ case use_this_charset.downcase # We work on a downcased variant here.
2271
+ when 'utf-8',
2272
+ 'utf',
2273
+ 'default'
2274
+ _ << return_utf_charset
2275
+ when 'iso'
2276
+ _ << return_iso_encoding
2277
+ else # Else use a specific charset.
2278
+ _ << '<meta http-equiv="content-type" content="text/html; charset='+use_this_charset+'" >'+NL
2279
+ end
2280
+ # ======================================================================= #
2281
+ # Annoy the hell out of robots:
2282
+ # ======================================================================= #
2283
+ _ << '<meta name="robots" content="noindex,nofollow,noarchive,noimageindex">'+NL
2284
+ return _ # Return that string finally.
2285
+ end
2286
+
2287
+ # ========================================================================= #
2288
+ # === string_span
2289
+ # ========================================================================= #
2290
+ def string_span(
2291
+ a = '',
2292
+ b = Span.to_s,
2293
+ c = '',
2294
+ d = '',
2295
+ e = ''
2296
+ )
2297
+ ::Cyberweb.string_span(a, b, c, d, e)
2298
+ end
2299
+
2300
+ # ========================================================================= #
2301
+ # === string_s
2302
+ #
2303
+ # This was disabled in May 2021. Not sure whether we will re-enable it
2304
+ # again one day or not. For now this is simply commented.
2305
+ # ========================================================================= #
2306
+ # def string_s(
2307
+ # content = '',
2308
+ # which_tag = 'span',
2309
+ # css_class = '',
2310
+ # the_id = '',
2311
+ # css_style = '',
2312
+ # javascript_code = ''
2313
+ # )
2314
+ # ::Cyberweb.string_s(
2315
+ # content,
2316
+ # which_tag,
2317
+ # css_class,
2318
+ # the_id,
2319
+ # css_style,
2320
+ # javascript_code
2321
+ # )
2322
+ # end; alias string_s2 string_s # === string_s2
2323
+
2324
+ # ========================================================================= #
2325
+ # === s (s tag)
2326
+ #
2327
+ # s is short for a <span> tag.
2328
+ #
2329
+ # Historically it was used for <span> tags, but lateron it was shortened
2330
+ # to become a generic "s" named method. This is a VERY important method.
2331
+ #
2332
+ # With it, you can specify arbitrary html tags.
2333
+ #
2334
+ # It will be often-used. sbr or string_s is an alternative to it.
2335
+ #
2336
+ # You may also use numbers rather than a specific tag, though I
2337
+ # discourage using numbers because they are less readable IMHO.
2338
+ # Anyway, here are the codes for these numbers:
2339
+ #
2340
+ # <b>1</b> is div, <b>2</b> is paragraph, <b>3</b> is span,
2341
+ # <b>4</b> is header1,<b>5</b> h2, <b>6</b> h3,
2342
+ # <b>7</b> h4, <b>8</b> h5, <b>9</b> h6
2343
+ #
2344
+ # s is like S() in my old php scripts, so we could do something like:
2345
+ #
2346
+ # <span class="s2em">YEah</span>
2347
+ #
2348
+ # Some specific usage example for this method:
2349
+ #
2350
+ # x.s 'Content','h5','s1em','border:1px solid blue','SoomeId'
2351
+ # x.s 'Content','h5','s1em','border:1px solid blue','SoomeId'
2352
+ # s 'here comes text','div','marl1em','div_id','padding:2px'
2353
+ #
2354
+ # ========================================================================= #
2355
+ def s(
2356
+ content = '',
2357
+ which_tag = 'span',
2358
+ css_class = '',
2359
+ the_id = '',
2360
+ css_style = '',
2361
+ optional_javascript_code = ''
2362
+ )
2363
+ # ======================================================================= #
2364
+ # Delegate towards the string_s() method next, which resides in the
2365
+ # ======================================================================= #
2366
+ # same file here.
2367
+ string_result = string_s(
2368
+ content,
2369
+ which_tag,
2370
+ css_class, the_id, css_style,
2371
+ optional_javascript_code
2372
+ )
2373
+ if block_given?
2374
+ yielded = yield
2375
+ case yielded
2376
+ # ===================================================================== #
2377
+ # === :editable
2378
+ # ===================================================================== #
2379
+ when :editable
2380
+ position = string_result.index('>') # Finds the first position.
2381
+ string_result[position,0] = ' contenteditable="true"'
2382
+ end
2383
+ end
2384
+ ee string_result
2385
+ end
2386
+
2387
+ # ========================================================================= #
2388
+ # === span
2389
+ #
2390
+ # We will simply output through the string_span() method here.
2391
+ # ========================================================================= #
2392
+ def span(
2393
+ content = '',
2394
+ css_class = Span.to_s,
2395
+ the_id = '',
2396
+ css_style = '',
2397
+ javascript = '',
2398
+ &block
2399
+ )
2400
+ ee string_span(
2401
+ content,
2402
+ css_class,
2403
+ the_id,
2404
+ css_style,
2405
+ javascript,
2406
+ &block
2407
+ )
2408
+ end; alias espan span # === espan
2409
+
2410
+ # ========================================================================= #
2411
+ # === cspan
2412
+ # ========================================================================= #
2413
+ def cspan
2414
+ eclose :span
2415
+ end
2416
+
2417
+ # ========================================================================= #
2418
+ # === Cyberweb.arrow_right
2419
+ # ========================================================================= #
2420
+ def self.arrow_right
2421
+ '→'
2422
+ end
2423
+
2424
+ # ========================================================================= #
2425
+ # === Cyberweb.left_arrow
2426
+ # ========================================================================= #
2427
+ def self.left_arrow
2428
+ '&larr;'
2429
+ end
2430
+
2431
+ # ========================================================================= #
2432
+ # === Cyberweb.glob (glob tag)
2433
+ #
2434
+ # Obtain all files from a given directory.
2435
+ #
2436
+ # This is essentially similar to Dir[], but we will append a '*'
2437
+ # character if no '*' is in our input argument.
2438
+ # ========================================================================= #
2439
+ def self.glob(i)
2440
+ i = i.to_s
2441
+ i << '*' unless i.include? '*'
2442
+ return Dir[i]
2443
+ end
2444
+
2445
+ # ========================================================================= #
2446
+ # === Cyberweb.string_ebr
2447
+ # ========================================================================= #
2448
+ def self.string_ebr(
2449
+ content = '',
2450
+ css_class = Span.to_s,
2451
+ the_id = '',
2452
+ css_style = '',
2453
+ javascript = '',
2454
+ &block
2455
+ )
2456
+ return Cyberweb.string_span(
2457
+ content,
2458
+ css_class,
2459
+ the_id,
2460
+ css_style,
2461
+ javascript,
2462
+ &block
2463
+ )+"<br>\n"
2464
+ end
2465
+
2466
+ # ========================================================================= #
2467
+ # === Cyberweb.string_p
2468
+ #
2469
+ # This is the string representation for a <p> tag. Since as of January
2470
+ # 2024 this method will delegate towards HtmlTags.stag(), which is
2471
+ # actually doing the real work here.
2472
+ # ========================================================================= #
2473
+ def self.string_p(
2474
+ css_class = '',
2475
+ the_id = '',
2476
+ css_style = '',
2477
+ javascript = ''
2478
+ )
2479
+ HtmlTags.stag(:p, css_class, the_id, css_style, javascript)
2480
+ end
2481
+
2482
+ # ========================================================================= #
2483
+ # === Cyberweb.spinbutton
2484
+ #
2485
+ # In December 2023 I confirmed that this code will create a spinbutton.
2486
+ #
2487
+ # Note that in HTML, this is more commonly called a "number-input".
2488
+ #
2489
+ # The following attributes can be used to specify restrictions:
2490
+ #
2491
+ # max: specifies the maximum value allowed
2492
+ # min: specifies the minimum value allowed
2493
+ # step: specifies the step-size
2494
+ # value: specifies the default value
2495
+ #
2496
+ # ========================================================================= #
2497
+ def self.spinbutton(
2498
+ start_position = 0,
2499
+ end_position = 100,
2500
+ increment_size = 1,
2501
+ id_to_be_used = nil
2502
+ )
2503
+ extra_CSS_rules = '
2504
+ <style>
2505
+ /* This will always show the spin buttons on the right side */
2506
+ input[type=number]::-webkit-inner-spin-button {
2507
+ opacity: 1
2508
+ }
2509
+ </style>
2510
+ '
2511
+ if id_to_be_used # This is the case when a id-value is provided.
2512
+ return extra_CSS_rules+
2513
+ '<input step="'+increment_size.to_s+'" id="'+id_to_be_used+'" '\
2514
+ 'type="number" value="'+start_position.to_s+'" min="1" max="'+end_position.to_s+'" />'
2515
+ else
2516
+ return extra_CSS_rules+
2517
+ '<input step="'+increment_size.to_s+'" '\
2518
+ 'type="number" value="'+start_position.to_s+'" min="1" max="'+end_position.to_s+'" />'
2519
+ end
2520
+ end
2521
+
1888
2522
  # ========================================================================= #
1889
2523
  # === Cyberweb.localhost?
1890
2524
  #
@@ -1959,4 +2593,9 @@ if __FILE__ == $PROGRAM_NAME
1959
2593
  e Cyberweb.logo?
1960
2594
  Cyberweb.generate_simple_webpage
1961
2595
  Cyberweb.download_webpage(ARGV)
2596
+ e Cyberweb.string_p('mars1em BOLD','some_id','border: 5px solid red','')
2597
+ text = 'abc def ghi'
2598
+ css_class = 'mars2em BOLD'
2599
+ the_id = 'some_id'
2600
+ e Cyberweb.string_s(text,'h4',css_class, the_id)
1962
2601
  end # cyberwebhtmlcomment