class RBT::Cookbooks::GenerateHomepage

Constants

BR
#

BR

#
LJUST
#

LJUST

#
USE_THIS_DIRECTORY
#

USE_THIS_DIRECTORY

#

Public Class Methods

[](i = '') click to toggle source
#

RBT::Cookbooks::GenerateHomepage[]

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 419
def self.[](i = '')
  self.new(i)
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/generate_homepage/initialize.rb, line 16
def initialize(
    i           = nil,
    run_already = true
  )
  register_sigint
  reset
  set_input(i)
  run if run_already
end

Public Instance Methods

_(i) click to toggle source
#

i

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 123
def _(i)
  i = i.to_s.dup
  @string << "#{i}#{N}"
end
a(i, optional_arguments = nil) click to toggle source
#

a

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 209
def a(i, optional_arguments = nil)
  if optional_arguments
    result = HtmlTags.a(i, optional_arguments)
  else
    result = HtmlTags.a(i)
  end
  if result.nil?
    opnn; e 'The result for '+i.to_s+' is nil.'
  end
  return result
end
br() click to toggle source
#

br

#
# File lib/rbt/utility_scripts/generate_homepage/html_tags.rb, line 21
def br
  BR
end
cdiv() click to toggle source
#

cdiv

#
# File lib/rbt/utility_scripts/generate_homepage/html_tags.rb, line 35
def cdiv
  HtmlTags.cdiv
end
cookbooks_include_this_program?(i) click to toggle source
#

cookbooks_include_this_program?

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 202
def cookbooks_include_this_program?(i)
  RBT.does_include?(i)
end
current_time() click to toggle source
#

current_time

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 156
def current_time
  return_day_month_year+' '+return_hours_minutes_seconds
end
data?()
Alias for: dataset?
dataset?() click to toggle source
#

dataset?

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 224
def dataset?
  @dataset
end
Also aliased as: data?
feedback_where_to_store() click to toggle source
#

feedback_where_to_store

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 231
def feedback_where_to_store
  opnn; e 'We will store in the directory `'+sdir(store_where?)+'`.'
end
file_location?() click to toggle source
#

file_location?

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 195
def file_location?
  @file_location
end
generate_a_webpage_for_this_program(program, index) click to toggle source
#

