Class: Cyberweb::HtmlToCyberwebConverter
- Inherits:
-
Base
- Object
- Base
- Cyberweb::HtmlToCyberwebConverter
show all
- Defined in:
- lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb
Overview
Cyberweb::HtmlToCyberwebConverter
Constant Summary
collapse
- NAMESPACE =
inspect
Constants inherited
from Base
Base::HOME_DIRECTORY_OF_THE_USER_X
Class Method Summary
collapse
-
.[](i = '') ⇒ Object
# === Cyberweb::HtmlToCyberwebConverter[] ========================================================================= #.
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?
#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
#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text
#append_to_the_commandline_arguments, #commandline_arguments?, #first_argument?, #parse_these_commandline_arguments, #second_argument?, #set_commandline_arguments
#all_html_colours, #lightgreen, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ HtmlToCyberwebConverter
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 39
def initialize(
commandline_arguments = nil,
run_already = true
)
reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Class Method Details
.[](i = '') ⇒ Object
#
Cyberweb::HtmlToCyberwebConverter[]
#
227
228
229
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 227
def self.[](i = '')
new(i)
end
|
Instance Method Details
#body?(use_this_regex = /<body>([0-9A-Za-z\s?!\/<>]+)<\/body>/, dataset = dataset?
) ⇒ Boolean
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 180
def body?(
use_this_regex = /<body>([0-9A-Za-z\s?!\/<>]+)<\/body>/, dataset = dataset?
)
unless dataset.include? '</body>'
e 'Warning (notice): the input data contains no closing </body> tag.'
end
scanned = dataset.scan(
use_this_regex
)
result = scanned.flatten.first.to_s
if result.start_with?("\n")
result[0,1] = ''
end
if result.end_with?("\n")
result[-1,1] = ''
end
return result
end
|
#cyberweb_object? ⇒ Boolean
Also known as:
cyberweb_object, cyberweb?
77
78
79
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 77
def cyberweb_object?
@internal_hash[:cyberweb_object]
end
|
#dataset? ⇒ Boolean
132
133
134
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 132
def dataset?
@internal_hash[:dataset]
end
|
#infer_the_new_name_from_the_path ⇒ Object
#
infer_the_new_name_from_the_path
#
164
165
166
167
168
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 164
def infer_the_new_name_from_the_path
_ = @internal_hash[:path_to_the_html_file]
_ = 'new_'+File.basename(_)
return _
end
|
#look_for_the_body_tag(in_which_dataset = dataset?,
, regex_to_use = /<body>([A-Za-z\?\s]+)<\/body>/) ⇒ Object
#
look_for_the_body_tag
#
119
120
121
122
123
124
125
126
127
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 119
def look_for_the_body_tag(
in_which_dataset = dataset?,
regex_to_use = /<body>([A-Za-z\?\s]+)<\/body>/ )
in_which_dataset =~ regex_to_use
if $1 and !$1.to_s.empty?
set_title($1.to_s)
end
end
|
#look_for_the_title(in_which_dataset = dataset?,
, regex_to_use = /<title>([A-Za-z\?\s]+)<\/title>/) ⇒ Object
106
107
108
109
110
111
112
113
114
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 106
def look_for_the_title(
in_which_dataset = dataset?,
regex_to_use = /<title>([A-Za-z\?\s]+)<\/title>/ )
in_which_dataset =~ regex_to_use
if $1 and !$1.to_s.empty?
set_title($1.to_s)
end
end
|
#path_to_the_html_file? ⇒ Boolean
#
path_to_the_html_file?
#
157
158
159
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 157
def path_to_the_html_file?
@internal_hash[:path_to_the_html_file]
end
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 53
def reset
super()
set_commandline_mode
@namespace = NAMESPACE
@internal_hash = {}
@internal_hash[:path_to_the_html_file] = nil
@internal_hash[:cyberweb_object] = Cyberweb::WebObject.new
end
|
218
219
220
221
222
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 218
def run
set_work_on_this_html_file(first?)
try_to_parse_the_html_file
save_into_a_new_html_file
end
|
#save_into_a_new_html_file ⇒ Object
#
save_into_a_new_html_file
#
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 203
def save_into_a_new_html_file
what = Cyberweb::HtmlTemplate[
title: title?.strip,
body: body?
].to_s
into = infer_the_new_name_from_the_path
e 'Storing into `'+sfile(into)+'` next.'
write_what_into(what, into)
end
|
#set_dataset(i) ⇒ Object
139
140
141
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 139
def set_dataset(i)
@internal_hash[:dataset] = i
end
|
#set_path_to_the_html_file(i) ⇒ Object
Also known as:
set_work_on_this_html_file
#
set_path_to_the_html_file
#
146
147
148
149
150
151
152
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 146
def set_path_to_the_html_file(i)
if i.is_a? Array
i = i.first
end
i = File.absolute_path(i)
@internal_hash[:path_to_the_html_file] = i
end
|
#set_title(i) ⇒ Object
85
86
87
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 85
def set_title(i)
cyberweb_object?.set_title(i)
end
|
#title? ⇒ Boolean
173
174
175
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 173
def title?
cyberweb_object?.title?
end
|
#try_to_parse_the_html_file ⇒ Object
#
try_to_parse_the_html_file
#
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/cyberweb/utility_scripts/html_to_cyberweb_converter.rb', line 92
def try_to_parse_the_html_file
_ = @internal_hash[:path_to_the_html_file].to_s
if _ and File.exist?(_)
set_dataset(File.read(_))
look_for_the_title
look_for_the_body_tag
else
e "No file exists at `#{_}`."
end
end
|