Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: grit/gather/chrome_html.py

Issue 10795081: Use ' instead of " when rewriting -webkit-image-set. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « grit/format/html_inline.py ('k') | grit/gather/chrome_html_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Prepares a Chrome HTML file by inlining resources and adding references to 6 """Prepares a Chrome HTML file by inlining resources and adding references to
7 high DPI resources and removing references to unsupported scale factors. 7 high DPI resources and removing references to unsupported scale factors.
8 8
9 This is a small gatherer that takes a HTML file, looks for src attributes 9 This is a small gatherer that takes a HTML file, looks for src attributes
10 and inlines the specified file, producing one HTML file with no external 10 and inlines the specified file, producing one HTML file with no external
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 Returns: 66 Returns:
67 string 67 string
68 """ 68 """
69 filename = src_match.group('filename') 69 filename = src_match.group('filename')
70 attr = src_match.group('attribute') 70 attr = src_match.group('attribute')
71 prefix = src_match.string[src_match.start():src_match.start('filename')-1] 71 prefix = src_match.string[src_match.start():src_match.start('filename')-1]
72 72
73 # Any matches for which a chrome URL handler will serve all scale factors 73 # Any matches for which a chrome URL handler will serve all scale factors
74 # can simply request all scale factors. 74 # can simply request all scale factors.
75 if _THEME_SOURCE.match(filename): 75 if _THEME_SOURCE.match(filename):
76 images = ["url(\"%s\") %s" % (filename, '1x')] 76 images = ["url('%s') %s" % (filename, '1x')]
77 for sc in scale_factors: 77 for sc in scale_factors:
78 images.append("url(\"%s@%s\") %s" % (filename, sc, sc)) 78 images.append("url('%s@%s') %s" % (filename, sc, sc))
79 return "%s: -webkit-image-set(%s" % (attr, ', '.join(images)) 79 return "%s: -webkit-image-set(%s" % (attr, ', '.join(images))
80 80
81 if filename.find(':') != -1: 81 if filename.find(':') != -1:
82 # filename is probably a URL, which we don't want to bother inlining 82 # filename is probably a URL, which we don't want to bother inlining
83 return src_match.group(0) 83 return src_match.group(0)
84 84
85 filename = filename.replace(DIST_SUBSTR, distribution) 85 filename = filename.replace(DIST_SUBSTR, distribution)
86 filepath = os.path.join(base_path, filename) 86 filepath = os.path.join(base_path, filename)
87 images = ["url(\"%s\") %s" % (filename, '1x')] 87 images = ["url('%s') %s" % (filename, '1x')]
88 88
89 for sc in scale_factors: 89 for sc in scale_factors:
90 # Check for existence of file and add to image set. 90 # Check for existence of file and add to image set.
91 scale_path = os.path.split(os.path.join(base_path, filename)) 91 scale_path = os.path.split(os.path.join(base_path, filename))
92 scale_image_path = os.path.join(scale_path[0], sc, scale_path[1]) 92 scale_image_path = os.path.join(scale_path[0], sc, scale_path[1])
93 if os.path.isfile(scale_image_path): 93 if os.path.isfile(scale_image_path):
94 # CSS always uses forward slashed paths. 94 # CSS always uses forward slashed paths.
95 scale_image_name = re.sub('(?P<path>(.*/)?)(?P<file>[^/]*)', 95 scale_image_name = re.sub('(?P<path>(.*/)?)(?P<file>[^/]*)',
96 '\\g<path>' + sc + '/\\g<file>', 96 '\\g<path>' + sc + '/\\g<file>',
97 filename) 97 filename)
98 images.append("url(\"%s\") %s" % (scale_image_name, sc)) 98 images.append("url('%s') %s" % (scale_image_name, sc))
99 return "%s: -webkit-image-set(%s" % (attr, ', '.join(images)) 99 return "%s: -webkit-image-set(%s" % (attr, ', '.join(images))
100 100
101 101
102 def InsertImageSets( 102 def InsertImageSets(
103 filepath, text, scale_factors, distribution): 103 filepath, text, scale_factors, distribution):
104 """Helper function that adds references to external images available in any of 104 """Helper function that adds references to external images available in any of
105 scale_factors in CSS backgrounds. 105 scale_factors in CSS backgrounds.
106 """ 106 """
107 # Add high DPI urls for css attributes: content, background, 107 # Add high DPI urls for css attributes: content, background,
108 # or *-image. 108 # or *-image.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 allow_external_script = self.allow_external_script_, 222 allow_external_script = self.allow_external_script_,
223 rewrite_function=lambda fp, t, d: ProcessImageSets( 223 rewrite_function=lambda fp, t, d: ProcessImageSets(
224 fp, t, self.scale_factors_, d)) 224 fp, t, self.scale_factors_, d))
225 else: 225 else:
226 distribution = html_inline.GetDistribution() 226 distribution = html_inline.GetDistribution()
227 self.inlined_text_ = ProcessImageSets( 227 self.inlined_text_ = ProcessImageSets(
228 os.path.dirname(filename), 228 os.path.dirname(filename),
229 util.ReadFile(filename, 'utf-8'), 229 util.ReadFile(filename, 'utf-8'),
230 self.scale_factors_, 230 self.scale_factors_,
231 distribution) 231 distribution)
OLDNEW
« no previous file with comments | « grit/format/html_inline.py ('k') | grit/gather/chrome_html_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698