Class: Cyberweb::Base

Inherits:
Object
  • Object
show all
Includes:
BaseModule, Cyberweb::BaseModule::FileRelatedFunctionality
Defined in:
lib/cyberweb/base/base.rb

Overview

Cyberweb::Base

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

NAMESPACE is a legacy constant - it is not deprecated, but downstream classes should ideally use the method called .infer_the_namespace() instead.

#
inspect
HOME_DIRECTORY_OF_THE_USER_X =
#

HOME_DIRECTORY_OF_THE_USER_X

The method used here is defined at cyberweb/constants/user_x.rb.

#
Cyberweb.home_x_dir?

Instance Method Summary collapse

Methods included from Cyberweb::BaseModule::FileRelatedFunctionality

#copy_this_file, #cpr, #delete_file, #filename_without_extension?, #read_file_via_utf8_encoding

Methods included from BaseModule

#attach_these_constants, #base_dir?, #beautiful_url, #create_the_internal_hash, #doctype?, #ee, #ensure_main_encoding, #esystem, #html_templates, #initialize_the_config_if_the_config_hash_is_empty, #internal_hash?, #log_dir?, #no_http, #random_alphabet_characters, #rarrow?, #rds, #remove_comments_from_this_string, #remove_numbers, #require_the_html_templates, #require_these, #return_file_size_in_kb_of, #return_html_comment, #ruby_sitelib_dir?, #sanitize_this_id, #string_remote_image, #today?, #try_to_require_rack, #try_to_require_the_open_gem, #write_what_into

Methods included from Cyberweb::BaseModule::ContentType

#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text

Methods included from Cyberweb::BaseModule::CommandlineArguments

#append_to_the_commandline_arguments, #commandline_arguments?, #first_argument?, #parse_these_commandline_arguments, #second_argument?, #set_commandline_arguments

Methods included from Cyberweb::BaseModule::Colours

#all_html_colours, #lightgreen, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato

Constructor Details

#initialize(commandline_arguments = ARGV) ⇒ Base

#

initialize

#


52
53
54
55
56
57
58
59
# File 'lib/cyberweb/base/base.rb', line 52

