lib/spiderfw/templates/layout.rb in spiderfw-0.6.1 vs lib/spiderfw/templates/layout.rb in spiderfw-0.6.2

- old
+ new

@@ -247,10 +247,11 @@ app_path = app.path elsif path.index(Spider::SpiderController.pub_path) == 0 app_relative_path = 'spider' app_path = Spider::SpiderController.pub_path end + app_pathname = Pathname.new(app_path) pub_app = "#{pub_dest}/#{app_relative_path}" FileUtils.mkdir_p(pub_app) src_files = Spider::ContentUtils.resolve_css_includes(path) src = "" @@ -261,18 +262,24 @@ src.scan(/url\([\s"']*([^\)"'\s]*)[\s"']*\)/m).uniq.collect do |url| url = url.first next if url =~ %r{^/} || url =~ %r{^[a-z]+://} path = "" - url_dest = File.expand_path(File.join(pub_app, url)) url_src = File.expand_path(File.join(src_dir, url)) - unless url_src.index(app_path) == 0 + src_pathname = Pathname.new(url_src) + src_rel = nil + begin + src_rel = src_pathname.relative_path_from(app_pathname) + rescue ArgumentError raise "Can't combine CSS if paths go outside app: #{url} in #{path}" end + + url_dest = File.join(pub_app, src_rel.to_s) + FileUtils.mkdir_p(File.dirname(url_dest)) cachebuster = Spider.conf.get('css.cachebuster') - new_url = "#{app_relative_path}/#{url}" + new_url = "#{app_relative_path}/#{src_rel}" if File.exist?(url_src) mtime = File.mtime(url_src).to_i if cachebuster && File.exist?(url_dest) && mtime > File.mtime(url_dest).to_i if cachebuster == :soft File.cp(url_src, url_dest) @@ -338,9 +345,19 @@ use_cdn = Spider.conf.get('assets.use_cdn') if types.include?(:js) self.assets[:js].each do |ass| ass = {:src => ass} if ass.is_a?(String) $out << "<script type=\"text/javascript\" src=\"#{ass[:src]}\"></script>\n" + end + unless @not_first_js + $out << "<script type=\"text/javascript\">" + @not_first_js = true + $out << "window.SPIDER_BASE_URL = '#{self[:base_url]}'; " + $out << "if (window.Spider) Spider.baseUrl = window.SPIDER_BASE_URL;\n" + unless self[:js_translations].blank? + $out << self[:js_translations]+"\n" + end + $out << "</script>" end end if types.include?(:css) self.assets[:css].each do |ass| ass = {:src => ass} if ass.is_a?(String)