Generate apis.html and css-properties.json for docs as part of crates’ build scripts

… rather than as an extra step after `cargo doc`.
This helps always using the correct set of CSS properties
(for layout 2013 v.s. 2020).
This commit is contained in:
Simon Sapin 2019-07-29 18:57:20 +02:00
parent ddb4e369dd
commit 0215d09ccb
8 changed files with 67 additions and 173 deletions

View file

@ -101,21 +101,32 @@ def main():
pref_attr = "servo_2013_pref"
if engine == "servo-2020":
pref_attr = "servo_2020_pref"
names_and_prefs = [
(prop.name, getattr(prop, pref_attr))
for p in properties.longhands + properties.shorthands
if p.enabled_in_content()
for prop in [p] + p.alias
]
write(OUT_DIR, "css_properties.json", json.dumps(names_and_prefs, indent=4))
properties_dict = {
kind: {
p.name: {
"pref": getattr(p, pref_attr)
}
for prop in properties_list
if prop.enabled_in_content()
for p in [prop] + prop.alias
}
for kind, properties_list in [
("longhands", properties.longhands),
("shorthands", properties.shorthands)
]
}
as_html = render(os.path.join(BASE, "properties.html.mako"), properties=properties_dict)
as_json = json.dumps(properties_dict, indent=4, sort_keys=True)
doc_servo = os.path.join(BASE, "..", "..", "..", "target", "doc", "servo")
write(doc_servo, "css-properties.html", as_html)
write(doc_servo, "css-properties.json", as_json)
write(OUT_DIR, "css-properties.json", as_json)
elif output == "geckolib":
if len(sys.argv) < 4:
abort(usage)
template = sys.argv[3]
header = render(template, data=properties)
sys.stdout.write(header)
elif output == "html":
write_html(properties)
def abort(message):
@ -153,19 +164,5 @@ def write(directory, filename, content):
abort("Found \"{}\" in {} ({})".format(python_addr.group(0), filename, full_path))
def write_html(properties):
properties = dict(
(p.name, {
"flag": p.servo_2013_pref,
"shorthand": hasattr(p, "sub_properties")
})
for p in properties.longhands + properties.shorthands
)
doc_servo = os.path.join(BASE, "..", "..", "..", "target", "doc", "servo")
html = render(os.path.join(BASE, "properties.html.mako"), properties=properties)
write(doc_servo, "css-properties.html", html)
write(doc_servo, "css-properties.json", json.dumps(properties, indent=4))
if __name__ == "__main__":
main()

View file

@ -3,38 +3,29 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="API documentation for the Rust `servo` crate.">
<meta name="keywords" content="rust, rustlang, rust-lang, servo">
<title>Supported CSS properties - servo - Rust</title>
<title>Supported CSS properties in Servo</title>
<link rel="stylesheet" type="text/css" href="../normalize.css">
<link rel="stylesheet" type="text/css" href="../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../main.css">
<link rel="stylesheet" type="text/css" href="../light.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<section id='main' class="content mod">
<h1 class='fqn'><span class='in-band'>CSS properties currently supported in <a class='mod' href=''>Servo</a></span></h1>
<div id='properties' class='docblock'>
<table>
<h1 class='fqn'><span class='in-band'>CSS properties currently supported in Servo</span></h1>
% for kind, props in sorted(properties.items()):
<h2>${kind.capitalize()}</h2>
<table>
<tr>
<th>Name</th>
<th>Pref</th>
</tr>
% for name, data in sorted(props.items()):
<tr>
<th>Property</th>
<th>Flag</th>
<th>Shorthand</th>
<td><code>${name}</code></td>
<td><code>${data['pref'] or ''}</code></td>
</tr>
% for prop in properties:
<tr>
<td>${prop}</td>
<td>${properties[prop]['flag']}</td>
<td>${properties[prop]['shorthand']}</td>
</tr>
% endfor
</table>
</div>
% endfor
</table>
% endfor
</section>
</body>
</html>