class Entityjs::Dirc
Public Class Methods
change_dir(name)
click to toggle source
# File lib/entityjs/dirc.rb, line 202 def self.change_dir(name) Dir.chdir(Dir.pwd+'/'+name) end
copy_config(name)
click to toggle source
# File lib/entityjs/dirc.rb, line 247 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 231 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 216 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 227 def self.create_file(name, contents) File.open(name, "w+") {|f| f.write(contents)} end
exists?(file)
click to toggle source
checks if file exists in the EntityJS game
# File lib/entityjs/dirc.rb, line 24 def self.exists?(file) return File.file? Dirc.game_root+'/'+file end
find_entity_src(ignore=nil)
click to toggle source
# File lib/entityjs/dirc.rb, line 174 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 97 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 148 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 138 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 106 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)
click to toggle source
returns all game scripts with short paths
# File lib/entityjs/dirc.rb, line 77 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 87 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 37 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 49 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)
click to toggle source
# File lib/entityjs/dirc.rb, line 60 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?()
click to toggle source
is the current directory an EntityJS game?
# File lib/entityjs/dirc.rb, line 9 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()
click to toggle source
# File lib/entityjs/dirc.rb, line 33 def self.game_root @game_root end
get_root(path)
click to toggle source
# File lib/entityjs/dirc.rb, line 206 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()
click to toggle source
path to EntityJS game
# File lib/entityjs/dirc.rb, line 29 def self.to_game_root Dir.chdir(@game_root) end