Module: Cyberweb::BaseModule

Includes:
Colours, CommandlineArguments, ContentType
Included in:
Base, Objectified::HtmlTags::Base
Defined in:
lib/cyberweb/base_module/base_module/base_module.rb,
lib/cyberweb/base_module/colours/colours.rb,
lib/cyberweb/base_module/content_type/content_type.rb,
lib/cyberweb/base_module/commandline_arguments/commandline_arguments.rb,
lib/cyberweb/base_module/file_related_functionality/file_related_functionality.rb

Overview

Cyberweb::BaseModule

Defined Under Namespace

Modules: Colours, CommandlineArguments, ContentType, FileRelatedFunctionality

Instance Method Summary collapse

Methods included from ContentType

#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text

Methods included from CommandlineArguments

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

Methods included from Colours

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

Instance Method Details

#attach_these_constants(i) ⇒ Object Also known as: fancy_extend, smart_include, adhoc_include, make_available, pull_in

#

attach_these_constants

This is an “alternative” to “include Foobar” code.

Example for using this method may go like this:

require 'roebe/knowledge_base/knowledge_base.rb'
pull_in Roebe::KnowledgeBase
#


167
168
169
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 167

def attach_these_constants(i)
  Object.send(:include, i)
end

#base_dir?Boolean Also known as: project_base_dir?, project_base_directory?, project_directory?

#

base_dir?

Getter-method to query the project-base-directory of the cyberweb project. It is mostly a helper-method.

#

Returns:

  • (Boolean)


54
55
56
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 54

def base_dir?
  Cyberweb.project_base_dir?
end

#beautiful_url(i) ⇒ Object Also known as: beautiful_URL

#

beautiful_url

#


296
297
298
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 296

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

#cd(i) ⇒ Object

#

cd (cd tag)

#


231
232
233
234
235
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 231

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

#create_the_internal_hashObject Also known as: reset_the_internal_hash

#

create_the_internal_hash

#


91
92
93
94
95
96
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 91

def create_the_internal_hash
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
end

#doctype?(optional_language = nil) ⇒ Boolean Also known as: default_doc_type?

#

doctype?

This method will return the following String:

"<!DOCTYPE html>"

It can also return a String such as:

"<!DOCTYPE html lang="en">"
#

Returns:

  • (Boolean)


249
250
251
252
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 249

def doctype?(optional_language = nil)
  require 'cyberweb/toplevel_methods/doctype.rb'
  return "#{Cyberweb.doctype?(optional_language)}\n"
end

#ee(i = '') ⇒ Object

#

ee (print tag)

This is essentially just a wrapper over print(), more or less.

#


205
206
207
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 205

def ee(i = '')
  ::Cyberweb.ee(i)
end

#ensure_main_encoding(i) ⇒ Object

#

ensure_main_encoding

#


152
153
154
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 152

def ensure_main_encoding(i)
  Cyberweb.ensure_main_encoding(i)
end

#esystem(i) ⇒ Object

#

esystem

#


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

def esystem(i)
  puts i
  system(i)
end

#html_templates(hash) ⇒ Object Also known as: html_template

#

html_templates

This method is just a wrapper over class Cyberweb::HtmlTemplate.

Since as of May 2023 class Cyberweb::HtmlTemplate is one of the most important classes of the cyberweb project, so it made sense to have a simpler method to yield a new html-template object.

#


370
371
372
373
374
375
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 370

def html_templates(hash)
  require_the_html_templates unless Cyberweb.const_defined?(:HtmlTemplate)
  Cyberweb.html_template(
    hash
  ).to_s # Make sure it is string-rendered.
end

#initialize_the_config_if_the_config_hash_is_emptyObject

#

initialize_the_config_if_the_config_hash_is_empty

#


212
213
214
215
216
217
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 212

def initialize_the_config_if_the_config_hash_is_empty
  _ = Cyberweb.config?
  if _ and _.empty?
    Cyberweb.initialize_the_config
  end
end

#internal_hash?Boolean Also known as: ihash?, internal_hash

#

internal_hash?

#

Returns:

  • (Boolean)


101
102
103
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 101

def internal_hash?
  @internal_hash
end

#log_dir?Boolean

#

log_dir?

The primary log-dir for the cyberweb-project.

Since as of July 2023 this tries to honour the configuration object if it is available.

#

Returns:

  • (Boolean)


184
185
186
187
188
189
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 184

def log_dir?
  require 'cyberweb/configuration/configuration.rb'
  _ = Cyberweb.log_dir?
  _ = '/home/x/Temp/cyberweb/' unless _ # Hardcoded "rescue" in this case.
  return _
