fuel.help: breadcrumbs in article pages too

modern-harvey2
Björn Lindqvist 2017-07-04 17:05:46 +02:00
parent 1265bb3b5c
commit 2ffb7a2669
3 changed files with 30 additions and 4 deletions

View File

@ -1,6 +1,10 @@
USING: fuel.help.private help.markup help.syntax strings ;
USING: fuel.help.private help.markup help.syntax sequences strings ;
IN: fuel.help
HELP: article-parents
{ $values { "article-name" string } { "parents" sequence } }
{ $description "All the parent articles for the article and ensures that the ancestor always is 'handbook'." } ;
HELP: get-article
{ $values { "name" string } { "str" string } }
{ $description "If an article and a vocab share name, we render the vocab instead." } ;

View File

@ -28,3 +28,9 @@ IN: fuel.help.tests
"io" vocab-help-article?
"help.lint" vocab-help-article?
] unit-test
{
{ "handbook" "io.servers" }
} [
"server-config" article-parents
] unit-test

View File

@ -12,15 +12,23 @@ SYMBOLS: $doc-path $next-link $prev-link $fuel-nav-crumbs ;
: common-crumbs ( -- crumbs )
{ "handbook" "vocab-index" } [ dup article-title \ article 3array ] map ;
: vocab-own-crumbs ( vocab -- crumbs )
: vocab-own-crumbs ( vocab-name -- crumbs )
"." split unclip [
[ CHAR: . suffix ] dip append
] accumulate swap suffix
[ dup "." split last \ vocab 3array ] map ;
: vocab-crumbs ( vocab -- crumbs )
: vocab-crumbs ( vocab-name -- crumbs )
vocab-own-crumbs common-crumbs prepend ;
: article-parents ( article-name -- parents )
[ article-parent ] follow
dup last "handbook" = [ "handbook" suffix ] unless
reverse but-last ;
: article-crumbs ( article-name -- crumbs )
article-parents [ dup article-title \ article 3array ] map ;
<PRIVATE
: find-word ( name -- word/f )
@ -134,8 +142,16 @@ PRIVATE>
: format-index ( seq -- seq )
[ [ >link name>> ] [ article-title ] bi 2array \ $subsection prefix ] map ;
: article-element ( name -- element )
\ article swap dup lookup-article
[ nip title>> ]
[
[ article-crumbs \ $fuel-nav-crumbs prefix ] [ content>> ] bi*
\ $nl prefix swap prefix
] 2bi 3array ;
: vocab-help-article? ( name -- ? )
dup lookup-vocab [ help>> = ] [ drop f ] if* ;
: get-article ( name -- str )
dup vocab-help-article? [ vocab-help ] [ lookup-article ] if ;
dup vocab-help-article? [ vocab-help ] [ article-element ] if ;