web_resource_bundler 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/VERSION +1 -1
  2. data/lib/web_resource_bundler/content_management/block_data.rb +18 -21
  3. data/lib/web_resource_bundler/content_management/block_parser.rb +58 -52
  4. data/lib/web_resource_bundler/content_management/css_url_rewriter.rb +3 -3
  5. data/lib/web_resource_bundler/content_management/resource_file.rb +38 -25
  6. data/lib/web_resource_bundler/exceptions.rb +1 -3
  7. data/lib/web_resource_bundler/file_manager.rb +14 -3
  8. data/lib/web_resource_bundler/filters/bundle_filter/resource_packager.rb +45 -27
  9. data/lib/web_resource_bundler/filters/bundle_filter.rb +27 -22
  10. data/lib/web_resource_bundler/filters/cdn_filter.rb +27 -23
  11. data/lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb +53 -40
  12. data/lib/web_resource_bundler/filters/image_encode_filter/image_data.rb +22 -17
  13. data/lib/web_resource_bundler/filters/image_encode_filter.rb +49 -23
  14. data/lib/web_resource_bundler/filters.rb +6 -1
  15. data/lib/web_resource_bundler/rails_app_helpers.rb +56 -40
  16. data/lib/web_resource_bundler/settings.rb +99 -0
  17. data/lib/web_resource_bundler/web_resource_bundler_init.rb +1 -1
  18. data/lib/web_resource_bundler.rb +100 -125
  19. data/spec/sample_block_helper.rb +3 -3
  20. data/spec/web_resource_bundler/content_management/block_data_spec.rb +56 -11
  21. data/spec/web_resource_bundler/content_management/block_parser_spec.rb +24 -10
  22. data/spec/web_resource_bundler/content_management/resource_file_spec.rb +7 -15
  23. data/spec/web_resource_bundler/file_manager_spec.rb +12 -4
  24. data/spec/web_resource_bundler/filters/bundle_filter/filter_spec.rb +5 -5
  25. data/spec/web_resource_bundler/filters/bundle_filter/resource_packager_spec.rb +15 -2
  26. data/spec/web_resource_bundler/filters/cdn_filter_spec.rb +15 -7
  27. data/spec/web_resource_bundler/filters/image_encode_filter/css_generator_spec.rb +44 -4
  28. data/spec/web_resource_bundler/filters/image_encode_filter/filter_spec.rb +20 -15
  29. data/spec/web_resource_bundler/settings_spec.rb +77 -0
  30. data/spec/web_resource_bundler/web_resource_bundler_spec.rb +19 -26
  31. data/web_resource_bundler.gemspec +4 -4
  32. metadata +5 -5
  33. data/lib/web_resource_bundler/settings_manager.rb +0 -91
  34. data/spec/web_resource_bundler/settings_manager_spec.rb +0 -88
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.20
1
+ 0.0.21
@@ -4,32 +4,31 @@ module WebResourceBundler
4
4
 
5
5
  def initialize(condition = "")
6
6
  @inline_block = ""
7
- @files = []
8
- @condition = condition
7
+ @files = []
8
+ @condition = condition
9
9
  @child_blocks = []
10
10
  end
11
11
 
12
12
  def styles
13
- @files.select do |f|
14
- !([WebResourceBundler::ResourceFileType::CSS,
15
- WebResourceBundler::ResourceFileType::IE_CSS] & f.types).empty?
16
- end
13
+ @files.select { |f| f.type[:ext] == 'css' }
17
14
  end
18
15
 
19
16
  def scripts
20
- @files.select {|f| f.types.include?(WebResourceBundler::ResourceFileType::JS)}
17
+ @files.select { |f| f.type[:ext] == 'js'}
18
+ end
19
+
20
+ def base64_styles
21
+ @files.select { |f| WebResourceBundler::ResourceFileType::CSS_TYPES.include?(f.type)}
22
+ end
23
+
24
+ def mhtml_styles
25
+ @files.select { |f| WebResourceBundler::ResourceFileType::MHTML_TYPES.include?(f.type)}
21
26
  end
22
27
 
23
28
  def clone
24
- clon = self.dup
25
- clon.files = self.files.map {|f| f.clone}
26
- if clon.child_blocks.size > 0
27
- clon.child_blocks = self.child_blocks.map do |block|
28
- block.clone
29
- end
30
- else
31
- clon.child_blocks = []
32
- end
29
+ clon = self.dup
30
+ clon.files = self.files.map {|f| f.clone}
31
+ clon.child_blocks = clon.child_blocks.any? ? self.child_blocks.map { |block| block.clone } : []
33
32
  clon
