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

Unified Diff: tools/grit/grit/format/html_inline.py

Issue 2872028: Modified grit to support <if expr="..."> tags within included html files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/options.html ('k') | tools/grit/grit/format/rc.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/format/html_inline.py
===================================================================
--- tools/grit/grit/format/html_inline.py (revision 51538)
+++ tools/grit/grit/format/html_inline.py (working copy)
@@ -19,6 +19,8 @@
import base64
import mimetypes
+from grit.node import base
+
DIST_DEFAULT = 'chromium'
DIST_ENV_VAR = 'CHROMIUM_BUILD'
DIST_SUBSTR = '%DISTRIBUTION%'
@@ -67,7 +69,7 @@
prefix = src_match.string[src_match.start():src_match.start('filename')-1]
return "%s\"data:%s;base64,%s\"" % (prefix, mimetype, inline_data)
-def InlineFile(input_filename, output_filename):
+def InlineFile(input_filename, output_filename, grd_node):
"""Inlines the resources in a specified file.
Reads input_filename, finds all the src attributes and attempts to
@@ -77,6 +79,7 @@
Args:
input_filename: name of file to read in
output_filename: name of file to be written to
+ grd_node: html node from the grd file for this include tag
"""
input_filepath = os.path.dirname(input_filename)
@@ -100,6 +103,16 @@
filename = filename.replace('%DISTRIBUTION%', distribution)
return os.path.join(input_filepath, filename)
+ def IsConditionSatisfied(src_match):
+ expression = src_match.group('expression')
+ return grd_node is None or grd_node.EvaluateCondition(expression)
+
+ def CheckConditionalElements(src_match):
+ """Helper function to conditionally inline inner elements"""
+ if not IsConditionSatisfied(src_match):
+ return ''
+ return src_match.group('content')
+
def InlineFileContents(src_match, pattern):
"""Helper function to inline external script and css files"""
filepath = GetFilepath(src_match)
@@ -144,7 +157,6 @@
lambda m: SrcReplace(m, filepath),
text)
-
# 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>',
@@ -157,10 +169,16 @@
flat_text)
flat_text = re.sub(
- '<!--\s*include\s+file="(?P<filename>[^"\']*)".*-->',
+ '<include\s+src="(?P<filename>[^"\']*)".*>',
InlineIncludeFiles,
flat_text)
+ # Check conditional elements, remove unsatisfied ones from the file.
+ flat_text = re.sub('<if .*?expr="(?P<expression>[^"]*)".*?>\s*' +
+ '(?P<content>([\s\S]+?))\s*</if>',
+ CheckConditionalElements,
+ 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,
« no previous file with comments | « chrome/browser/resources/options.html ('k') | tools/grit/grit/format/rc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698