<commit_before>! Copyright (C) 2005, 2010 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs classes classes.tuple
classes.error combinators combinators.short-circuit continuations
debugger effects generic help.crossref help.markup help.stylesheet
help.topics io io.styles kernel make namespaces prettyprint
sequences sorting vocabs words words.symbol ;
IN: help

GENERIC: word-help* ( word -- content )

: word-help ( word -- content )
    dup "help" word-prop [ ] [
        dup word-help* dup
        [ swap 2array 1array ] [ 2drop f ] if
    ] ?if ;

: $predicate ( element -- )
    { { "object" object } { "?" boolean } } $values
    [
        "Tests if the object is an instance of the " ,
        first "predicating" word-prop <$link> ,
        " class." ,
    ] { } make $description ;

M: word word-help* drop f ;

M: predicate word-help* drop \ $predicate ;

: all-articles ( -- seq )
    articles get keys
    all-words [ word-help ] filter append ;

: orphan-articles ( -- seq )
    articles get keys
    [ article-parent ] reject ;

: xref-help ( -- )
    all-articles [ xref-article ] each ;

: error? ( word -- ? )
    {
        [ error-class? ]
        [ \ $error-description swap word-help elements empty? not ]
    } 1|| ;

: sort-articles ( seq -- newseq )
    [ dup article-title ] { } map>assoc sort-values keys ;

: all-errors ( -- seq )
    all-words [ error? ] filter sort-articles ;

M: word valid-article? drop t ;

M: word article-name name>> ;

M: word article-title
    dup [ parsing-word? ] [ symbol? ] bi or [
        name>>
    ] [
        [ unparse ]
        [ stack-effect [ effect>string " " prepend ] [ "" ] if* ] bi
        append
    ] if ;

<PRIVATE

: (word-help) ( word -- element )
    [
        {
            [ \ $vocabulary swap 2array , ]
            [ word-help % ]
            [ \ $related swap 2array , ]
            [ dup global at [ get-global \ $value swap 2array , ] [ drop ] if ]
            [ \ $definition swap 2array , ]
        } cleave
    ] { } make ;

M: word article-content (word-help) ;

: word-with-methods ( word -- elements )
    [
        [ (word-help) % ]
        [ \ $methods swap 2array , ]
        bi
    ] { } make ;

PRIVATE>

M: generic article-content word-with-methods ;

M: class article-content word-with-methods ;

M: word article-parent "help-parent" word-prop ;

M: word set-article-parent swap "help-parent" set-word-prop ;

: ($title) ( topic -- )
    [ [ article-title ] [ >link ] bi write-object ] ($block) ;

: $navigation-row ( content element -- )
    prefix 1array , ;

: ($navigation-table) ( element -- )
    help-path-style get table-style [ $table ] with-variable ;

: ($navigation-prev) ( topic -- )
    [ prev-article [ 1array \ $long-link $navigation-row ] when* ] 
    { } make [ ($navigation-table) ] unless-empty ;

: ($navigation-next) ( topic -- )
    [ next-article [ 1array \ $long-link $navigation-row ] when* ] 
    { } make [ ($navigation-table) ] unless-empty ;

: ($navigation-path) ( topic -- )
    help-path-style get
       [ help-path [ reverse $breadcrumbs ] unless-empty ]
    with-style ;<commit_msg>help: Added arrows in prev/next links<commit_after>! Copyright (C) 2005, 2010 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs classes classes.tuple
classes.error combinators combinators.short-circuit continuations
debugger effects generic help.crossref help.markup help.stylesheet
help.topics io io.styles kernel make namespaces prettyprint
sequences sorting vocabs words words.symbol ;
IN: help

GENERIC: word-help* ( word -- content )

: word-help ( word -- content )
    dup "help" word-prop [ ] [
        dup word-help* dup
        [ swap 2array 1array ] [ 2drop f ] if
    ] ?if ;

: $predicate ( element -- )
    { { "object" object } { "?" boolean } } $values
    [
        "Tests if the object is an instance of the " ,
        first "predicating" word-prop <$link> ,
        " class." ,
    ] { } make $description ;

M: word word-help* drop f ;

M: predicate word-help* drop \ $predicate ;

: all-articles ( -- seq )
    articles get keys
    all-words [ word-help ] filter append ;

: orphan-articles ( -- seq )
    articles get keys
    [ article-parent ] reject ;

: xref-help ( -- )
    all-articles [ xref-article ] each ;

: error? ( word -- ? )
    {
        [ error-class? ]
        [ \ $error-description swap word-help elements empty? not ]
    } 1|| ;

: sort-articles ( seq -- newseq )
    [ dup article-title ] { } map>assoc sort-values keys ;

: all-errors ( -- seq )
    all-words [ error? ] filter sort-articles ;

M: word valid-article? drop t ;

M: word article-name name>> ;

M: word article-title
    dup [ parsing-word? ] [ symbol? ] bi or [
        name>>
    ] [
        [ unparse ]
        [ stack-effect [ effect>string " " prepend ] [ "" ] if* ] bi
        append
    ] if ;

<PRIVATE

: (word-help) ( word -- element )
    [
        {
            [ \ $vocabulary swap 2array , ]
            [ word-help % ]
            [ \ $related swap 2array , ]
            [ dup global at [ get-global \ $value swap 2array , ] [ drop ] if ]
            [ \ $definition swap 2array , ]
        } cleave
    ] { } make ;

M: word article-content (word-help) ;

: word-with-methods ( word -- elements )
    [
        [ (word-help) % ]
        [ \ $methods swap 2array , ]
        bi
    ] { } make ;

PRIVATE>

M: generic article-content word-with-methods ;

M: class article-content word-with-methods ;

M: word article-parent "help-parent" word-prop ;

M: word set-article-parent swap "help-parent" set-word-prop ;

: ($title) ( topic -- )
    [ [ article-title ] [ >link ] bi write-object ] ($block) ;

: $navigation-row-prev ( content element -- )
    prefix 1array "<" prefix , ;

: $navigation-row-next ( content element -- )
    prefix 1array ">" suffix , ;

: ($navigation-table) ( element -- )
    help-path-style get table-style [ $table ] with-variable ;

: ($navigation-prev) ( topic -- )
    [ prev-article [ 1array \ $long-link $navigation-row-prev ] when* ] 
    { } make [ ($navigation-table) ] unless-empty ;

: ($navigation-next) ( topic -- )
    [ next-article [ 1array \ $long-link $navigation-row-next ] when* ] 
    { } make [ ($navigation-table) ] unless-empty ;

: ($navigation-path) ( topic -- )
    help-path-style get
       [ help-path [ reverse $breadcrumbs ] unless-empty ]
    with-style ;
{'fraction_non_alphanumeric': 0.14469602977667495, 'fraction_numerical': 0.006358560794044665, 'mean_word_length': 2.2277277277277276, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7449089', 'n_tokens_mistral': 2115, 'n_tokens_neox': 2045, 'n_words': 550}