diff --git a/lib/global_path.rb b/lib/global_path.rb index 20f09f18bd4..c2d9a2a4da2 100644 --- a/lib/global_path.rb +++ b/lib/global_path.rb @@ -6,4 +6,13 @@ module GlobalPath def cdn_path(p) "#{GlobalSetting.cdn_url}#{path(p)}" end + + def cdn_relative_path(path) + if (cdn_url = GlobalSetting.cdn_url).present? + URI.parse(cdn_url).path + path + else + path + end + end + end diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 040f70e2b29..ff109fbc289 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -102,8 +102,8 @@ end def compress_node(from,to) to_path = "#{assets_path}/#{to}" - - source_map_root = (d=File.dirname(from)) == "." ? "/assets" : "/assets/#{d}" + assets = cdn_relative_path("/assets") + source_map_root = assets + (d=File.dirname(from)) == "." ? "" : "/#{d}" source_map_url = cdn_path "/assets/#{to}.map" cmd = "uglifyjs '#{assets_path}/#{from}' -p relative -c -m -o '#{to_path}' --source-map-root '#{source_map_root}' --source-map '#{assets_path}/#{to}.map' --source-map-url '#{source_map_url}'" diff --git a/spec/components/global_path_spec.rb b/spec/components/global_path_spec.rb new file mode 100644 index 00000000000..41b778c9af3 --- /dev/null +++ b/spec/components/global_path_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' +require 'global_path' + +class GlobalPathInstance + extend GlobalPath +end + +describe GlobalPath do + + context 'cdn_relative_path' do + def cdn_relative_path(p) + GlobalPathInstance.cdn_relative_path(p) + end + + it "just returns path for no cdn" do + expect(cdn_relative_path("/test")).to eq("/test") + end + + it "returns path when a cdn is defined with a path" do + GlobalSetting.expects(:cdn_url).returns("//something.com/foo") + expect(cdn_relative_path("/test")).to eq("/foo/test") + end + + it "returns path when a cdn is defined with a path" do + GlobalSetting.expects(:cdn_url).returns("https://something.com:221/foo") + expect(cdn_relative_path("/test")).to eq("/foo/test") + end + + end +end