Class: Entityjs::Dirc
- Inherits:
-
Object
- Object
- Entityjs::Dirc
- Defined in:
- lib/entityjs/dirc.rb
Class Method Summary collapse
- .change_dir(name) ⇒ Object
- .copy_config(name) ⇒ Object
- .copy_file(name, new_name = nil) ⇒ Object
- .create_dir(name, move = false) ⇒ Object
- .create_file(name, contents) ⇒ Object
- .find_entity_src(ignore = nil) ⇒ Object
- .find_entity_src_url(ignore = nil) ⇒ Object
- .find_eunit_src(ignore = nil) ⇒ Object
- .find_eunit_src_url(ignore = nil) ⇒ Object
- .find_scripts(ignore = nil, order = nil) ⇒ Object
-
.find_scripts_short(ignore = nil, order = nil) ⇒ Object
returns all game scripts with short paths.
- .find_scripts_url(ignore = nil, order = nil) ⇒ Object
- .find_tests_url(ignore = nil) ⇒ Object
- .game? ⇒ Boolean
- .game_root ⇒ Object
- .get_root(path) ⇒ Object
- .to_game_root ⇒ Object
Class Method Details
.change_dir(name) ⇒ Object
173 174 175 |
# File 'lib/entityjs/dirc.rb', line 173 def self.change_dir(name) Dir.chdir(Dir.pwd+'/'+name) end |
.copy_config(name) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/entityjs/dirc.rb', line 218 def self.copy_config(name) self.copy_file('config.yml') f = File.open('config.yml', 'r') contents = f.read contents = contents.sub(/\$NAME/, name) File.open('config.yml', "w+") do |f| f.write(contents) end end |
.copy_file(name, new_name = nil) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/entityjs/dirc.rb', line 202 def self.copy_file(name, new_name=nil) if new_name.nil? new_name = name end template = self.get_root_path+'/lib/blank/'+name ::FileUtils.cp template, new_name path = "/#{name}" path = self.get_root(path) puts "Created: #{path}" end |
.create_dir(name, move = false) ⇒ Object
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/entityjs/dirc.rb', line 187 def self.create_dir(name, move=false) if !File.directory? name Dir.mkdir(name) end if move self.change_dir(name) end end |
.create_file(name, contents) ⇒ Object
198 199 200 |
# File 'lib/entityjs/dirc.rb', line 198 def self.create_file(name, contents) File.open(name, "w+") {|f| f.write(contents)} end |
.find_entity_src(ignore = nil) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/entityjs/dirc.rb', line 145 def self.find_entity_src(ignore=nil) ignore ||= [] ents = Dir[Entityjs::source_folder+"/**/*.js"] #sort by name ents.sort! #push re.js to the top i = ents.index{|i| i.match(/re\.js$/) } if i.nil? puts 'Error cannot find re.js!' return ents end k = ents.delete_at(i) ents.unshift(k) if ignore.any? ents.delete_if {|i| !i.match(/#{ignore.join('|')}/).nil? } end return ents end |
.find_entity_src_url(ignore = nil) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/entityjs/dirc.rb', line 68 def self.find_entity_src_url(ignore=nil) srcs = self.find_entity_src(ignore) #remove src directory and replace with entityjs srcs = srcs.collect{|k| k[k.rindex('src/')..-1].gsub('src', 'entityjs') } return srcs end |
.find_eunit_src(ignore = nil) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/entityjs/dirc.rb', line 119 def self.find_eunit_src(ignore=nil) ignore ||= [] ents = Dir[Entityjs::eunit_folder+"/**/*.js"].sort #make sure qunit is at the top i = ents.index{|i| i.match(/qunit\.js$/) } if i.nil? puts 'Error cannot find qunit.js!' return ents end #remove k = ents.delete_at(i) #push at front ents.unshift(k) if ignore.any? ents.delete_if {|i| !i.match(/#{ignore.join('|')}/).nil? } end return ents end |
.find_eunit_src_url(ignore = nil) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/entityjs/dirc.rb', line 109 def self.find_eunit_src_url(ignore=nil) srcs = self.find_eunit_src(ignore) #remove src directory and replace with entityjs srcs = srcs.collect{|k| k[k.rindex('qunit/')..-1] } return srcs end |
.find_scripts(ignore = nil, order = nil) ⇒ Object
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/entityjs/dirc.rb', line 77 def self.find_scripts(ignore=nil, order=nil) ignore ||= [] order ||= [] valids = Compile.valid_scripts.join(",") scripts = Dir["#{Dirc.game_root}/#{Config.scripts_folder}/**/*.{#{valids}}"].sort #sort again by extension scripts.sort! {|x,y| File.extname(x) <=> File.extname(y) } #ignore files if ignore.any? scripts = scripts.delete_if {|i| !i.match(/#{ignore.join('|')}/).nil? } end #order files order.reverse.each do |i| scripts.each do |s| if s.match /#{i}/ scripts.delete(s) scripts.unshift(s) end end end return scripts end |
.find_scripts_short(ignore = nil, order = nil) ⇒ Object
returns all game scripts with short paths
48 49 50 51 52 53 54 55 56 |
# File 'lib/entityjs/dirc.rb', line 48 def self.find_scripts_short(ignore=nil, order=nil) scripts = self.find_scripts_url(ignore, order) scripts.collect do |i| i.sub(Config.scripts_folder+'/', '') end end |
.find_scripts_url(ignore = nil, order = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/entityjs/dirc.rb', line 58 def self.find_scripts_url(ignore=nil, order=nil) scripts = self.find_scripts(ignore, order) #change filenames scripts = scripts.collect{|k| k[k.rindex(Config.scripts_folder+'/')..-1] } return scripts end |
.find_tests_url(ignore = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/entityjs/dirc.rb', line 31 def self.find_tests_url(ignore=nil) valids = Compile.valid_scripts.join(",") ignore ||= [] tests = Dir["#{Dirc.game_root}/#{Config.tests_folder}/**/*.{#{valids}}"].sort tests = tests.collect do |i| i[i.rindex(Config.tests_folder+'/')..-1] end if ignore.any? tests.delete_if {|i| !i.match(/#{ignore.join('|')}/).nil? } end return tests end |
.game? ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/entityjs/dirc.rb', line 8 def self.game? #check if scripts dir exists if File.directory? Config.scripts_folder if @game_root.nil? @game_root = Dir.pwd end return true end return false end |
.game_root ⇒ Object
26 27 28 29 |
# File 'lib/entityjs/dirc.rb', line 26 def self.game_root @game_root end |
.get_root(path) ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/entityjs/dirc.rb', line 177 def self.get_root(path) cut = Dir.pwd.split(root) if cut.length == 2 path = cut.pop+path end return path end |
.to_game_root ⇒ Object
22 23 24 |
# File 'lib/entityjs/dirc.rb', line 22 def self.to_game_root Dir.chdir(@game_root) end |