module AsciiParadise::EmbeddableInterface

Constants

N_DELAY_IN_MS_TO_USE
#

N_DELAY_IN_MS_TO_USE

#
RUN_N_TIMES
#

RUN_N_TIMES

#

Public Class Methods

routes?() click to toggle source
#

AsciiParadise::EmbeddableInterface.routes?

Define all legal routes via this Array. This Array will then be used to add more routes to any sinatra-application that needs it.

#
# File lib/ascii_paradise/www/embeddable_interface.rb, line 30
def self.routes?
  [
    'n_animated_ascii_components',
    'animated_ascii',
    'animated_ascii/*'
  ]
end

Public Instance Methods

return_sinatra_animated_ascii() click to toggle source
#

return_sinatra_animated_ascii

#
# File lib/ascii_paradise/www/embeddable_interface.rb, line 103
def return_sinatra_animated_ascii
  'Please supply the name of the animated ASCII component.'
end
return_sinatra_animated_ascii_with_arguments( i = web_params_as_string? ) click to toggle source
#

return_sinatra_animated_ascii

#
# File lib/ascii_paradise/www/embeddable_interface.rb, line 41
  def return_sinatra_animated_ascii_with_arguments(
      i = web_params_as_string?
    )
    i = i.dup if i.frozen?
    # ======================================================================= #
    # Get all available ASCII components into an Array.
    # ======================================================================= #
    # array = AsciiParadise.available_ascii_components?
    # sample = array.sample
    dataset = AsciiParadise.obtain_dataset_for(i) # sample)
    _ = '<html><head>'.dup
    _ << '<script>

/* Dataset used: '+i.to_s+' */

const dataset = ['

dataset.each {|entry|
  entry = entry.dup
  entry.gsub!("\\", "\\\\\\") # Replace \ with \\.
  _ << '`'+entry+'`,'
}
_.strip!
_.chop!
_ << '];

function set_body_content(i) {
  document.body.innerHTML = i;
}

async function do_loop() {
  let outer_loop = 0
  while(outer_loop < '+RUN_N_TIMES.to_s+') {
    let i = 0;
    while (i < dataset.length) {
      set_body_content(
        "<pre>"+dataset[i]+"</pre>"
      )
      i += 1;
      await new Promise(r => setTimeout(r, '+N_DELAY_IN_MS_TO_USE.to_s+'));
    }
    outer_loop += 1;
  }
}

</script>
</head><body>
<h2>Showcasing animated ASCII components next.</h2>
'
    _ <<  '</body>

<script>
do_loop()
</script>

</html>'
    return _
  end
return_sinatra_n_animated_ascii_components() click to toggle source
#

return_sinatra_n_animated_ascii_components

#
# File lib/ascii_paradise/www/embeddable_interface.rb, line 110
def return_sinatra_n_animated_ascii_components
  n_components = AsciiParadise.n_animated_ascii_components?.size
  _ = ''.dup
  _ << 'There are '+n_components.to_s+' registered, animated ASCII '\
       'components available as part of the ascii_paradise gem.'
  return _
end