Class: Cyberweb::CreateStandaloneHtmlPage

Inherits:
Base
  • Object
show all
Defined in:
lib/cyberweb/utility_scripts/create_standalone_html_page.rb

Overview

Cyberweb::CreateStandaloneHtmlPage

Constant Summary

Constants inherited from Base

Base::HOME_DIRECTORY_OF_THE_USER_X, Base::NAMESPACE

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, #opnn, #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) ⇒ CreateStandaloneHtmlPage

#

initialize

#


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cyberweb/utility_scripts/create_standalone_html_page.rb', line 32

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  case run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    run_already = false
  end
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_open_via_the_browser
    # ===================================================================== #
    when :do_not_open_via_the_browser
      do_not_open_via_the_browser
    end
  end
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Cyberweb::CreateStandaloneHtmlPage[]

#


202
203
204
# File 'lib/cyberweb/utility_scripts/create_standalone_html_page.rb', line 202

def self.[](i = '')
  new(i)
end

Instance Method Details

#create_the_html_file_using_this_dataset(dataset, into = :infer) ⇒ Object

#

create_the_html_file_using_this_dataset

#


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cyberweb/utility_scripts/create_standalone_html_page.rb', line 110

def create_the_html_file_using_this_dataset(
    dataset,
    into = :infer
  )
  case into
  # ======================================================================= #
  # === :infer
  # ======================================================================= #
  when :infer,
       :default
    into = @store_into_this_base_directory+
           File.basename(@work_on_this_file).
           delete_suffix('.cgi')+'.html'
  end
  what = dataset
  e 'Saving into '+sfile(into)+' next.'
  write_what_into(what, into)
  if is_on_roebe? and
    @shall_we_try_to_open_the_autogenerated_file_after_it_has_been_created
    require 'open'
    Open.in_browser(into)
  end
end

#do_not_open_via_the_browserObject

#

do_not_open_via_the_browser

#


85
86
87
# File 'lib/cyberweb/utility_scripts/create_standalone_html_page.rb', line 85

def do_not_open_via_the_browser
  @shall_we_try_to_open_the_autogenerated_file_after_it_has_been_created = false
end

#resetObject

#

reset (reset tag)

#


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cyberweb/utility_scripts/create_standalone_html_page.rb', line 63

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @shall_we_try_to_open_the_autogenerated_file_after_it_has_been_created
  #
  # The following variable is only respected on is-roebe systems.
  # ======================================================================= #
  @shall_we_try_to_open_the_autogenerated_file_after_it_has_been_created = true
  # ======================================================================= #
  # === @shall_we_create_a_subdirectory_and_copy_the_image_files
  #
  # If the following variable is set to true then we will create a
  # subdirectory and then copy all these images.
  # ======================================================================= #
  @shall_we_create_a_subdirectory_and_copy_the_image_files = true
  set_store_into_this_base_directory
end

#runObject

#

run (run tag)

#


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/cyberweb/utility_scripts/create_standalone_html_page.rb', line 137

def run
  begin
    require 'image_paradise/utility_scripts/image_gallery/image_gallery.rb'
  rescue LoadError; end
  @start_dir = return_pwd
  # @work_on_this_file = File.basename(first_argument?.dup)
  @work_on_this_file = rds(
    first_argument?.dup
  ).dup
  absolute_path = File.absolute_path(@work_on_this_file).
                  gsub(
                    Regexp.quote('/home/x/'),''
                  )
  use_this_url = 'http://localhost/'+absolute_path
  puts ::Colours.rev+
       'Working on the file '+steelblue(@work_on_this_file)+
       ' next. The URL that will be used is: '
  puts
  puts ::Colours.steelblue(use_this_url)
  puts
  data = URI.open(use_this_url).read
  puts 'Next the .html file will be created.'
  use_this_as_the_filename = :infer
  if @shall_we_create_a_subdirectory_and_copy_the_image_files
    name_of_the_subdirectory = use_this_url # This will be like "http://localhost/data/images/fotos/responsive_image_gallery.cgi".
    # Next we must distinguish between URLs that have a '?'
    # and those that do not.
    if name_of_the_subdirectory.include?('?')
      name_of_the_subdirectory = name_of_the_subdirectory.split('?').last.to_s+'/'
    else
      name_of_the_subdirectory = File.basename(name_of_the_subdirectory).delete_suffix('.cgi')+'/'
    end
    replacement_value = ::ImageParadise::ImageGallery.modify_this_key(
      name_of_the_subdirectory.delete('/')
    )
    # Add an exception for the base directory next:
    if replacement_value == 'responsive_image_gallery'
      replacement_value = ''
    end
    real_absolute_target = '/home/x/data/images/fotos/'+
                           replacement_value
    if replacement_value.empty?
      name_of_the_subdirectory = 'responsive_image_gallery'
    else
      name_of_the_subdirectory = File.basename(replacement_value)
    end
    use_this_as_the_filename = name_of_the_subdirectory+'.html'
    unless File.directory?(name_of_the_subdirectory)
      puts 'Creating the subdirectory '+
           ::Colours.royalblue(name_of_the_subdirectory)+' next.'
      mkdir(name_of_the_subdirectory)
    end
    cd(name_of_the_subdirectory)
    all_images = Dir[real_absolute_target+'**/**'].select {|entry|
      is_an_image?(entry)
    }
    cpr(all_images, return_pwd)
    cd(start_dir?)
  end
  create_the_html_file_using_this_dataset(data, use_this_as_the_filename)
end

#set_store_into_this_base_directory(i = return_pwd) ⇒ Object

#

set_store_into_this_base_directory

#


92
93
94
95
96
97
98
# File 'lib/cyberweb/utility_scripts/create_standalone_html_page.rb', line 92

def set_store_into_this_base_directory(i = return_pwd)
  i = i.dup if i.frozen?
  unless i.end_with?('/')
    i << '/'
  end
  @store_into_this_base_directory = i
end

#start_dir?Boolean

#

start_dir?

#

Returns:

  • (Boolean)


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

def start_dir?
  @start_dir
end