Help pages now have next/prev links
parent
d001237921
commit
4849830ebd
|
@ -13,7 +13,7 @@ io.streams.string continuations debugger compiler.units eval ;
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
"foo" article-children
|
"foo" article-children
|
||||||
"foo" "help.crossref.tests" lookup 1array sequence=
|
"foo" "help.crossref.tests" lookup >link 1array sequence=
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ "foo" ] [ "foo" "help.crossref.tests" lookup article-parent ] unit-test
|
[ "foo" ] [ "foo" "help.crossref.tests" lookup article-parent ] unit-test
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
! Copyright (C) 2005, 2007 Slava Pestov.
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays definitions generic assocs
|
USING: arrays definitions generic assocs math fry
|
||||||
io kernel namespaces prettyprint prettyprint.sections
|
io kernel namespaces prettyprint prettyprint.sections
|
||||||
sequences words summary classes help.topics help.markup ;
|
sequences words summary classes help.topics help.markup ;
|
||||||
IN: help.crossref
|
IN: help.crossref
|
||||||
|
|
||||||
|
: article-links ( topic elements -- seq )
|
||||||
|
[ article-content ] dip
|
||||||
|
collect-elements [ >link ] map ;
|
||||||
|
|
||||||
: article-children ( topic -- seq )
|
: article-children ( topic -- seq )
|
||||||
article-content { $subsection } collect-elements ;
|
{ $subsection } article-links ;
|
||||||
|
|
||||||
M: link uses
|
M: link uses
|
||||||
article-content
|
{ $subsection $link $see-also } article-links ;
|
||||||
{ $subsection $link $see-also }
|
|
||||||
collect-elements [ \ f or ] map ;
|
|
||||||
|
|
||||||
: help-path ( topic -- seq )
|
: help-path ( topic -- seq )
|
||||||
[ article-parent ] follow rest ;
|
[ article-parent ] follow rest ;
|
||||||
|
@ -24,3 +26,13 @@ M: link uses
|
||||||
|
|
||||||
: unxref-article ( topic -- )
|
: unxref-article ( topic -- )
|
||||||
>link unxref ;
|
>link unxref ;
|
||||||
|
|
||||||
|
: prev/next-article ( article n -- article' )
|
||||||
|
[ dup article-parent dup ] dip
|
||||||
|
'[ article-children [ index _ + ] keep ?nth ]
|
||||||
|
[ 2drop f ]
|
||||||
|
if ;
|
||||||
|
|
||||||
|
: prev-article ( article -- prev ) -1 prev/next-article ;
|
||||||
|
|
||||||
|
: next-article ( article -- next ) 1 prev/next-article ;
|
|
@ -93,28 +93,32 @@ M: word article-parent "help-parent" word-prop ;
|
||||||
|
|
||||||
M: word set-article-parent swap "help-parent" set-word-prop ;
|
M: word set-article-parent swap "help-parent" set-word-prop ;
|
||||||
|
|
||||||
: $doc-path ( article -- )
|
: ($title) ( topic -- )
|
||||||
help-path [
|
[ [ article-title ] [ >link ] bi write-object ] ($block) ;
|
||||||
[
|
|
||||||
help-path-style get [
|
: $navigation-row ( content element label -- )
|
||||||
"Parent topics: " write $links
|
[ prefix 1array ] dip prefix , ;
|
||||||
] with-style
|
|
||||||
] ($block)
|
: $navigation-table ( topic -- )
|
||||||
] unless-empty ;
|
[
|
||||||
|
[ help-path [ \ $links "Up:" $navigation-row ] unless-empty ]
|
||||||
|
[ prev-article [ 1array \ $long-link "Prev:" $navigation-row ] when* ]
|
||||||
|
[ next-article [ 1array \ $long-link "Next:" $navigation-row ] when* ]
|
||||||
|
tri
|
||||||
|
] { } make [ $table ] unless-empty ;
|
||||||
|
|
||||||
: $title ( topic -- )
|
: $title ( topic -- )
|
||||||
title-style get [
|
title-style get [
|
||||||
title-style get [
|
title-style get [
|
||||||
dup [
|
[ ($title) ]
|
||||||
dup article-title swap >link write-object
|
[ help-path-style get [ $navigation-table ] with-style ] bi
|
||||||
] ($block) $doc-path
|
|
||||||
] with-nesting
|
] with-nesting
|
||||||
] with-style nl ;
|
] with-style nl ;
|
||||||
|
|
||||||
: print-topic ( topic -- )
|
: print-topic ( topic -- )
|
||||||
>link
|
>link
|
||||||
last-element off dup $title
|
last-element off
|
||||||
article-content print-content nl ;
|
[ $title ] [ article-content print-content nl ] bi ;
|
||||||
|
|
||||||
SYMBOL: help-hook
|
SYMBOL: help-hook
|
||||||
|
|
||||||
|
@ -125,12 +129,8 @@ help-hook global [ [ print-topic ] or ] change-at
|
||||||
|
|
||||||
: about ( vocab -- )
|
: about ( vocab -- )
|
||||||
dup require
|
dup require
|
||||||
dup vocab [ ] [
|
dup vocab [ ] [ no-vocab ] ?if
|
||||||
"No such vocabulary: " prepend throw
|
dup vocab-help [ help ] [
|
||||||
] ?if
|
|
||||||
dup vocab-help [
|
|
||||||
help
|
|
||||||
] [
|
|
||||||
"The " write vocab-name write
|
"The " write vocab-name write
|
||||||
" vocabulary does not define a main help article." print
|
" vocabulary does not define a main help article." print
|
||||||
"To define one, refer to \\ ABOUT: help" print
|
"To define one, refer to \\ ABOUT: help" print
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays definitions generic io kernel assocs
|
USING: accessors arrays definitions generic io kernel assocs
|
||||||
hashtables namespaces make parser prettyprint sequences strings
|
hashtables namespaces make parser prettyprint sequences strings
|
||||||
io.styles vectors words math sorting splitting classes slots
|
io.styles vectors words math sorting splitting classes slots fry
|
||||||
vocabs help.stylesheet help.topics vocabs.loader quotations ;
|
sets vocabs help.stylesheet help.topics vocabs.loader quotations ;
|
||||||
IN: help.markup
|
IN: help.markup
|
||||||
|
|
||||||
! Simple markup language.
|
! Simple markup language.
|
||||||
|
@ -157,6 +157,9 @@ ALIAS: $slot $snippet
|
||||||
: ($long-link) ( object -- )
|
: ($long-link) ( object -- )
|
||||||
[ article-title ] [ >link ] bi write-link ;
|
[ article-title ] [ >link ] bi write-link ;
|
||||||
|
|
||||||
|
: $long-link ( object -- )
|
||||||
|
first ($long-link) ;
|
||||||
|
|
||||||
: ($subsection) ( element quot -- )
|
: ($subsection) ( element quot -- )
|
||||||
[
|
[
|
||||||
subsection-style get [
|
subsection-style get [
|
||||||
|
@ -201,7 +204,7 @@ ALIAS: $slot $snippet
|
||||||
"See also" $heading $links ;
|
"See also" $heading $links ;
|
||||||
|
|
||||||
: related-words ( seq -- )
|
: related-words ( seq -- )
|
||||||
dup [ "related" set-word-prop ] curry each ;
|
dup '[ _ "related" set-word-prop ] each ;
|
||||||
|
|
||||||
: $related ( element -- )
|
: $related ( element -- )
|
||||||
first dup "related" word-prop remove
|
first dup "related" word-prop remove
|
||||||
|
@ -335,7 +338,8 @@ M: f ($instance)
|
||||||
|
|
||||||
GENERIC: elements* ( elt-type element -- )
|
GENERIC: elements* ( elt-type element -- )
|
||||||
|
|
||||||
M: simple-element elements* [ elements* ] with each ;
|
M: simple-element elements*
|
||||||
|
[ elements* ] with each ;
|
||||||
|
|
||||||
M: object elements* 2drop ;
|
M: object elements* 2drop ;
|
||||||
|
|
||||||
|
@ -346,13 +350,7 @@ M: array elements*
|
||||||
: elements ( elt-type element -- seq ) [ elements* ] { } make ;
|
: elements ( elt-type element -- seq ) [ elements* ] { } make ;
|
||||||
|
|
||||||
: collect-elements ( element seq -- elements )
|
: collect-elements ( element seq -- elements )
|
||||||
[
|
swap '[ _ elements [ rest ] map concat ] map concat prune ;
|
||||||
swap [
|
|
||||||
elements [
|
|
||||||
rest [ dup set ] each
|
|
||||||
] each
|
|
||||||
] curry each
|
|
||||||
] H{ } make-assoc keys ;
|
|
||||||
|
|
||||||
: <$link> ( topic -- element )
|
: <$link> ( topic -- element )
|
||||||
1array \ $link prefix ;
|
1array \ $link prefix ;
|
||||||
|
|
|
@ -15,6 +15,7 @@ GENERIC: >link ( obj -- obj )
|
||||||
M: link >link ;
|
M: link >link ;
|
||||||
M: vocab-spec >link ;
|
M: vocab-spec >link ;
|
||||||
M: object >link link boa ;
|
M: object >link link boa ;
|
||||||
|
M: f >link drop \ f >link ;
|
||||||
|
|
||||||
PREDICATE: word-link < link name>> word? ;
|
PREDICATE: word-link < link name>> word? ;
|
||||||
|
|
||||||
|
@ -73,4 +74,4 @@ M: f article-name drop \ f article-name ;
|
||||||
M: f article-title drop \ f article-title ;
|
M: f article-title drop \ f article-title ;
|
||||||
M: f article-content drop \ f article-content ;
|
M: f article-content drop \ f article-content ;
|
||||||
M: f article-parent drop \ f article-parent ;
|
M: f article-parent drop \ f article-parent ;
|
||||||
M: f set-article-parent drop \ f set-article-parent ;
|
M: f set-article-parent drop \ f set-article-parent ;
|
Loading…
Reference in New Issue