summaryrefslogtreecommitdiffstats
path: root/tools/grit
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 19:54:05 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 19:54:05 +0000
commitde17ab159c33d8a89dcccae69c167c5d4a6cda68 (patch)
treec6912bdfc4af4954cf65ef4ff1f7dfd6c2d5a3e6 /tools/grit
parentca936213e4aaff3bc046623161f658100af2d084 (diff)
downloadchromium_src-de17ab159c33d8a89dcccae69c167c5d4a6cda68.zip
chromium_src-de17ab159c33d8a89dcccae69c167c5d4a6cda68.tar.gz
chromium_src-de17ab159c33d8a89dcccae69c167c5d4a6cda68.tar.bz2
Move the shared JS and CSS out of the HTML files and into separate files.
Review URL: http://codereview.chromium.org/99151 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15323 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
-rwxr-xr-xtools/grit/grit/format/html_inline.py41
1 files changed, 36 insertions, 5 deletions
diff --git a/tools/grit/grit/format/html_inline.py b/tools/grit/grit/format/html_inline.py
index 9871fbd..e5bb2f4 100755
--- a/tools/grit/grit/format/html_inline.py
+++ b/tools/grit/grit/format/html_inline.py
@@ -37,7 +37,7 @@ def ReadFile(input_filename):
f.close()
return file_contents
-def SrcInline(src_match, base_path, distribution):
+def SrcInlineAsDataURL(src_match, base_path, distribution):
"""regex replace function.
Takes a regex match for src="filename", attempts to read the file
@@ -88,16 +88,47 @@ def InlineFile(input_filename, output_filename):
distribution = distribution[1:].lower()
def SrcReplace(src_match):
- """Helper function to provide SrcInline with the base file path"""
- return SrcInline(src_match, input_filepath, distribution)
+ """Helper function to provide SrcInlineAsDataURL with the base file path"""
+ return SrcInlineAsDataURL(src_match, input_filepath, distribution)
+
+ def InlineFileContents(src_match, pattern):
+ """Helper function to inline external script and css files"""
+ filename = src_match.group('filename')
+
+ if filename.find(':') != -1:
+ # filename is probably a URL, which we don't want to bother inlining
+ return src_match.group(0)
+
+ filename = filename.replace('%DISTRIBUTION%', distribution)
+ filepath = os.path.join(input_filepath, filename)
+
+ return pattern % ReadFile(filepath)
+
+ def InlineScript(src_match):
+ """Helper function to inline external script files"""
+ return InlineFileContents(src_match, '<script>%s</script>')
+
+ def InlineCss(src_match):
+ """Helper function to inline external css files"""
+ return InlineFileContents(src_match, '<style>%s</style>')
+
+ # We need to inline css and js before we inline images so that image
+ # references gets inlined in the css and js
+ flat_text = re.sub('<script .*?src="(?P<filename>[^"\']*)".*?></script>',
+ InlineScript,
+ ReadFile(input_filename))
+
+ flat_text = re.sub('<link rel="stylesheet".+?href="(?P<filename>[^"\']*)".*?>',
+ InlineCss,
+ flat_text)
# TODO(glen): Make this regex not match src="" text that is not inside a tag
flat_text = re.sub('src="(?P<filename>[^"\']*)"',
SrcReplace,
- ReadFile(input_filename))
+ flat_text)
# TODO(glen): Make this regex not match url('') that is not inside a style
- flat_text = re.sub('background:[ ]*url\(\'(?P<filename>[^"\']*)\'',
+ flat_text = re.sub('background(?:-image)?:[ ]*url\(\'(?P<filename>[^"\']*)\'',
SrcReplace,
flat_text)