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
-
.exists?(file) ⇒ Boolean
checks if a local file exists.
- .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_styles(ignore = nil) ⇒ Object
- .find_styles_url(ignore = 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
201 202 203 |
# File 'lib/entityjs/dirc.rb', line 201 def self.change_dir(name) Dir.chdir(Dir.pwd+'/'+name) end |
.copy_config(name) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/entityjs/dirc.rb', line 246 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
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/entityjs/dirc.rb', line 230 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
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/entityjs/dirc.rb', line 215 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
226 227 228 |
# File 'lib/entityjs/dirc.rb', line 226 def self.create_file(name, contents) File.open(name, "w+") {|f| f.write(contents)} end |
.exists?(file) ⇒ Boolean
checks if a local file exists
23 24 25 |
# File 'lib/entityjs/dirc.rb', line 23 def self.exists?(file) return File.file? Dirc.game_root+'/'+file end |
.find_entity_src(ignore = nil) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/entityjs/dirc.rb', line 173 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
96 97 98 99 100 101 102 103 |
# File 'lib/entityjs/dirc.rb', line 96 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
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 147 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
137 138 139 140 141 142 143 144 145 |
# File 'lib/entityjs/dirc.rb', line 137 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
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/entityjs/dirc.rb', line 105 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
76 77 78 79 80 81 82 83 84 |
# File 'lib/entityjs/dirc.rb', line 76 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
86 87 88 89 90 91 92 93 94 |
# File 'lib/entityjs/dirc.rb', line 86 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_styles(ignore = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/entityjs/dirc.rb', line 36 def self.find_styles(ignore=nil) ignore ||= [] styles = Dir["#{Dirc.game_root}/#{Config.styles_folder}/**/*.css"].sort if ignore.any? styles.delete_if {|i| !i.match(/#{ignore.join('|')}/).nil?} end return styles end |
.find_styles_url(ignore = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/entityjs/dirc.rb', line 48 def self.find_styles_url(ignore=nil) styles = self.find_styles(ignore) #remove extra folders styles = styles.collect do |i| i[i.rindex(Config.styles_folder+'/')..-1] end return styles end |
.find_tests_url(ignore = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/entityjs/dirc.rb', line 59 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
31 32 33 34 |
# File 'lib/entityjs/dirc.rb', line 31 def self.game_root @game_root end |
.get_root(path) ⇒ Object
205 206 207 208 209 210 211 212 213 |
# File 'lib/entityjs/dirc.rb', line 205 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
27 28 29 |
# File 'lib/entityjs/dirc.rb', line 27 def self.to_game_root Dir.chdir(@game_root) end |