| Index: grit/format/html_inline.py
|
| diff --git a/grit/format/html_inline.py b/grit/format/html_inline.py
|
| index 7adc743b7c018a7691e8c7c0dcc86560752502af..d2e9eed91f5a3318181527692b1cec3669a94b26 100755
|
| --- a/grit/format/html_inline.py
|
| +++ b/grit/format/html_inline.py
|
| @@ -116,7 +116,7 @@ class InlinedData:
|
|
|
| def DoInline(
|
| input_filename, grd_node, allow_external_script=False, names_only=False,
|
| - rewrite_function=None):
|
| + rewrite_function=None, filename_expansion_function=None):
|
| """Helper function that inlines the resources in a specified file.
|
|
|
| Reads input_filename, finds all the src attributes and attempts to
|
| @@ -129,10 +129,14 @@ def DoInline(
|
| names_only: |nil| will be returned for the inlined contents (faster).
|
| rewrite_function: function(filepath, text, distribution) which will be
|
| called to rewrite html content before inlining images.
|
| + filename_expansion_function: function(filename) which will be called to
|
| + rewrite filenames before attempting to read them.
|
| Returns:
|
| a tuple of the inlined data as a string and the set of filenames
|
| of all the inlined files
|
| """
|
| + if filename_expansion_function:
|
| + input_filename = filename_expansion_function(input_filename)
|
| input_filepath = os.path.dirname(input_filename)
|
| distribution = GetDistribution()
|
|
|
| @@ -153,6 +157,8 @@ def DoInline(
|
| return None
|
|
|
| filename = filename.replace('%DISTRIBUTION%', distribution)
|
| + if filename_expansion_function:
|
| + filename = filename_expansion_function(filename)
|
| return os.path.normpath(os.path.join(base_path, filename))
|
|
|
| def IsConditionSatisfied(src_match):
|
| @@ -204,12 +210,16 @@ def DoInline(
|
| inlined_files.add(filepath)
|
|
|
| if names_only:
|
| - inlined_files.update(GetResourceFilenames(filepath,
|
| - allow_external_script,
|
| - rewrite_function))
|
| + inlined_files.update(GetResourceFilenames(
|
| + filepath,
|
| + allow_external_script,
|
| + rewrite_function,
|
| + filename_expansion_function=filename_expansion_function))
|
| return ""
|
|
|
| - return pattern % InlineToString(filepath, grd_node, allow_external_script)
|
| + return pattern % InlineToString(
|
| + filepath, grd_node, allow_external_script,
|
| + filename_expansion_function=filename_expansion_function)
|
|
|
| def InlineIncludeFiles(src_match):
|
| """Helper function to directly inline generic external files (without
|
| @@ -328,7 +338,7 @@ def DoInline(
|
|
|
|
|
| def InlineToString(input_filename, grd_node, allow_external_script=False,
|
| - rewrite_function=None):
|
| + rewrite_function=None, filename_expansion_function=None):
|
| """Inlines the resources in a specified file and returns it as a string.
|
|
|
| Args:
|
| @@ -338,10 +348,12 @@ def InlineToString(input_filename, grd_node, allow_external_script=False,
|
| the inlined data as a string
|
| """
|
| try:
|
| - return DoInline(input_filename,
|
| - grd_node,
|
| - allow_external_script=allow_external_script,
|
| - rewrite_function=rewrite_function).inlined_data
|
| + return DoInline(
|
| + input_filename,
|
| + grd_node,
|
| + allow_external_script=allow_external_script,
|
| + rewrite_function=rewrite_function,
|
| + filename_expansion_function=filename_expansion_function).inlined_data
|
| except IOError, e:
|
| raise Exception("Failed to open %s while trying to flatten %s. (%s)" %
|
| (e.filename, input_filename, e.strerror))
|
| @@ -368,14 +380,17 @@ def InlineToFile(input_filename, output_filename, grd_node):
|
|
|
| def GetResourceFilenames(filename,
|
| allow_external_script=False,
|
| - rewrite_function=None):
|
| + rewrite_function=None,
|
| + filename_expansion_function=None):
|
| """For a grd file, returns a set of all the files that would be inline."""
|
| try:
|
| - return DoInline(filename,
|
| - None,
|
| - names_only=True,
|
| - allow_external_script=allow_external_script,
|
| - rewrite_function=rewrite_function).inlined_files
|
| + return DoInline(
|
| + filename,
|
| + None,
|
| + names_only=True,
|
| + allow_external_script=allow_external_script,
|
| + rewrite_function=rewrite_function,
|
| + filename_expansion_function=filename_expansion_function).inlined_files
|
| except IOError, e:
|
| raise Exception("Failed to open %s while trying to flatten %s. (%s)" %
|
| (e.filename, filename, e.strerror))
|
|
|