@@ -28,18 +28,23 @@ def render(self, data, output: pathlib.Path):
2828
2929 `data` must have a `template` attribute denoting which template to use from the template directory.
3030
31- If the file is unchanged, then no write is performed (and `done_something` remains unchanged)
32-
33- If `guard_base` is provided, it must be a path at the root of `output` and a header guard will be injected in
34- the template based off of the relative path of `output` in `guard_base`
31+ Optionally, `data` can also have an `extensions` attribute denoting list of file extensions: they will all be
32+ appended to the template name with an underscore and be generated in turn.
3533 """
3634 mnemonic = type (data ).__name__
3735 output .parent .mkdir (parents = True , exist_ok = True )
38- data = self ._r .render_name (data .template , data , generator = self ._generator )
39- with open (output , "w" ) as out :
40- out .write (data )
41- log .debug (f"generated { mnemonic } { output .name } " )
42- self .written .add (output )
36+ extensions = getattr (data , "extensions" , [None ])
37+ for ext in extensions :
38+ output_filename = output
39+ template = data .template
40+ if ext :
41+ output_filename = output_filename .with_suffix (f".{ ext } " )
42+ template += f"_{ ext } "
43+ contents = self ._r .render_name (template , data , generator = self ._generator )
44+ with open (output_filename , "w" ) as out :
45+ out .write (contents )
46+ log .debug (f"{ mnemonic } : generated { output .name } " )
47+ self .written .add (output_filename )
4348
4449 def cleanup (self , existing ):
4550 """ Remove files in `existing` for which no `render` has been called """
0 commit comments