Module: AsciiParadise::EmbeddableInterface

Defined in:
lib/ascii_paradise/www/embeddable_interface.rb

Overview

AsciiParadise::EmbeddableInterface

Constant Summary collapse

RUN_N_TIMES =
#

RUN_N_TIMES

#
15
N_DELAY_IN_MS_TO_USE =
#

N_DELAY_IN_MS_TO_USE

#
100

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.return_sinatra_animated_ascii_with_arguments(i = web_params_as_string? ) ⇒ Object

#

AsciiParadise::EmbeddableInterface.return_sinatra_animated_ascii_with_arguments

#


49
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ascii_paradise/www/embeddable_interface.rb', line 49

def self.return_sinatra_animated_ascii_with_arguments(
    i = web_params_as_string?
  )
  i = i.dup if i.frozen?
  # ======================================================================= #
  # Obtain the raw dataset via AsciiParadise.obtain_dataset_for() next.
  # ======================================================================= #
  dataset = AsciiParadise.obtain_dataset_for(i)
  # ======================================================================= #
  # Build up our return String next.
  # ======================================================================= #
  _ = '<html><head>'.dup
  _ << '<script>

/* The original dataset that was used is: '+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

.routes?Boolean

#

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.

#

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/ascii_paradise/www/embeddable_interface.rb', line 31

def self.routes?
  [
    'n_animated_ascii_components',
    'animated_ascii',
    'animated_ascii/*'
  ]
end

Instance Method Details

#return_sinatra_animated_asciiObject

#

return_sinatra_animated_ascii

#


112
113
114
# File 'lib/ascii_paradise/www/embeddable_interface.rb', line 112

def return_sinatra_animated_ascii
  'Please supply the name of the animated ASCII component.'
end

#return_sinatra_animated_ascii_with_arguments(i) ⇒ Object

#

return_sinatra_animated_ascii_with_arguments

#


42
43
44
# File 'lib/ascii_paradise/www/embeddable_interface.rb', line 42

def return_sinatra_animated_ascii_with_arguments(i)
  AsciiParadise::EmbeddableInterface.return_sinatra_animated_ascii_with_arguments(i)
end

#return_sinatra_n_animated_ascii_componentsObject

#

return_sinatra_n_animated_ascii_components

#


119
120
121
122
123
124
125
# File 'lib/ascii_paradise/www/embeddable_interface.rb', line 119

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