doc: Add a standard way to add metadata to the property documentation.

This commit is contained in:
Emmanuel Lepage Vallee 2022-07-12 23:17:53 -07:00
parent a698d20e81
commit 27f329a229
3 changed files with 40 additions and 15 deletions

View File

@ -299,6 +299,16 @@ create_type {
)
end
end
-- Allow the template to be shorter by using a for-loop.
for _, mt in ipairs {"propertyunit", "rangestart", "rangestop" } do
local tag_desc = named_tags[mt]
if item.tags[mt] and item.tags[mt][1] then
local title = tag_desc.title or mt
item:add_metadata(title, item.tags[mt][1])
end
end
end
}
@ -901,6 +911,7 @@ add_custom_tag {
-- apoint or a pixel.
add_custom_tag {
name = "propertyunit",
title = "Unit",
hidden = true,
auto_subtags = false
}
@ -916,11 +927,13 @@ add_custom_tag {
-- Some values, mostly bytes, have a minimum and maximum value.
add_custom_tag {
name = "rangestart",
title = "Range starts",
hidden = true,
auto_subtags = false
}
add_custom_tag {
name = "rangestop",
title = "Range stops",
hidden = true,
auto_subtags = false
}
@ -1204,7 +1217,7 @@ local function init_custom_types(item)
-- Give each item an unique identifier so the JavaScript can locate them.
item.uid, item_id = item_id, item_id + 1
item.delims, item.auto_usage, item.auto_params = {}, {}, {}
item.delims, item.auto_usage, item.auto_params, item.metadata = {}, {}, {}, {}
local to_rm = {}
@ -1278,6 +1291,18 @@ local function init_custom_types(item)
return nil, nil, extra
end
-- Recursive way to annotate property-like objects.
local amt
amt = function(self, title, value, children)
self.metadata[#self.metadata+1] = {
title = title,
value = value,
children = children or {},
add_metadata = amt
}
end
item.add_metadata = amt
item.is_init = true
end

View File

@ -70,8 +70,7 @@ dd > code,
td code,
span.default_value,
.see_also_description code,
.important_box code,
.property_type code
.important_box code
{
background-color: #eaedf587;
padding-left: 3px;
@ -524,7 +523,7 @@ dl.function dd {
margin-bottom: 15px;
}
#content dl.function dd h3, .property_type i {
#content dl.function dd h3, .see_also i {
margin-top: 0px;
margin-left: 0px;
padding-left: 0px;
@ -748,8 +747,3 @@ pre .url { color: #272fc2; text-decoration: underline; }
.copy-link--failure {
background-color: red;
}
.property_type {
display: inline-block;
margin-left: 15px;
}

View File

@ -378,17 +378,23 @@
$(M(ldoc.descript(item),item))
# if kind == "Object properties" and item.params[1] then
</dd>
<h3>Constraints:</h3>
<span class="property_type">
<br/>
<table class="see_also">
# if item:default_of_param(item.params[1]) then
<i>Default value: </b> <code>$(item:default_of_param(item.params[1]))</code><br/>
<tr><td><i>Default value: </i></td><td> <code>$(item:default_of_param(item.params[1]))</code></td><tr/>
# end
# if item.params[1] then
<i>Type constraint: </b> $(M(item.params.map[item.params[1]],item))<br/>
# for _, metadata in ldoc.ipairs(item.metadata or {}) do
<tr><td><i>$(metadata.title): </i></td><td> $(metadata.value)</td><tr/>
# for _, child in ldoc.ipairs(metadata.children) do
<tr class="see_also_sublist"><td><i>$(child.title): </i></td><td> $(child.value)</td><tr/>
# end
# end
# if item.params.map[item.params[1]] and item.params.map[item.params[1]] ~= "" then
<tr><td><i>Valid values: </i></td><td> $(M(item.params.map[item.params[1]],item))</td><tr/>
# end
</table>
</span>
<dd>
# elseif show_parms and item.params and #item.params > 0 and not item.hide_params then
# local subnames = module.kinds:type_of(item).subnames
# if subnames then