Index: tools/grit/grit/format/html_inline.py |
diff --git a/tools/grit/grit/format/html_inline.py b/tools/grit/grit/format/html_inline.py |
index 643052dd2e66063e4c2155831f32a3e8ac92c203..4d1e355b4a72a8a0150c163889952e6e52d4f1bf 100755 |
--- a/tools/grit/grit/format/html_inline.py |
+++ b/tools/grit/grit/format/html_inline.py |
@@ -128,7 +128,7 @@ class InlinedData: |
self.inlined_files = inlined_files |
def DoInline( |
- input_filename, grd_node, allow_external_script=False, |
+ input_filename, evaluate_condition, allow_external_script=False, |
preprocess_only=False, names_only=False, rewrite_function=None, |
filename_expansion_function=None): |
"""Helper function that inlines the resources in a specified file. |
@@ -139,7 +139,7 @@ def DoInline( |
Args: |
input_filename: name of file to read in |
- grd_node: html node from the grd file for this include tag |
+ evaluate_condition: a function to evaluate boolean conditions |
Dan Beam
2016/07/14 17:47:58
this isn't really too helpful of a variable name,
|
preprocess_only: Skip all HTML processing, only handle <if> and <include>. |
names_only: |nil| will be returned for the inlined contents (faster). |
rewrite_function: function(filepath, text, distribution) which will be |
@@ -179,7 +179,7 @@ def DoInline( |
def IsConditionSatisfied(src_match): |
expression = src_match.group('expression') |
- return grd_node is None or grd_node.EvaluateCondition(expression) |
+ return evaluate_condition is None or evaluate_condition(expression) |
def CheckConditionalElements(str): |
"""Helper function to conditionally inline inner elements""" |
@@ -236,7 +236,9 @@ def DoInline( |
return "" |
return pattern % InlineToString( |
- filepath, grd_node, allow_external_script=allow_external_script, |
+ filepath, |
+ evaluate_condition, |
+ allow_external_script=allow_external_script, |
filename_expansion_function=filename_expansion_function) |
def InlineIncludeFiles(src_match): |
@@ -249,7 +251,7 @@ def DoInline( |
"""Helper function to inline external script files""" |
attrs = (match.group('attrs1') + match.group('attrs2')).strip() |
if attrs: |
- attrs = ' ' + attrs |
+ attrs = ' ' + attrs |
return InlineFileContents(match, '<script' + attrs + '>%s</script>') |
def InlineCSSText(text, css_filepath): |
@@ -356,21 +358,21 @@ def DoInline( |
return InlinedData(flat_text, inlined_files) |
-def InlineToString(input_filename, grd_node, preprocess_only = False, |
+def InlineToString(input_filename, evaluate_condition, preprocess_only = False, |
allow_external_script=False, rewrite_function=None, |
filename_expansion_function=None): |
"""Inlines the resources in a specified file and returns it as a string. |
Args: |
input_filename: name of file to read in |
- grd_node: html node from the grd file for this include tag |
+ evaluate_condition: a function to evaluate boolean conditions |
Returns: |
the inlined data as a string |
""" |
try: |
return DoInline( |
input_filename, |
- grd_node, |
+ evaluate_condition, |
preprocess_only=preprocess_only, |
allow_external_script=allow_external_script, |
rewrite_function=rewrite_function, |
@@ -380,7 +382,7 @@ def InlineToString(input_filename, grd_node, preprocess_only = False, |
(e.filename, input_filename, e.strerror)) |
-def InlineToFile(input_filename, output_filename, grd_node): |
+def InlineToFile(input_filename, output_filename, evaluate_condition): |
"""Inlines the resources in a specified file and writes it. |
Reads input_filename, finds all the src attributes and attempts to |
@@ -390,11 +392,11 @@ def InlineToFile(input_filename, output_filename, grd_node): |
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 |
+ evaluate_condition: a function to evaluate boolean conditions |
Returns: |
a set of filenames of all the inlined files |
""" |
- inlined_data = InlineToString(input_filename, grd_node) |
+ inlined_data = InlineToString(input_filename, evaluate_condition) |
with open(output_filename, 'wb') as out_file: |
out_file.writelines(inlined_data) |