mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Swift: integrated template name in dataclass
This commit is contained in:
@@ -83,7 +83,7 @@ def generate(opts, renderer):
|
|||||||
includes=get_includes(data, include_dir=input.parent),
|
includes=get_includes(data, include_dir=input.parent),
|
||||||
declarations=get_declarations(data))
|
declarations=get_declarations(data))
|
||||||
|
|
||||||
renderer.render("dbscheme", out, dbscheme)
|
renderer.render(dbscheme, out)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -97,6 +97,8 @@ class DbSchemeInclude:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DbScheme:
|
class DbScheme:
|
||||||
|
template: ClassVar = 'dbscheme'
|
||||||
|
|
||||||
src: str
|
src: str
|
||||||
includes: List[DbSchemeInclude]
|
includes: List[DbSchemeInclude]
|
||||||
declarations: List[DbDecl]
|
declarations: List[DbDecl]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ https://mustache.github.io/
|
|||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
import pathlib
|
||||||
|
|
||||||
import pystache
|
import pystache
|
||||||
|
|
||||||
@@ -39,14 +40,16 @@ class Renderer:
|
|||||||
def rendered(self):
|
def rendered(self):
|
||||||
return self.written | self.skipped
|
return self.written | self.skipped
|
||||||
|
|
||||||
def render(self, name, output, data):
|
def render(self, data, output: pathlib.Path):
|
||||||
""" Render the template called `name` in the template directory, writing to `output` using `data` as context
|
""" Render `data` to `output`.
|
||||||
|
|
||||||
|
`data` must have a `template` attribute denoting which template to use from the template directory.
|
||||||
|
|
||||||
If the file is unchanged, then no write is performed (and `done_something` remains unchanged)
|
If the file is unchanged, then no write is performed (and `done_something` remains unchanged)
|
||||||
"""
|
"""
|
||||||
mnemonic, _, _ = name.lower().partition(".")
|
mnemonic = type(data).__name__
|
||||||
output.parent.mkdir(parents=True, exist_ok=True)
|
output.parent.mkdir(parents=True, exist_ok=True)
|
||||||
data = self.r.render_name(name, data, generator=self.generator)
|
data = self.r.render_name(data.template, data, generator=self.generator)
|
||||||
if output.is_file():
|
if output.is_file():
|
||||||
with open(output, "rb") as file:
|
with open(output, "rb") as file:
|
||||||
if _md5(data.encode()) == _md5(file.read()):
|
if _md5(data.encode()) == _md5(file.read()):
|
||||||
|
|||||||
Reference in New Issue
Block a user