mirror of
https://github.com/googlefonts/noto-emoji.git
synced 2025-06-07 23:37:58 +00:00
Use standard string.Template mechanism.
This commit is contained in:
parent
ff93f20f66
commit
fabd80e194
1 changed files with 9 additions and 16 deletions
|
@ -29,6 +29,7 @@ import os
|
||||||
from os import path
|
from os import path
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from nototools import tool_utils
|
from nototools import tool_utils
|
||||||
|
@ -436,38 +437,30 @@ def _parse_annotation_file(afile):
|
||||||
|
|
||||||
|
|
||||||
def _instantiate_template(template, arg_dict):
|
def _instantiate_template(template, arg_dict):
|
||||||
id_regex = re.compile('{{([a-zA-Z0-9_]+)}}')
|
id_regex = re.compile(r'\$([a-zA-Z0-9_]+)')
|
||||||
ids = set(m.group(1) for m in id_regex.finditer(template))
|
ids = set(m.group(1) for m in id_regex.finditer(template))
|
||||||
keyset = set(arg_dict.keys())
|
keyset = set(arg_dict.keys())
|
||||||
missing_ids = ids - keyset
|
|
||||||
extra_args = keyset - ids
|
extra_args = keyset - ids
|
||||||
if extra_args:
|
if extra_args:
|
||||||
print >> sys.stderr, (
|
print >> sys.stderr, (
|
||||||
'the following %d args are unused:\n%s' %
|
'the following %d args are unused:\n%s' %
|
||||||
(len(extra_args), ', '.join(sorted(extra_args))))
|
(len(extra_args), ', '.join(sorted(extra_args))))
|
||||||
text = template
|
return string.Template(template).substitute(arg_dict)
|
||||||
if missing_ids:
|
|
||||||
raise ValueError(
|
|
||||||
'the following %d ids in the template have no args:\n%s' %
|
|
||||||
(len(missing_ids), ', '.join(sorted(missing_ids))))
|
|
||||||
for arg in ids:
|
|
||||||
text = re.sub('{{%s}}' % arg, arg_dict[arg], text)
|
|
||||||
return text
|
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE = """<!DOCTYPE html>
|
TEMPLATE = """<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>{{title}}</title>{{fontFaceStyle}}
|
<title>$title</title>$fontFaceStyle
|
||||||
<style>{{style}}</style>
|
<style>$style</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!--
|
<!--
|
||||||
{{info}}
|
$info
|
||||||
-->
|
-->
|
||||||
<h3>{{title}}</h3>
|
<h3>$title</h3>
|
||||||
{{content}}
|
$content
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
@ -629,4 +622,4 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue