Module: Asciimo

Defined in:
lib/asciimo.rb

Defined Under Namespace

Classes: JQuery

Constant Summary collapse

VERSION =
"0.2.0"
HOME =
File.expand_path(File.join(File.dirname(__FILE__), "..", "ext", "asciimo"))
LIB =
File.join(HOME, "lib")
FONTS =
File.join(HOME, "fonts")

Class Method Summary collapse

Class Method Details

.colorsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/asciimo.rb', line 30

def colors
  #TODO figure out a way to load this from the JS source.
  [
    'bold',
    'italic',
    'underline',
    'yellow',
    'cyan',
    'white',
    'green',
    'red',
    'grey',
    'blue',
    'magenta',
    'inverse'
  ]
end

.fontsObject



23
24
25
26
27
28
# File 'lib/asciimo.rb', line 23

def fonts
  cxt = V8::Context.new
  figlet = cxt['Figlet'] = cxt['Object'].new
  cxt.load("#{LIB}/fonts.js")
  figlet.fontList.to_a
end

.text(font, text, color = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/asciimo.rb', line 9

def text(font, text, color = nil)
  cxt = V8::Context.new
  asciimo = cxt.scope
  asciimo['window'] = asciimo
  asciimo['$'] = JQuery.new
  cxt.load("#{LIB}/asciimo.js")
  cxt.load("#{LIB}/colors.js")

  ascii = nil
  asciimo.Figlet.write(text, font, proc {|result| ascii = result})

  return color ? asciimo.stylize(ascii, color) : ascii
end