def initialize(
    commandline_arguments = ARGV
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
end

Instance Method Details

#be_verboseObject Also known as: set_be_verbose

#

be_verbose

Whether we will be verbose or not.

#


157
158
159
# File 'lib/cyberweb/base/base.rb', line 157

def be_verbose
  @internal_hash[:be_verbose] = true
end

#be_verbose?Boolean

#

be_verbose?

#

Returns:

  • (Boolean)


164
165
166
# File 'lib/cyberweb/base/base.rb', line 164

def be_verbose?
  @internal_hash[:be_verbose]
end

#cascading_style_sheets_directory?Boolean

#

cascading_style_sheets_directory?

#

Returns:

  • (Boolean)


439
440
441
# File 'lib/cyberweb/base/base.rb', line 439

def cascading_style_sheets_directory?
  "#{project_base_directory?}cascading_style_sheets/"
end

#cd(i) ⇒ Object

#

cd (cd tag)

#


103
104
105
# File 'lib/cyberweb/base/base.rb', line 103

def cd(i)
  Dir.chdir(i) if File.directory?(i)
end

#commandline_mode?Boolean Also known as: commandline?

#

commandline_mode?

#

Returns:

  • (Boolean)


180
181
182
# File 'lib/cyberweb/base/base.rb', line 180

def commandline_mode?
  @internal_hash[:mode] == :commandline
end

#copyright?Boolean Also known as: copyright

#

To display a copyright symbol + text you can use this method.

#

Returns:

  • (Boolean)


79
80
81
# File 'lib/cyberweb/base/base.rb', line 79

def copyright?
  COPYRIGHT_SYMBOL
end

#css_comment(i = '') ⇒ Object

#

css_comment

#


325
326
327
# File 'lib/cyberweb/base/base.rb', line 325

def css_comment(i = '')
  return Cyberweb.css_comment(i)
end

#delete_directory(i) ⇒ Object Also known as: remove_directory

#

delete_directory

Consistently use this method if you wish to remove a directory.

#


132
133
134
135
136
# File 'lib/cyberweb/base/base.rb', line 132

def delete_directory(i)
  if File.directory? i # Silent removal.
    FileUtils.rm_rf(i) unless i.start_with? '/'
  end
end

#do_toggleObject Also known as: toggle

#

do_toggle

This method can be used to quickly change between the two main modi.

#


313
314
315
316
317
318
319
320
# File 'lib/cyberweb/base/base.rb', line 313

def do_toggle
  case @internal_hash[:mode]
  when :www
    @internal_hash[:mode] = :commandline
  else
    @internal_hash[:mode] = :www
  end
end

#e(*args) ⇒ Object

#

e (e tag)

This is the method e, short for “echo”, aka output. There are two basic means for output, depending on the main “modus operandi”.

(1) the normal e() is just a wrapper for “puts”, which is to be used

on the commandline.

(2) the modified use for the www (such as in .cgi scripts), where

e is a wrapper over sbr, combining a <span> tag and then a
newline (via <br>).
#


267
268
269
270
271
272
273
# File 'lib/cyberweb/base/base.rb', line 267

def e(*args)
  if commandline_mode?
    puts args.first # Only report the first argument for now. May change at a later time. (August 2018)
  else
    ee Cyberweb.string_sbr(args) # ee defaults to printing.
  end
end

#echo_raw(i = '') ⇒ Object Also known as: er, re

#

echo_raw

This is a simplified echo-method, in case e() does not work.

#


494
495
496
# File 'lib/cyberweb/base/base.rb', line 494

def echo_raw(i = '')
  puts i
end

#filename?Boolean

#

filename?

#

Returns:

  • (Boolean)


465
466
467
# File 'lib/cyberweb/base/base.rb', line 465

def filename?
  ::Cyberweb.filename?.to_s
end

#full_path_to_image_directory?Boolean Also known as: path_to_the_main_image_directory?, path_to_the_image_directory?, prepend_path_to_the_images?

#

full_path_to_image_directory?

Convenience method towards the images.

#

Returns:

  • (Boolean)


247
248
249
# File 'lib/cyberweb/base/base.rb', line 247

def full_path_to_image_directory?
  Cyberweb.path_to_images?
end

#html_colours?Boolean

#

html_colours?

#

Returns:

  • (Boolean)


485
486
487
# File 'lib/cyberweb/base/base.rb', line 485

def html_colours?
  return ::Cyberweb.html_colours?
end

#html_image(i) ⇒ Object Also known as: html_img

#

html_image

Wrapper method towards the objectified <img> HTML tag.

#


346
347
348
349
350
351
352
# File 'lib/cyberweb/base/base.rb', line 346

def html_image(i)
  if i.is_a? Symbol
    i = ::Cyberweb::WebImages.map_symbol_to_image_location(i).dup
    #i.prepend(full_path_to_image_directory?)
  end
  return Cyberweb::Objectified::HtmlTags::Img.new(i)
end

#htmlentities(i) ⇒ Object Also known as: html_ent

#

htmlentities

#


195
196
197
# File 'lib/cyberweb/base/base.rb', line 195

def htmlentities(i)
  return Cyberweb.htmlentities(i)
end

#img_dir?Boolean

#

img_dir?

This method refers to a local directory where images are kept.

This is hardcoded for my home system, so it is fairly useless for other people.

#

Returns:

  • (Boolean)


405
406
407
408
# File 'lib/cyberweb/base/base.rb', line 405

def img_dir?
  "#{server_base_directory?}"\
  "#{use_this_relative_directory_for_custom_images?}"
end

#infer_the_namespaceObject

#

infer_the_namespace

This will assume the true namespace from the inspectable name.

#


204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/cyberweb/base/base.rb', line 204

def infer_the_namespace
  _ = inspect
  if _.include?(':0x')
    _ = _.split(':0x').first.to_s.strip
  end
  _ = _.to_s.delete('<')
  if _.include? ' '
    _ = _.split(' ').first.delete('#')
    if _.include? ':'
      _ = _.split(':')[0 .. -2].reject {|entry| entry.empty? }.join('::')
    end
  end
  @internal_hash[:namespace] = _.delete('#') # And assign it here.
end

#initialize_the_configurationObject Also known as: load_the_configuration

#

initialize_the_configuration

#


413
414
415
# File 'lib/cyberweb/base/base.rb', line 413

def initialize_the_configuration
  ::Cyberweb.load_the_configuration
end

#is_a_file?(i) ⇒ Boolean

#

is_a_file?

#

Returns:

  • (Boolean)


502
503
504
# File 'lib/cyberweb/base/base.rb', line 502

def is_a_file?(i)
  File.file?(i)
end

#is_a_video_file?(i) ⇒ Boolean

#

is_a_video_file?

#

Returns:

  • (Boolean)


278
279
280
281
# File 'lib/cyberweb/base/base.rb', line 278

def is_a_video_file?(i)
  require 'cyberweb/toplevel_methods/toplevel_methods.rb'
  Cyberweb.is_a_video_file?(i)
end

#is_an_image_file?(i) ⇒ Boolean Also known as: is_an_image?, is_image?

#

is_an_image_file?

This method will return true if the input is an image, otherwise it will yield false.

#

Returns:

  • (Boolean)


289
290
291
# File 'lib/cyberweb/base/base.rb', line 289

def is_an_image_file?(i)
  Cyberweb.is_an_image_file?(i)
end

#is_on_roebe?Boolean Also known as: on_roebe?, roebe_system?

#

is_on_roebe?

#

Returns:

  • (Boolean)


172
173
174
# File 'lib/cyberweb/base/base.rb', line 172

def is_on_roebe?
  Cyberweb.is_on_roebe?
end

#last_tag_used?Boolean

#

last_tag_used?

#

Returns:

  • (Boolean)


371
372
373
# File 'lib/cyberweb/base/base.rb', line 371

def last_tag_used?
  Cyberweb.last_tag_used?
end

#last_tag_used_first_element?Boolean

#

last_tag_used_first_element?

#

Returns:

  • (Boolean)


378
379
380
# File 'lib/cyberweb/base/base.rb', line 378

def last_tag_used_first_element?
  last_tag_used?.first.to_s
end

#last_tag_used_id?Boolean

#

last_tag_used_id?

#

Returns:

  • (Boolean)


385
386
387
388
# File 'lib/cyberweb/base/base.rb', line 385

def last_tag_used_id?
  _ = last_tag_used?
  return _.last
end

#mkdir(i) ⇒ Object Also known as: create_directory

#

mkdir (mkdir tag)

This method can be used to create a directory.

#


112
113
114
115
116
117
118
# File 'lib/cyberweb/base/base.rb', line 112

def mkdir(i)
  begin
    FileUtils.mkdir_p(i)
  rescue Errno::EACCES # => error
    e "Permission denied for the directory `#{i}`."
  end
end

#mode?Boolean

#

mode?

#

Returns:

  • (Boolean)


297
298
299
# File 'lib/cyberweb/base/base.rb', line 297

def mode?
  @internal_hash[:mode]
end

#namespace?Boolean

#

namespace?

#

Returns:

  • (Boolean)


222
223
224
# File 'lib/cyberweb/base/base.rb', line 222

def namespace?
  @internal_hash[:namespace]
end

#open_in_browser(i) ⇒ Object

#

open_in_browser

#


472
473
474
475
476
477
478
479
480
# File 'lib/cyberweb/base/base.rb', line 472

def open_in_browser(i)
  begin
    require 'open'
    if i.include? ' '
      i = '"'+i+'"'
    end
    Open.in_browser(i)
  rescue LoadError; end
end

#opne(i) ⇒ Object

#

opne

#


141
142
143
# File 'lib/cyberweb/base/base.rb', line 141

def opne(i)
  opnn; puts i
end

#opnn(namespace = namespace? # NAMESPACE ) ⇒ Object

#

opnn

This method can be used to display which class is responsible for commandline-output.

#


232
233
234
235
236
237
238
239
# File 'lib/cyberweb/base/base.rb', line 232

def opnn(
    namespace = namespace? # NAMESPACE
  )
  if namespace.is_a? String # Convert String object into Hash object here.
    namespace = { namespace: namespace }
  end
  Opn.opn(namespace)
end

#remove_comments_from_this_string_but_preserve_CSS_rules(i) ⇒ Object

#

remove_comments_from_this_string_but_preserve_CSS_rules

This method is similar to remove_comments_from_this_string() but it will specifically retain “{}” such as in “#smoke_1 {”.

#


335
336
337
338
# File 'lib/cyberweb/base/base.rb', line 335

def remove_comments_from_this_string_but_preserve_CSS_rules(i)
  use_this_regex = /^\s*#.+[^{]$/ # See: https://rubular.com/r/bz3BDrVynbtTwH
  return i.gsub(use_this_regex,'')
end

#remove_html(i) ⇒ Object

#

remove_html

#


357
358
359
# File 'lib/cyberweb/base/base.rb', line 357

def remove_html(i)
  Cyberweb.remove_html(i)
end

#resetObject

#

reset (reset tag)

#


64
65
66
67
68
69
70
71
72
# File 'lib/cyberweb/base/base.rb', line 64

def reset
  create_the_internal_hash # Initialize the internal-hash here.
  # ======================================================================= #
  # === :mode
  #
  # :mode can be either :www or :commandline.
  # ======================================================================= #
  @internal_hash[:mode] = :www
end

#return_all_directoriesObject

#

return_all_directories

#


148
149
150
# File 'lib/cyberweb/base/base.rb', line 148

def return_all_directories
  return Dir['*'].select {|entry| File.directory?(entry) }
end

#return_dateObject Also known as: dd_mm_yyyy

#

return_date

This method will return a String such as “20.10.2023”.

#


88
89
90
# File 'lib/cyberweb/base/base.rb', line 88

def return_date
  ::Time.now.strftime '%d.%m.%Y'
end

#return_program_name(i = $PROGRAM_NAME) ⇒ Object

#

return_program_name

This method will return the filename. So if you have an URL such as bla/webforum.cgi then this method will simply return the String “webforum.cgi”.

Since as of August 2023 this method here taps into a toplevel-defined method.

#


453
454
455
456
457
458
459
# File 'lib/cyberweb/base/base.rb', line 453

def return_program_name(
    i = $PROGRAM_NAME
  )
  return ensure_main_encoding(
    Cyberweb.return_program_name(i)
  )
end

#return_pwdObject

#

return_pwd

#


96
97
98
# File 'lib/cyberweb/base/base.rb', line 96

def return_pwd
  Cyberweb.return_pwd
end

#ruby_header?Boolean

#

ruby_header?

#

Returns:

  • (Boolean)


123
124
125
# File 'lib/cyberweb/base/base.rb', line 123

def ruby_header?
  RUBY_HEADER
end

#server_base_directory?Boolean

#

server_base_directory?

#

Returns:

  • (Boolean)


393
394
395
# File 'lib/cyberweb/base/base.rb', line 393

def server_base_directory?
  Cyberweb.server_base_directory?
end

#set_commandline_modeObject Also known as: use_commandline_mode

#

set_commandline_mode

#


187
188
189
# File 'lib/cyberweb/base/base.rb', line 187

def set_commandline_mode
  @internal_hash[:mode] = :commandline
end

#set_last_tag_used(a, id = '') ⇒ Object

#

set_last_tag_used

#


364
365
366
# File 'lib/cyberweb/base/base.rb', line 364

def set_last_tag_used(a, id = '')
  Cyberweb.set_last_tag_used(a, id)
end

#update_the_image_directoryObject

#

update_the_image_directory

#


420
421
422
# File 'lib/cyberweb/base/base.rb', line 420

def update_the_image_directory
  ::Cyberweb.update_use_this_relative_directory_for_custom_images
end

#use_this_relative_directory_for_custom_images?Boolean Also known as: name_of_img_dir?, default_image_directory?, image_directory?

#

use_this_relative_directory_for_custom_images?

This method will return a string such as “data/images/”.

#

Returns:

  • (Boolean)


430
431
432
# File 'lib/cyberweb/base/base.rb', line 430

def use_this_relative_directory_for_custom_images?
  return Cyberweb.name_of_img_dir?
end

#www_mode?Boolean

#

www_mode?

#

Returns:

  • (Boolean)


304
305
306
# File 'lib/cyberweb/base/base.rb', line 304

def www_mode?
  @internal_hash[:mode] == :www
end