docs: show the full information for deprecated functions

pull/13865/head
Delyan Angelov 2022-03-29 15:17:55 +03:00
parent fd34ebd84e
commit 7ee93c8a20
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 25 additions and 13 deletions

View File

@ -12,9 +12,13 @@ import v.doc
import v.pref
const (
css_js_assets = ['doc.css', 'normalize.css', 'doc.js', 'dark-mode.js']
default_theme = os.resource_abs_path('theme')
link_svg = '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>'
css_js_assets = ['doc.css', 'normalize.css', 'doc.js', 'dark-mode.js']
default_theme = os.resource_abs_path('theme')
link_svg = '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>'
single_quote = "'"
double_quote = '"'
no_quotes_replacement = [single_quote, '', double_quote, '']
)
enum HighlightTokenTyp {
@ -385,8 +389,9 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
highlighted_code := html_highlight(dn.content, tb)
node_class := if dn.kind == .const_group { ' const' } else { '' }
sym_name := get_sym_name(dn)
has_deprecated := 'deprecated' in dn.tags
mut tags := dn.tags.filter(it != 'deprecated')
mut deprecated_tags := dn.tags.filter(it.starts_with('deprecated'))
deprecated_tags.sort()
mut tags := dn.tags.filter(!it.starts_with('deprecated'))
tags.sort()
mut node_id := get_node_id(dn)
mut hash_link := if !head { ' <a href="#$node_id">#</a>' } else { '' }
@ -406,13 +411,12 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
}
dnw.write_string('</div>')
}
if tags.len > 0 || has_deprecated {
mut attributes := if has_deprecated {
'<div class="attribute attribute-deprecated">deprecated</div>'
} else {
''
}
attributes += tags.map('<div class="attribute">$it</div>').join('')
if deprecated_tags.len > 0 {
attributes := deprecated_tags.map('<div class="attribute attribute-deprecated">${no_quotes(it)}</div>').join('')
dnw.writeln('<div class="attributes">$attributes</div>')
}
if tags.len > 0 {
attributes := tags.map('<div class="attribute">$it</div>').join('')
dnw.writeln('<div class="attributes">$attributes</div>')
}
if !head && dn.content.len > 0 {
@ -494,3 +498,7 @@ fn write_toc(dn doc.DocNode, mut toc strings.Builder) {
}
toc.writeln('</li>')
}
fn no_quotes(s string) string {
return s.replace_each(no_quotes_replacement)
}

View File

@ -260,7 +260,11 @@ pub fn (mut d Doc) stmt(stmt ast.Stmt, filename string) ?DocNode {
}
ast.FnDecl {
if stmt.is_deprecated {
node.tags << 'deprecated'
for sa in stmt.attrs {
if sa.name.starts_with('deprecated') {
node.tags << sa.str()
}
}
}
if stmt.is_unsafe {
node.tags << 'unsafe'