Class: Cyberweb::Generator::CGI

Inherits:
Generator show all
Defined in:
lib/cyberweb/generator/cgi.rb

Overview

Cyberweb::Generator::CGI

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
MAIN_EDITOR_TO_USE =
#

MAIN_EDITOR_TO_USE

This is mostly only useful for my home system.

#
'bluefish'
USE_THESE_CSS_CLASSES_FOR_THE_MAIN_DIV_ELEMENT =
#

USE_THESE_CSS_CLASSES_FOR_THE_MAIN_DIV_ELEMENT

#
'mar0px pad0px s0_8em'
DEFAULT_PAGE_CONTENT =
#

DEFAULT_PAGE_CONTENT

This is the basic skeleton that will be used to generate the file in question.

#
::Cyberweb::Generator::CGI.generate_default_skeleton_for_webpage

Constants inherited from Base

Base::HOME_DIRECTORY_OF_THE_USER_X

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#be_verbose, #be_verbose?, #cascading_style_sheets_directory?, #cd, #commandline_mode?, #copyright?, #css_comment, #delete_directory, #do_toggle, #e, #echo_raw, #filename?, #full_path_to_image_directory?, #html_colours?, #html_image, #htmlentities, #img_dir?, #infer_the_namespace, #initialize_the_configuration, #is_a_file?, #is_a_video_file?, #is_an_image_file?, #is_on_roebe?, #last_tag_used?, #last_tag_used_first_element?, #last_tag_used_id?, #mkdir, #mode?, #namespace?, #open_in_browser, #opne, #remove_comments_from_this_string_but_preserve_CSS_rules, #remove_html, #return_all_directories, #return_date, #return_program_name, #return_pwd, #ruby_header?, #server_base_directory?, #set_commandline_mode, #set_last_tag_used, #update_the_image_directory, #use_this_relative_directory_for_custom_images?, #www_mode?

Methods included from 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, #cd, #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, #server_base_directory?, #string_remote_image, #today?, #try_to_require_rack, #try_to_require_the_open_gem, #write_what_into

Methods included from BaseModule::ContentType

#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text

Methods included from BaseModule::CommandlineArguments

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

Methods included from BaseModule::Colours

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

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ CGI

#

initialize

#


90
91
92
93
94
95
96
97
# File 'lib/cyberweb/generator/cgi.rb', line 90

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline(commandline_arguments)
  run if run_already
end

Class Method Details

.generate_default_skeleton_for_webpage(use_this_title = 'Provide a title for the page here') ⇒ Object

#

Cyberweb::Generator::CGI.generate_default_skeleton_for_webpage

This method will return a String that is ultimately used for the autogeneration of new .cgi files.

#


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cyberweb/generator/cgi.rb', line 50

def self.generate_default_skeleton_for_webpage(
    use_this_title = 'Provide a title for the page here'
  )
  return RUBY_HEADER+"
# =========================================================================== #
# require 'roebe/www/foobar.cgi'
# =========================================================================== #
require 'cyberweb/autoinclude'

english(:filename_capitalized) {
created_on '#{Cyberweb.date_today}' # #{Cyberweb.return_current_weekday}.
autoextend # ← This can be used to automatically do: include Cyberweb
# title '#{use_this_title}' # Or use this as the title.
ruby_favicon
default_template ''
body_css_class 'mar0px s2px padt2px VERDANAs'
body_css_style 'background-color: #d3d2d1;'
default_font_size_and_hyperlinks

preferred_width('#{USE_THESE_CSS_CLASSES_FOR_THE_MAIN_DIV_ELEMENT}') {
h1 dot(106, 'marr8px')+
   title?,
   'mart1px marb0_5em'
p_default_le {
}
}}"
end

Instance Method Details

#commandline?Boolean

#

commandline?

#

Returns:

  • (Boolean)


147
148
149
# File 'lib/cyberweb/generator/cgi.rb', line 147

def commandline?
  @commandline
end

#generate_cgi_file(i) ⇒ Object

#

generate_cgi_file

This method will ultimately generate a proper .cgi file.

#


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/cyberweb/generator/cgi.rb', line 184

def generate_cgi_file(i)
  # ======================================================================= #
  # We have to re-determine the title of a page.
  # ======================================================================= #
  @title_of_page = File.basename(i).
                   tr('_',' ').
                   gsub(/#{File.extname(i)}/,'')
  update_default_page_content # Need to update @default_page_content here.
  # ======================================================================= #
  # Assign the default page content next to a helper-variable:
  # ======================================================================= #
  what = @default_page_content
  into = i
  write_what_into(what, into) # ← Create the file here.
  opne "The file `#{sfile(into)}#{rev}` was created." if File.exist? into
  # ======================================================================= #
  # Run a chmod to ensure the file has the correct permission next.
  # ======================================================================= #
  FileUtils.chmod(0755, into) if File.exist?(into)
  if is_on_roebe?
    # ===================================================================== #
    # Open it on my home system as well, via my main editor.
    # ===================================================================== #
    Esystem.esystem("#{MAIN_EDITOR_TO_USE} #{into} &")
    begin
      require 'open' unless Object.const_defined?(:Open)
    rescue LoadError; end
    Open.in_browser(into)
  end
end

#opnnObject

#

opnn

#


161
162
163
# File 'lib/cyberweb/generator/cgi.rb', line 161

def opnn
  super(NAMESPACE)
end

#process_commandlineObject

#

process_commandline

Only act on the keyword “generate”.

#


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cyberweb/generator/cgi.rb', line 123

def process_commandline
  if commandline?.is_a? Array
    _ = commandline?.first
  else
    _ = commandline?
  end
  if commandline?
    case _ # case tag
    # ===================================================================== #
    # === generate
    # ===================================================================== #
    when 'generate'
      generate_cgi_file(commandline?[1])
    else
      if _.end_with?('.cgi','.rb')
        generate_cgi_file(_)
      end
    end
  end
end

#resetObject

#

reset (reset tag)

#


102
103
104
105
106
107
108
109
# File 'lib/cyberweb/generator/cgi.rb', line 102

def reset
  super()
  # ======================================================================= #
  # === @title_of_page
  # ======================================================================= #
  @title_of_page = ''.dup # Will be empty initially.
  @default_page_content = DEFAULT_PAGE_CONTENT
end

#runObject

#

run (run tag)

#


218
219
220
# File 'lib/cyberweb/generator/cgi.rb', line 218

def run
  process_commandline
end

#set_commandline(i = '') ⇒ Object

#

set_commandline

#


114
115
116
# File 'lib/cyberweb/generator/cgi.rb', line 114

def set_commandline(i = '')
  @commandline = i
end

#title_of_page?Boolean Also known as: title?

#

title_of_page?

#

Returns:

  • (Boolean)


154
155
156
# File 'lib/cyberweb/generator/cgi.rb', line 154

def title_of_page?
  @title_of_page
end

#update_default_page_contentObject

#

update_default_page_content

This method will generate and assign the default skeleton for a webpage to the instance variable @default_page_content.

#


171
172
173
174
175
176
177
# File 'lib/cyberweb/generator/cgi.rb', line 171

def update_default_page_content
  # ======================================================================= #
  # The first argument will be the title of the .cgi file at hand.
  # ======================================================================= #
  @default_page_content =
    Cyberweb::Generator::CGI.generate_default_skeleton_for_webpage(title?) # Assign it here.
end