34
33
  end
35
34
 
@@ -47,16 +46,14 @@ module WebResourceBundler
47
46
  block_data.child_blocks.each do |child|
48
47
  result += BlockData.all_childs(child)
49
48
  end
50
- return result
49
+ result
51
50
  end
52
51
 
53
52
  def apply_filters(filters)
54
- unless filters.empty?
53
+ if filters.any?
55
54
  filters.each do |filter|
56
55
  items = BlockData.all_childs(self)
57
- items.each do |block_data|
58
- filter.apply!(block_data)
59
- end
56
+ items.each { |block_data| filter.apply!(block_data) }
60
57
  end
61
58
  end
62
59
  end
@@ -1,63 +1,69 @@
1
1
  module WebResourceBundler
2
- class BlockParser
3
- CONDITIONAL_BLOCK_PATTERN = /<!--\s*\[\s*if[^>]*IE\s*\d*[^>]*\]\s*>(.*?)<!\s*\[\s*endif\s*\]\s*-->/xmi
4
- CONDITION_PATTERN = /<!--\s*(\[[^<]*\])\s*>/
5
- LINK_PATTERN = /(<(link|script[^>]*?src\s*=).*?(><\/script>|>))/
6
- URL_PATTERN = /(href|src) *= *["']([^"'?]+)/i
7
-
8
- #parsing block content recursively
9
- #nested comments NOT supported
10
- #result is BlockData with conditional blocks in child_blocks
11
- def parse_block_with_childs(block, condition)
12
- block_data = BlockData.new(condition)
13
- block.gsub!(CONDITIONAL_BLOCK_PATTERN) do |s|
14
- new_block = CONDITIONAL_BLOCK_PATTERN.match(s)[1]
15
- new_condition = CONDITION_PATTERN.match(s)[1]
16
- block_data.child_blocks << parse_block_with_childs(new_block, new_condition)
17
- s = ""
2
+ module BlockParser
3
+
4
+ CONDITIONAL_BLOCK_PATTERN = /<!--\s*\[\s*if[^>]*IE\s*\d*[^>]*\]\s*>(.*?)<!\s*\[\s*endif\s*\]\s*-->/
5
+ CONDITION_PATTERN = /<!--\s*(\[[^<]*\])\s*>/
6
+ LINK_PATTERN = /(<(link|script[^>]*?src\s*=).*?(><\/script>|>))/i
7
+ URL_PATTERN = /(href|src) *= *["']([^"'?]+)/i
8
+
9
+ class << self
10
+
11
+ #just a short method to start parsing block
12
+ def parse(block)
13
+ parse_block_with_childs(block, "")
14
+ end
15
+
16
+ private
17
+
18
+ #parsing block content recursively
19
+ #nested comments NOT supported
20
+ #result is BlockData with conditional blocks in child_blocks
21
+ def parse_block_with_childs(block, condition)
22
+ block_data = BlockData.new(condition)
23
+ block.gsub!(CONDITIONAL_BLOCK_PATTERN) do |s|
24
+ child_block = $1
25
+ child_condition = CONDITION_PATTERN.match(s)[1]
26
+ block_data.child_blocks << parse_block_with_childs(child_block, child_condition)
27
+ ""
28
+ end
29
+ block_data.files = find_files(block)
30
+ block_data.inline_block = remove_links(block)
31
+ block_data
18
32
  end
19
- files = find_files(block)
20
- block_data.files = files
21
- block_data.inline_block = remove_links(block)
22
- block_data
23
- end
24
-
25
- #removing resource links from block
26
- #example: "<link href="bla"><script src="bla"></script>my inline content" => "my inline content"
27
- def remove_links(block)
28
- inline_block = block.gsub(LINK_PATTERN) do |s|
29
- extension = File.extname(URL_PATTERN.match(s)[2])
30
- if /\.js|\.css/.match(extension) and not s.include?('://')
31
- #we should delete link to local css or js resource
32
- ''
33
- else
34
- #link to remote resource should be kept
35
- s
33
+
34
+ #removing resource links from block
35
+ #example: "<link href="bla"><script src="bla"></script>my inline content" => "my inline content"
36
+ def remove_links(block)
37
+ inline_block = block.gsub(LINK_PATTERN) do |s|
38
+ url = URL_PATTERN.match(s)[2]
39
+ extension = File.extname(url)
40
+ /\.js|\.css/.match(extension) && !URI.parse(url).absolute? ? '' : s
36
41
  end
42
+ inline_block
37
43
  end
38
- return inline_block
39
- end
40
-
41
- #looking for css and js files included and create BlockFiles with files paths
42
- def find_files(block)
43
- files = []
44
- block.scan(URL_PATTERN).each do |property, value|
45
- unless value.include?('://')
46
- case property
47
- when "src"
48
- then files << WebResourceBundler::ResourceFile.new_js_file(value) if File.extname(value) == '.js'
49
- when "href"
50
- then files << WebResourceBundler::ResourceFile.new_style_file(value) if File.extname(value) == '.css'
44
+
45
+ #looking for css and js files included and create BlockFiles with files paths
46
+ def find_files(block)
47
+ files = []
48
+ block.scan(URL_PATTERN).each do |attribute, path|
49
+ if !URI.parse(path).absolute?
50
+ resource = create_resource_file(attribute, path)
51
+ files << resource if resource
51
52
  end
52
53
  end
54
+ files
55
+ end
56
+
57
+ def create_resource_file(attribute, path)
58
+ case attribute
59
+ when "src"
60
+ then WebResourceBundler::ResourceFile.new_js_file(path) if File.extname(path) == '.js'
61
+ when "href"
62
+ then WebResourceBundler::ResourceFile.new_css_file(path) if File.extname(path) == '.css'
63
+ end
53
64
  end
54
- files
55
- end
56
65
 
57
- #just a short method to start parsing passed block
58
- def parse(block)
59
- parse_block_with_childs(block, "")
60
- end
66
+ end
61
67
 
62
68
  end
63
69
  end
@@ -1,10 +1,10 @@
1
1
  class WebResourceBundler::CssUrlRewriter
2
2
  class << self
3
+ URL_TAG_PATTERN = /url\s*\(['|"]?([^\)'"]+)['|"]?\)/i
3
4
  # rewrites a relative path to an absolute path, removing excess "../" and "./"
4
5
  # rewrite_relative_path("stylesheets/default/global.css", "../image.gif") => "/stylesheets/image.gif"
5
-
6
6
  def rewrite_relative_path(source_url, relative_url)
7
- return relative_url if relative_url.include?('http://')
7
+ return relative_url if URI.parse(relative_url).absolute?
8
8
  File.expand_path(relative_url, File.dirname(source_url))
9
9
  end
10
10
 
@@ -15,7 +15,7 @@ class WebResourceBundler::CssUrlRewriter
15
15
  # url(/stylesheets/../images/active_scaffold/default/add.gif);
16
16
  # url('/images/active_scaffold/default/add.gif');
17
17
  def rewrite_content_urls!(filename, content)
18
- content.gsub!(/url\s*\(['|"]?([^\)'"]+)['|"]?\)/) { "url('#{rewrite_relative_path(filename, $1)}')" }
18
+ content.gsub!(URL_TAG_PATTERN) { "url('#{rewrite_relative_path(filename, $1)}')" }
19
19
  content
20
20
  end
21
21
 
@@ -1,38 +1,51 @@
1
1
  module WebResourceBundler
2
2
 
3
3
  class ResourceFileType
4
- CSS = {:value => 1, :name => 'style', :ext => 'css'}
5
- JS = {:value => 2, :name => 'script', :ext => 'js'}
6
- IE_CSS = {:value => 3, :name => 'style', :ext => 'css'}
7
- MHTML = {:value => 4, :name => 'style', :ext => 'mhtml'}
4
+
5
+ CSS = {:value => 1 , :name => 'style' , :ext => 'css' }
6
+ JS = {:value => 2 , :name => 'script' , :ext => 'js' }
7
+ MHTML_CSS = {:value => 3 , :name => 'style' , :ext => 'css' }
8
+ BASE64_CSS = {:value => 4 , :name => 'style' , :ext => 'css' }
9
+ MHTML = {:value => 5 , :name => 'mhtml' , :ext => 'mhtml' }
10
+
11
+ CSS_TYPES = [CSS, BASE64_CSS]
12
+ MHTML_TYPES = [CSS, MHTML_CSS, MHTML]
8
13
  end
9
14
 
10
15
  class ResourceFile
11
- attr_accessor :types #array of ResourceFileType's objects
12
- attr_accessor :path, :content
13
- def initialize(path, content, *types)
14
- @types = types.flatten
16
+
17
+ attr_accessor :type, :path, :content
18
+
19
+ def initialize(path, content, type)
20
+ @type = type
15
21
  @content = content
16
- @path = path
17
- end
18
- def self.new_js_file(path, content = "")
19
- ResourceFile.new(path, content, ResourceFileType::JS)
20
- end
21
- def self.new_css_file(path, content = "")
22
- ResourceFile.new(path, content, ResourceFileType::CSS)
23
- end
24
- def self.new_ie_css_file(path, content ="")
25
- ResourceFile.new(path, content, ResourceFileType::IE_CSS)
26
- end
27
- def self.new_style_file(path, content ="")
28
- ResourceFile.new(path, content, ResourceFileType::CSS, ResourceFileType::IE_CSS)
29
- end
30
- def self.new_mhtml_file(path, content = "")
31
- ResourceFile.new(path, content, ResourceFileType::MHTML)
22
+ @path = path
32
23
  end
24
+
25
+ class << self
26
+
27
+ def new_js_file(path, content = "")
28
+ ResourceFile.new(path, content, ResourceFileType::JS)
29
+ end
30
+
31
+ def new_css_file(path, content = "")
32
+ ResourceFile.new(path, content, ResourceFileType::CSS)
33
+ end
34
+
35
+ def new_mhtml_css_file(path, content = "")
36
+ ResourceFile.new(path, content, ResourceFileType::MHTML_CSS)
37
+ end
38
+
39
+ def new_mhtml_file(path, content = "")
40
+ ResourceFile.new(path, content, ResourceFileType::MHTML)
41
+ end
42
+
43
+ end
44
+
33
45
  def clone
34
- ResourceFile.new(self.path.dup, self.content.dup, self.types.dup)
46
+ ResourceFile.new(self.path.dup, self.content.dup, self.type.dup)
35
47
  end
48
+
36
49
  end
37
50
 
38
51
  end
@@ -5,9 +5,7 @@ module WebResourceBundler::Exceptions
5
5
  @message = message
6
6
  end
7
7
 
8
- def to_s
9
- @message
10
- end
8
+ def to_s; @message; end
11
9
 
12
10
  end
13
11
 
@@ -1,9 +1,14 @@
1
1
  module WebResourceBundler
2
2
  class FileManager
3
- attr_accessor :resource_dir, :cache_dir
3
+ attr_reader :resource_dir, :cache_dir
4
4
 
5
- def initialize(resource_dir, cache_dir)
6
- @resource_dir, @cache_dir = resource_dir, cache_dir
5
+ def initialize(attributes)
6
+ set_settings(attributes)
7
+ end
8
+
9
+ def set_settings(attributes)
10
+ @resource_dir = attributes[:resource_dir]
11
+ @cache_dir = attributes[:cache_dir]
7
12
  end
8
13
 
9
14
  def full_path(relative_path)
@@ -25,6 +30,12 @@ module WebResourceBundler
25
30
  Dir.mkdir(path)
26
31
  end
27
32
  end
33
+
34
+ def write_file(path, content)
35
+ File.open(full_path(path), "w") do |f|
36
+ f.print(content)
37
+ end
38
+ end
28
39
 
29
40
  end
30
41
  end
@@ -1,48 +1,66 @@
1
1
  module WebResourceBundler::Filters::BundleFilter
2
2
  class ResourcePackager
3
- IMPORT_PTR = /\@import ['|"](.*?)['|"];/
3
+ IMPORT_PTR = /\@import ['|"](.*?)['|"];/i
4
4
 
5
5
  def initialize(settings, file_manager)
6
- @settings = settings
6
+ @settings = settings
7
7
  @file_manager = file_manager
8
8
  end
9
9
 
10
10
  #recursively iterates through all files and imported files
11
11
  def bundle_files(files)
12
12
  output = ""
13
- files.select{|f| not f.content.empty? }.each do |file|
14
- path = file.path
13
+ files.select { |f| !f.content.empty? }.each do |file|
15
14
  content = file.content
16
- output << "/* --------- #{path} --------- */\n"
17
- if file.types.first[:ext] == 'css'
18
- imported_files = extract_imported_files!(content, path)
19
- #getting imported (@import ...) files contents
20
- imported_resource_files = []
21
- imported_files.each do |imported_file|
22
- imported_resource_files << WebResourceBundler::ResourceFile.new_css_file(imported_file, @file_manager.get_content(imported_file))
23
- end
24
- #bundling imported files
25
- output << bundle_files(imported_resource_files) unless imported_resource_files.empty?
26
- end
27
- #adding ';' symbol in case javascript developer forget to do this
28
- content << ';' if File.extname(path) == '.js'
29
- output << content
30
- output << "\n/* --------- END #{path} --------- */\n"
15
+ path = file.path
16
+ output << bundled_file_header(path)
17
+ output << include_imported_files(content, path) if file.type[:ext] == 'css'
18
+ content << javascript_fix if file.type[:ext] == '.js'
19
+ output << content
20
+ output << bundled_file_footer(path)
31
21
  end
32
22
  output
33
23
  end
34
24
 
35
- #finds all imported files in css
25
+ private
26
+
27
+ #to avoid problems with javascript we should add closing ;
28
+ def javascript_fix
29
+ ';'
30
+ end
31
+
32
+ def include_imported_files(content, base_path)
33
+ imported_file_paths = extract_imported_files!(content, base_path)
34
+ imported_resource_files = build_imported_files(imported_file_paths)
35
+ imported_resource_files.any? ? bundle_files(imported_resource_files) : ''
36
+ end
37
+
38
+ #finds all imported files paths in css
36
39
  def extract_imported_files!(content, base_file_path)
37
- imported_files = []
40
+ paths = []
38
41
  content.gsub!(IMPORT_PTR) do |result|
39
- imported_file = IMPORT_PTR.match(result)[1]
40
- if imported_file
41
- imported_files << File.join(File.dirname(base_file_path), imported_file)
42
- end
43
- result = ""
42
+ path = $1
43
+ paths << File.join(File.dirname(base_file_path), path) if path
44
+ ""
45
+ end
46
+ paths
47
+ end
48
+
49
+ def bundled_file_header(path)
50
+ "/* --------- #{path} --------- */\n"
51
+ end
52
+
53
+ def bundled_file_footer(path)
54
+ "\n/* --------- END #{path} --------- */\n"
55
+ end
56
+
57
+ #created resource files using imported files paths
58
+ def build_imported_files(imported_file_paths)
59
+ files = []
60
+ imported_file_paths.map do |path|
61
+ files << WebResourceBundler::ResourceFile.new_css_file(path, @file_manager.get_content(path)) if File.basename(path).split('.')[-1] == 'css'
44
62
  end
45
- return imported_files
63
+ files
46
64
  end
47
65
 
48
66
  end
@@ -1,6 +1,8 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "/bundle_filter")
2
+
2
3
  require 'bundle_filter/resource_packager'
3
4
  require 'base_filter'
5
+
4
6
  module WebResourceBundler::Filters::BundleFilter
5
7
  class Filter < WebResourceBundler::Filters::BaseFilter
6
8
 
@@ -10,23 +12,29 @@ module WebResourceBundler::Filters::BundleFilter
10
12
  end
11
13
 
12
14
  def apply!(block_data)
13
- new_files = []
14
- unless block_data.styles.empty?
15
- new_css_filename = css_bundle_filepath(block_data.styles)
16
- new_css_content = @packager.bundle_files(block_data.styles)
17
- new_css_file = WebResourceBundler::ResourceFile.new_style_file(new_css_filename, new_css_content)
18
- new_files << new_css_file
19
- end
20
- unless block_data.scripts.empty?
21
- new_js_filename = js_bundle_filepath(block_data.scripts)
22
- new_js_content = @packager.bundle_files(block_data.scripts)
23
- new_js_file = WebResourceBundler::ResourceFile.new_js_file(new_js_filename, new_js_content)
24
- new_files << new_js_file
25
- end
26
- block_data.files = new_files
15
+ new_files = []
16
+ new_files << create_css_bundle(block_data.styles) if block_data.styles.any?
17
+ new_files << create_js_bundle(block_data.scripts) if block_data.scripts.any?
18
+ block_data.files = new_files
27
19
  block_data
28
20
  end
29
21
 
22
+ private
23
+
24
+ #creates one bundle resource file from css files
25
+ def create_css_bundle(styles)
26
+ filename = css_bundle_filepath(styles)
27
+ content = @packager.bundle_files(styles)
28
+ WebResourceBundler::ResourceFile.new_css_file(filename, content)
29
+ end
30
+
31
+ #creates one bundle resource file from js files
32
+ def create_js_bundle(scripts)
33
+ filename = js_bundle_filepath(scripts)
34
+ content = @packager.bundle_files(scripts)
35
+ WebResourceBundler::ResourceFile.new_js_file(filename, content)
36
+ end
37
+
30
38
  def get_md5(files)
31
39
  items = [(files.map {|f| f.path }).sort]
32
40
  items << @settings[:protocol]
@@ -36,14 +44,11 @@ module WebResourceBundler::Filters::BundleFilter
36
44
  end
37
45
 
38
46
  def bundle_filepath(type, files)
39
- unless files.empty?
40
- items = [type[:name] + '_' + get_md5(files)]
41
- items += @settings[:filename_additional_data] if @settings[:filename_additional_data]
42
- items << type[:ext]
43
- return File.join(@settings[:cache_dir], items.join('.'))
44
- else
45
- return nil
46
- end
47
+ return nil if files.empty?
48
+ items = [type[:name] + '_' + get_md5(files)]
49
+ items += @settings[:filename_additional_data] if @settings[:filename_additional_data]
50
+ items << type[:ext]
51
+ File.join(@settings[:cache_dir], items.join('.'))
47
52
  end
48
53
 
49
54
  #just aliases to simplify code
@@ -1,5 +1,9 @@
1
1
  module WebResourceBundler::Filters::CdnFilter
2
2
  class Filter < WebResourceBundler::Filters::BaseFilter
3
+
4
+ FILE_PREFIX = 'cdn_'
5
+ IMAGE_URL_PATTERN = /url\s*\(['|"]?([^\)'"]+\.(jpg|gif|png|jpeg|bmp))['|"]?\)/i
6
+
3
7
  def initialize(settings, file_manager)
4
8
  super(settings, file_manager)
5
9
  end
@@ -12,37 +16,37 @@ module WebResourceBundler::Filters::CdnFilter
12
16
  block_data
13
17
  end
14
18
 
15
- def new_filepath(path)
16
- File.join(@settings[:cache_dir], 'cdn_' + File.basename(path))
19
+ private
20
+
21
+ def new_filepath(path)
22
+ File.join(@settings[:cache_dir], FILE_PREFIX + File.basename(path))
17
23
  end
18
24
 
19
25
  #insures that image linked to one particular host
26
+ #host type depends on request protocol type
20
27
  def host_for_image(image_url)
21
- #hosts are different depending on protocol
22
- if @settings[:protocol] == 'https'
23
- hosts = @settings[:https_hosts]
24
- else
25
- hosts = @settings[:http_hosts]
26
- end
27
- #getting host based on image url hash
28
- host_index = image_url.hash % hosts.size
29
- hosts[host_index]
28
+ hosts = get_hosts
29
+ index = image_url.hash % hosts.size
30
+ hosts[index]
30
31
  end
31
32
 
33
+ def get_hosts
34
+ key = @settings[:protocol] == 'https' ? :https_hosts : :http_hosts
35
+ @settings[key]
36
+ end
37
+
38
+ #rewrites image urls excluding mhtml and base64 urls
32
39
  def rewrite_content_urls!(file_path, content)
33
- content.gsub!(/url\s*\(['|"]?([^\)'"]+)['|"]?\)/) do |s|
34
- matched_url = $1
35
- #we shouldn't change url value for base64 encoded images
36
- if not (/base64/.match(s) or /mhtml/.match(s)) and matched_url.match(/\.(jpg|gif|png|jpeg|bmp)/)
37
- #using CssUrlRewriter method to get image url
38
- url = WebResourceBundler::CssUrlRewriter.rewrite_relative_path(file_path, matched_url)
39
- host = host_for_image(url)
40
- s = "url('#{File.join(host, url)}')"
41
- else
42
- s
43
- end
40
+ content.gsub!(IMAGE_URL_PATTERN) do |s|
41
+ url = WebResourceBundler::CssUrlRewriter.rewrite_relative_path(file_path, $1)
42
+ host = host_for_image(url)
43
+ s = url_css_tag(host, url)
44
44
  end
45
45
  end
46
-
46
+
47
+ def url_css_tag(host, url)
48
+ "url('#{File.join(host, url)}')"
49
+ end
50
+
47
51
  end
48
52
  end