Class: Entityjs::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/entityjs/commands/font.rb

Class Method Summary collapse

Class Method Details

.generate(name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/entityjs/commands/font.rb', line 5

def self.generate(name)
  if !Dirc.game?
    return 2
  end
  puts 'not implemented yet'
  return 0
  
  tests = []
  
  if name.class == Array
    tests = name[1..-1]
    
    name = name.first
  end
  
  #remove extra slash
  if name[0] == '/'
    name = name[1..-1]
  end
  
  filename = name
  if name.index('.').nil?
    filename += '_test.js'
  end
  
  dir = Config.tests_folder
  
  Dirc.change_dir(dir)
  
  #create folder if they don't exist
  folders = filename.split('/')
  filename = folders.pop
  
  if folders.size > 0
    folders.each do |i|
      if !Dir.exists?(i)
        Dir.mkdir(i)
      end
      
      Dirc.change_dir(i)
    end
    
  end
  
  if File.exists?(filename)
    return 3
  end
  
  File.open(filename, 'w') do |f|
    
    f.write("module('#{name}');")
    
    tests.each do |i|
      f.write("\n\ntest('#{i}', function(){\n\t\n\t\n\t\n});")
    end
    
    f.close
  end
  
  puts "Created test: tests/#{filename}"
  
  Dir.chdir(Dirc.game_root)
  
  return 0
end