generate_a_webpage_for_this_program

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 238
def generate_a_webpage_for_this_program(program, index)
  obtain_dataset_for(program)
  # ======================================================================= #
  # Ok now we have the dataset. Start to build up the html page.
  # ======================================================================= #
  program_name        = dataset?.program_name?
  program_version     = dataset?.program_version?
  short_name          = dataset?.real_short_name?
  url1                = dataset?.url1?
  url2                = dataset?.url2?
  size                = dataset?.size?
  md5sum              = dataset?.md5sum
  deps                = dataset?.deps?
  extra_information   = dataset?.extra_information?.strip
  blfs_entry          = dataset?.blfs?
  if extra_information.start_with? '"'
    extra_information[0,1] = ''
  end
  if extra_information.end_with? '"'
    extra_information.chop!
    extra_information.strip!
  end
  binaries            = dataset?.binaries?.join(', ').strip.chop
  libraries           = dataset?.libraries?.join(', ').strip.chop
  the_program_before  = @array_available_programs[index-1]
  the_next_program_is = @array_available_programs[index+1]
  opnn; e 'Working on the program `'+slateblue(program.to_s.ljust(LJUST))+
          '` next (Version: '+royalblue(program_version.to_s.rjust(10))+').'
  _ '<html>'
  _ HtmlTags.title(program_name)
  # ======================================================================= #
  # Next, define some basic CSS style
  # ======================================================================= #
  _ '<style>
     div.top_navigation {
       background: #ecedef;
       margin:  0;
       padding: 0.3em .5em;
       border: 1px solid black;
     }
     pre {
       font-size: larger;
     }
     </style>'
  _ '<body>'
  # ======================================================================= #
  # === The top header
  # ======================================================================= #
  _ '<div class="top_navigation">'
  _ HtmlTags.h1(short_name)
  _ cdiv
  _ '<h2>Introduction to '+short_name.capitalize+'</h2>'
  what = @string
  into = use_this_directory+short_name.downcase+'.html'
  set_file_location(into)
  # ======================================================================= #
  # Next add the program description:
  # ======================================================================= #
  dataset_as_pre_tag = HtmlTags.pre(dataset?.raw_description?)
  _ HtmlTags.p(dataset_as_pre_tag,'','','margin-left:2em')
  # ======================================================================= #
  # Show the extra information next.              (extra information tag)
  # ======================================================================= #
  unless extra_information.empty?
    _ '<h3>Extra information</h3>'
    formatted_extra_information = extra_information.gsub(/#{N}/,'<br>')
    _ HtmlTags.p(formatted_extra_information,
        '','','margin-left:2.5em'
      )
  end
  # ======================================================================= #
  # Next, the "Package Information" subsection follows:
  # ======================================================================= #
  _ HtmlTags.h3('Package Information')
  _ "This program is available at the following URL:#{br}#{br}"
  _ '<p>'
  _ a(url1, css_style: 'margin-left:2em; margin-top:1em; padding:1.5em; border: 1px solid darkblue;
     font-weight:800; background-color: #f0fff0;')+br+br
  if url2
    _ BR
    _ 'Additionally, this is most likely another good URL resource:'+br+br
    _ a(url2, css_style: 'margin-left:2em; font-weight:800;')
  end
  _ '</p>'
  _ '<ul>'
  _ '<li><p><b>MD5-sum:</b> '+md5sum.to_s+' </p></li>'
  use_this_size = (size.to_f / 1024 / 1024).round(5).to_s
  _ '<li><p><b>Download size:</b> '+use_this_size+' MB </p></li>'
  _ '</ul>'
  # ======================================================================= #
  # === Dependencies
  #
  # We will next provide a link to the other dependencies.
  # ======================================================================= #
  unless deps.empty?
    _ '<h4>Dependencies for the project <b>'+program_name+':</h4>'
    _ p # Paragraph.
      deps.each {|dependency|
        _ HtmlTags.span(dependency, style: 'margin-left: 3em')
        _ ' -> '
        _ HtmlTags.a(dependency+'.html') 
        _ br
      }
    _ '</p>'
  end
  # ======================================================================= #
  # === BLFS subsection
  #
  # We add a link to the remote LFS/BLFS entry, should it exist.
  # ======================================================================= #
  unless blfs_entry.empty?
    _ '<div style="margin-bottom:2px">'
    _ '<h4>the LFS/BLFS entry can be seen here:</h4>'
    _ HtmlTags.a(blfs_entry.first, style: 'margin-left:3em') 
    _ '</div>'
  end 
  # ======================================================================= #
  # === Contents
  #
  # Add the contents subsection next.
  # ======================================================================= #
  _ '<div style="margin-bottom:1em">'
  _ '  <h3>Content</h3>'
  unless binaries.to_s.empty?
    _ '  <b style="margin-left:2em">Installed Programs:</b> '+binaries.to_s+'<br>'
  end
  unless libraries.to_s.empty?
    _ '  <b style="margin-left:2em">Installed Libraries:</b> '+libraries.to_s+'<br>'
  end
  # ======================================================================= #
  # We don't track installed directories as of yet.
  # ======================================================================= #
  _ '  <b style="margin-left:2em">Installed Directories: (Not yet implemented)</b><br>'
  _ '</div>'
  # ======================================================================= #
  # Add the next and previous program to the chain. These are links
  # that the user can click on.
  # ======================================================================= #
  begin
    if the_program_before
      _ a(the_program_before+'.html')
      _ ' | ' # Add a separator.
    end
    _ a(the_next_program_is+'.html')
  rescue NoMethodError; end # Do a silent rescue though.
  _ br+br+'<i>This file was autogenerated at <b>'+current_time+'</b></i>'
  _ '</body></html>'
  write_what_into(what, into)
  reset_string
end
generate_all_webpages() click to toggle source
#

generate_all_webpages

This method will generate all the various .html webpages.

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 394
def generate_all_webpages
  notify_the_user_how_we_will_start
  # ======================================================================= #
  # We must create the directory if it does not yet exist.
  # ======================================================================= #
  unless File.directory? use_this_directory
    mkdir(use_this_directory)
  end
  # ======================================================================= #
  # cd into that directory.
  # ======================================================================= #
  opnn; cd use_this_directory
  # ======================================================================= #
  # Ok, next we iterate over all programs:
  # ======================================================================= #
  @array_available_programs = available_programs?
  @array_available_programs.each_with_index {|program, index|
    generate_a_webpage_for_this_program(program, index)
  }
  report_where_there_file_is
end
input?() click to toggle source
#

input?

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 116
def input?
  @input
end
notify_the_user_how_we_will_start() click to toggle source
#

notify_the_user_how_we_will_start

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 147
def notify_the_user_how_we_will_start
  opnn; e 'Now generating a '+slateblue('LFS-like homepage')+'.'
  opnn; e 'We will use this directory as our base directory:'
  opnn; e '  '+sdir(use_this_directory)
end
obtain_dataset_for(i) click to toggle source
#

obtain_dataset_for

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 131
def obtain_dataset_for(i)
  i = RBT::Cookbooks::Cookbook.new(i) { :bypass_menu }
  @dataset = i
end
p() click to toggle source
#

p

#
# File lib/rbt/utility_scripts/generate_homepage/html_tags.rb, line 28
def p
  HtmlTags.p
end
report_where_there_file_is(i = @file_location) click to toggle source
#

report_where_there_file_is

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 184
def report_where_there_file_is(i = @file_location)
  where = (File.dirname(i)+'/').squeeze('/')
  opnn; e 'The files are now available at'
  e
  opnn; e '  `'+sdir(where)+'`.'
  e
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 60
def reset
  super()
  @namespace = NAMESPACE[:namespace]+'::GenerateHomepage'
  reset_string
  set_file_location # Initialize with a default value.
end
reset_string() click to toggle source
#

reset_string

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 70
def reset_string
  @string = ''.dup
end
return_day_month_year() click to toggle source
#

return_day_month_year

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 170
def return_day_month_year
  Time.now.strftime('%d.%m.%Y') # => '13.12.2015
end
return_hours_minutes_seconds() click to toggle source
#

return_hours_minutes_seconds

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 163
def return_hours_minutes_seconds
  Time.now.strftime('%H:%M:%S') # => '05:44:39'
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/generate_homepage/run.rb, line 16
def run
  # ======================================================================= #
  # The next if-clause is valid for when the user did input a program
  # name such as 'ruby'.
  # ======================================================================= #
  if input? and
     cookbooks_include_this_program?(input?.sub(/\.yml$/,''))
    _ = "#{File.dirname(file_location?)}/#{input?}.html"
    XorgBuffer[_] if Object.const_defined? :XorgBuffer
    if Object.const_defined? :OpenInBrowser
      opnn; e "Next opening `#{simp(_)}` in a browser tab."
      OpenInBrowser[_] # We open it in the browser as well.
    end
  else
    generate_all_webpages # This will generate all the various individual .html files.
  end
end
set_file_location(i = use_this_directory+'ruby.html') click to toggle source
#

set_file_location

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 177
def set_file_location(i = use_this_directory+'ruby.html')
  @file_location = i
end
set_input(i = '') click to toggle source
#

set_input

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 92
def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup if i
  case i # case tag
  # ======================================================================= #
  # === genhomepage --l?
  # ======================================================================= #
  when '--location?','--location','--l?',
       'LOCATION','WHERE'
    feedback_where_to_store
    exit
  # ======================================================================= #
  # === genhomepage --help
  # ======================================================================= #
  when '--help','HELP'
    show_help
    exit
  end
  @input = i
end
show_help() click to toggle source
#

show_help

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 77
def show_help
  e
  e 'Currently this class responds to these instructions:'
  e
  ecomment '  ['+sfancy('name')+'] # Give the name of the program '\
           'you wish to open in a browser tab.'
  e
  ecomment '         # No argument - this is the default way to invoke it.'
  ecomment '         # In this case, we will generate a lot of .html files.'
  e
end
store_where?()
Alias for: use_this_directory?
use_this_directory()
Alias for: use_this_directory?
use_this_directory?() click to toggle source
#

use_this_directory?

#
# File lib/rbt/utility_scripts/generate_homepage/generate_homepage.rb, line 139
def use_this_directory?
  USE_THIS_DIRECTORY
end
Also aliased as: use_this_directory, store_where?