From 2d4e5a7bdbc81a1c9c51796b9d61398f0c211bf1 Mon Sep 17 00:00:00 2001 From: mirion Date: Fri, 8 Nov 2013 13:41:55 +0100 Subject: [PATCH] Fix the handling of static_url-s containing a query string or a hash. Such a case occurs for example when using web fonts in constructs like: src: static_url('webfonts/my-webfont.eot?#iefix') format('embedded-opentype'), static_url('webfonts/my-webfont.svg#bold') format('svg'); --- lib/sproutcore/builders/chance_file.rb | 29 ++++++++++++++++++++++++-- lib/sproutcore/builders/stylesheet.rb | 26 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/sproutcore/builders/chance_file.rb b/lib/sproutcore/builders/chance_file.rb index 3c9db44a..79ab45e4 100644 --- a/lib/sproutcore/builders/chance_file.rb +++ b/lib/sproutcore/builders/chance_file.rb @@ -8,7 +8,7 @@ class Builder::ChanceFile < Builder::Base def build(dst_path) instances = entry[:chance_instances] || [entry[:chance_instance]] - + # Ensure all entries are staged. When Abbot updates, it may skip regenerating # the manifest and just run us, in which case, the previous staged version # will be out-of-date. @@ -34,7 +34,7 @@ def build(dst_path) src }.join("") - # Don't write empty files... but keep in mind that hte + # Don't write empty files... but keep in mind that hte if src.length > 0 if chance_file.end_with?("png") # Writing it as binary to avoid newline problems on Windows @@ -68,6 +68,31 @@ def rewrite_inline_code(code) def static_url(url=''); "url('#{url}')" ; end + def sc_static_match + /(sc_static|static_url|sc_target)\(\s*['"]([^?#"']*)\??(#?[^"']*?)['"]\s*\)/ + end + + # Handles occurances of sc_static() or static_url() + def replace_static_url(line) + line.gsub!(sc_static_match) do | rsrc | + entry_name = $2 + entry_hash = $3 || '' + entry_name = "#{$2}:index.html" if $1 == 'sc_target' + + static_entry = entry.manifest.find_entry($2) + + if !static_entry + SC.logger.warn "#{$2} was not found. Line: #{rsrc}" + url = '' + elsif $1 == 'sc_target' + url = static_entry[:friendly_url] || static_entry.cacheable_url + else + url = static_entry.cacheable_url + $3 + end + + static_url(url) + end + end end diff --git a/lib/sproutcore/builders/stylesheet.rb b/lib/sproutcore/builders/stylesheet.rb index 81ae06f5..e450aa5d 100644 --- a/lib/sproutcore/builders/stylesheet.rb +++ b/lib/sproutcore/builders/stylesheet.rb @@ -36,6 +36,32 @@ def rewrite_inline_code(code) def static_url(url=''); "url('#{url}')" ; end + def sc_static_match + /(sc_static|static_url|sc_target)\(\s*['"]([^?#"']*)\??(#?[^"']*?)['"]\s*\)/ + end + + # Handles occurances of sc_static() or static_url() + def replace_static_url(line) + line.gsub!(sc_static_match) do | rsrc | + entry_name = $2 + entry_hash = $3 || '' + entry_name = "#{$2}:index.html" if $1 == 'sc_target' + + static_entry = entry.manifest.find_entry($2) + + if !static_entry + SC.logger.warn "#{$2} was not found. Line: #{rsrc}" + url = '' + elsif $1 == 'sc_target' + url = static_entry[:friendly_url] || static_entry.cacheable_url + else + url = static_entry.cacheable_url + $3 + end + + static_url(url) + end + end + end end