end

#no_http(i) ⇒ Object

#

no_http

Returns a variant without leading “http://” string. Please use this method whenever getting rid of http.

#


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

def no_http(i)
  return i.sub(/^http:\/\//, '')
end

#random_alphabet_characters(n_characters = 10) ⇒ Object

#

random_alphabet_characters

#


303
304
305
306
307
308
309
310
311
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 303

def random_alphabet_characters(
    n_characters = 10
  )
  _ = ''.dup
  n_characters.times {
    _ << ('a' .. 'z').to_a.sample
  }
  return _
end

#rarrow?Boolean Also known as: rarrow

#

rarrow?

#

Returns:

  • (Boolean)


350
351
352
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 350

def rarrow?
  ''
end

#rds(i) ⇒ Object

#

rds (rds tag)

#


343
344
345
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 343

def rds(i)
  Cyberweb.rds(i)
end

#remove_comments_from_this_string(i) ⇒ Object

#

remove_comments_from_this_string

This method will simply remove all leading “#” comments from the given String, up to each end of the given line.

#


120
121
122
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 120

def remove_comments_from_this_string(i)
  return i.gsub(/^\s*#.+$/,'')
end

#remove_numbers(i) ⇒ Object

#

remove_numbers

#


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

def remove_numbers(i)
  return i.delete('[0-9]')
end

#require_the_html_templatesObject

#

require_the_html_templates

This method is only relevant for classes OTHER than class Cyberweb::HtmlTemplate.

#


66
67
68
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 66

def require_the_html_templates
  require 'cyberweb/requires/require_the_html_template.rb'
end

#require_these(i) ⇒ Object

#

require_these

This method can be used to batch-require several files in one go.

#


129
130
131
132
133
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 129

def require_these(i)
  [i].flatten.reject {|line| line.strip.empty? }.each {|this_project|
    require(this_project.strip)
  }
end

#return_file_size_in_kb_of(this_file) ⇒ Object

#

return_file_size_in_kb_of

#


222
223
224
225
226
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 222

def return_file_size_in_kb_of(
    this_file
  )
  (File.size(this_file).to_f / 1024.0).round(2)
end

#return_html_comment(of_this_text = '') ⇒ Object

#

return_html_comment

This helper-method will simply append some HTML comment, properly embedded.

#


319
320
321
322
323
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 319

def return_html_comment(
    of_this_text = ''
  )
  return Cyberweb.html_comment(of_this_text.to_s)
end

#ruby_sitelib_dir?Boolean

#

ruby_sitelib_dir?

#

Returns:

  • (Boolean)


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

def ruby_sitelib_dir?
  RbConfig::CONFIG['sitelibdir'].to_s+'/'
end

#sanitize_this_id(i) ⇒ Object

#

sanitize_this_id

This method can be used to sanitize the given input, for further use as a HTML id. A few assumptions will be made for input that is passed to this method; but, even aside from these assumptions, the most important point for this method is that it can be consistently used/re-used.

#


263
264
265
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 263

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

#server_base_directory?Boolean

#

server_base_directory?

#

Returns:

  • (Boolean)


328
329
330
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 328

def server_base_directory?
  Cyberweb.server_base_directory?
end

#string_remote_image(i = :a_fat_cat) ⇒ Object

#

string_remote_image

#


270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 270

def string_remote_image(
    i = :a_fat_cat
  )
  begin
    require 'html_tags/individual_tags/img.rb'
  rescue LoadError; end
  if i.is_a? Symbol
    require 'beautiful_url'
    i = BeautifulUrl.this_remote_URL(i)
  end
  HtmlTags.img(i)
end

#today?Boolean

#

today?

#

Returns:

  • (Boolean)


110
111
112
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 110

def today?
  Date.today.strftime('%d.%m.%Y')
end

#try_to_require_rackObject

#

try_to_require_rack

#


82
83
84
85
86
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 82

def try_to_require_rack
  begin
    require 'rack'
  rescue LoadError; end
end

#try_to_require_the_open_gemObject

#

try_to_require_the_open_gem

#


73
74
75
76
77
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 73

def try_to_require_the_open_gem
  begin
    require 'open'
  rescue LoadError; end
end

#write_what_into(what, into) ⇒ Object

#

write_what_into

This is simply a wrapper over the toplevel method with the same name.

For the source code have a look at the .rb file that is required above this method body.

#


144
145
146
# File 'lib/cyberweb/base_module/base_module/base_module.rb', line 144

def write_what_into(what, into)
  Cyberweb.write_what_into(what, into)
end