20 __authors__ = [ |
20 __authors__ = [ |
21 '"Todd Larsen" <tlarsen@google.com>', |
21 '"Todd Larsen" <tlarsen@google.com>', |
22 ] |
22 ] |
23 |
23 |
24 |
24 |
25 def makeSiblingTemplatesList(templates, new_template_file): |
25 def makeSiblingTemplatesList(templates, new_template_file, |
|
26 default_template=None): |
26 """Converts template paths into a list of "sibling" templates. |
27 """Converts template paths into a list of "sibling" templates. |
27 |
28 |
28 Args: |
29 Args: |
29 templates: search list of templates (or just a single template not in a |
30 templates: search list of templates (or just a single template not in a |
30 list) from which template paths will be extracted (discarding the final |
31 list) from which template paths will be extracted (discarding the final |
31 template file name of each template) |
32 template file name of each template) |
32 new_template_file: new "sibling" template file to append to each extracted |
33 new_template_file: new "sibling" template file to append to each extracted |
33 template path |
34 template path |
34 |
35 default_template: a default template (or a list of them) to append to the |
|
36 end of the generated "sibling" template paths; default is None |
|
37 |
35 Returns: |
38 Returns: |
36 A list of potential "sibling" templates named by new_template_file located |
39 A list of potential "sibling" templates named by new_template_file located |
37 in the paths of the templates in the supplied list. For example, from: |
40 in the paths of the templates in the supplied list. For example, from: |
38 ['foo/bar/the_old_template.html', 'foo/the_old_template.html'] |
41 ['foo/bar/the_old_template.html', 'foo/the_old_template.html'] |
39 to: |
42 to: |
40 ['foo/bar/some_new_template.html', 'foo/some_new_template.html'] |
43 ['foo/bar/some_new_template.html', 'foo/some_new_template.html'] |
41 """ |
44 """ |
42 if not isinstance(templates, (list, tuple)): |
45 if not isinstance(templates, (list, tuple)): |
43 templates = [templates] |
46 templates = [templates] |
44 |
47 |
45 return [ |
48 if default_template is None: |
46 '%s/%s' % (t.rsplit('/', 1)[0], new_template_file) for t in templates] |
49 default_template = [] |
|
50 |
|
51 if not isinstance(default_template, (list, tuple)): |
|
52 default_template = [default_template] |
|
53 |
|
54 sibling_templates = [ |
|
55 '%s/%s' % (t.rsplit('/', 1)[0], new_template_file) for t in templates] |
|
56 |
|
57 return sibling_templates + default_template |