class Entityjs::Page
Public Class Methods
processor_ext()
click to toggle source
# File lib/entityjs/page.rb, line 6 def self.processor_ext return '.js' end
render_entityjs_src(path)
click to toggle source
# File lib/entityjs/page.rb, line 24 def self.render_entityjs_src(path) path = Entityjs::root+'/src/'+path return IO.read(path) end
render_eunit(path)
click to toggle source
# File lib/entityjs/page.rb, line 41 def self.render_eunit(path) IO.read(Entityjs::root+"/public/qunit/#{path}") end
render_favicon()
click to toggle source
# File lib/entityjs/page.rb, line 14 def self.render_favicon path = Entityjs::public_path+'/favicon.ico' return IO.read(path) end
render_play_page(ops={})
click to toggle source
# File lib/entityjs/page.rb, line 10 def self.render_play_page(ops={}) self.set_vars("play.html", ops) end
render_script(path)
click to toggle source
# File lib/entityjs/page.rb, line 36 def self.render_script(path) file = path.sub(/#{self.processor_ext}$/i, '') return Config.preprocess(Compile.script_to_js(file)) end
render_test(path)
click to toggle source
# File lib/entityjs/page.rb, line 30 def self.render_test(path) file = path.sub(/#{self.processor_ext}$/i, '') return Config.preprocess(Compile.test_to_js(file)) end
render_test_page()
click to toggle source
# File lib/entityjs/page.rb, line 20 def self.render_test_page self.set_vars('test.html', :tests=>true) end
Protected Class Methods
compile_css_html()
click to toggle source
# File lib/entityjs/page.rb, line 75 def self.compile_css_html styles_url = Dirc.find_styles_url(Config.instance.styles_ignore) css = '' styles_url.each do |s| css += "\t<link rel=\"stylesheet\" href=\"#{s}\" type=\"text/css\"/>\n" end return css end
compile_js_html(tests=false)
click to toggle source
compiles html js tags for render on webpage
# File lib/entityjs/page.rb, line 89 def self.compile_js_html(tests=false) tests ||= false js = %Q( <script type=\"text/javascript\"> window.addEventListener\(\"load\", function(){ #{Build.js_config} re.version = \"#{VERSION}\"; }\); </script> ) ent_ignore = Config.instance.entity_ignore srcs_ignore = Config.instance.scripts_ignore if tests ent_ignore += Config.instance.tests_entity_ignore srcs_ignore += Config.instance.tests_scripts_ignore end ent = Dirc.find_entity_src_url(ent_ignore) srcs = Dirc.find_scripts_url(srcs_ignore, Config.instance.scripts_order) if tests tests_src = Dirc.find_tests_url(Config.instance.tests_ignore) ent += Dirc.find_eunit_src_url else tests_src = [] end merg = ent | srcs | tests_src last = '' merg.each do |s| #output a divider for each js root folders = s.split('/') #remove file at the end folders.pop folders.join('/') first_folder = folders if last != first_folder if first_folder.is_a? Array line = first_folder.join('/') else line = first_folder end js += "\n\n\t<!-- #{line} -->\n" last = first_folder end #add processor extension to non-js files so the server processes it into js if !s.match(/^scripts\//).nil? #add processor to all files, because preprocessor needs it to activate s += self.processor_ext end js += "\t<script src=\"#{s}\" type=\"text/javascript\"></script>\n" end return js end
set_vars(path, ops={})
click to toggle source
# File lib/entityjs/page.rb, line 46 def self.set_vars(path, ops={}) #search locally first if Dirc::exists?(path) contents = IO.read(Dirc.game_root+'/'+path); else contents = IO.read("#{Entityjs::public_path}/#{path}") end contents = Config.preprocess(contents) #set javascript srcs if !ops[:js] js = self.compile_js_html(ops[:tests]) else js = ops[:js] end contents = contents.sub("RE_JS", js) #add css if !ops[:css] css = self.compile_css_html else css = ops[:css] end contents = contents.sub("RE_CSS", css) end