Skip to content

Commit 24697fe

Browse files
committed
Swift: integrated template name in dataclass
1 parent 197ea5b commit 24697fe

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

swift/codegen/dbschemegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def generate(opts, renderer):
8383
includes=get_includes(data, include_dir=input.parent),
8484
declarations=get_declarations(data))
8585

86-
renderer.render("dbscheme", out, dbscheme)
86+
renderer.render(dbscheme, out)
8787

8888

8989
if __name__ == "__main__":

swift/codegen/lib/dbscheme.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class DbSchemeInclude:
9797

9898
@dataclass
9999
class DbScheme:
100+
template: ClassVar = 'dbscheme'
101+
100102
src: str
101103
includes: List[DbSchemeInclude]
102104
declarations: List[DbDecl]

swift/codegen/lib/render.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import hashlib
99
import logging
10+
import pathlib
1011

1112
import pystache
1213

@@ -39,14 +40,16 @@ def done_something(self):
3940
def rendered(self):
4041
return self.written | self.skipped
4142

42-
def render(self, name, output, data):
43-
""" Render the template called `name` in the template directory, writing to `output` using `data` as context
43+
def render(self, data, output: pathlib.Path):
44+
""" Render `data` to `output`.
45+
46+
`data` must have a `template` attribute denoting which template to use from the template directory.
4447
4548
If the file is unchanged, then no write is performed (and `done_something` remains unchanged)
4649
"""
47-
mnemonic, _, _ = name.lower().partition(".")
50+
mnemonic = type(data).__name__
4851
output.parent.mkdir(parents=True, exist_ok=True)
49-
data = self.r.render_name(name, data, generator=self.generator)
52+
data = self.r.render_name(data.template, data, generator=self.generator)
5053
if output.is_file():
5154
with open(output, "rb") as file:
5255
if _md5(data.encode()) == _md5(file.read()):

0 commit comments

Comments
 (0)