// 2011.03.14 # Doj
// Функции для генерации документации в формате googlecode'а

namespace GOOGLECODE
  : dembroname->simplename ( B: x - B: y)
    // заменяем значки на текстовые эквиваленты
    " _" \" _underline_"
    " #" \" _hash_"
    " ?" \" _question_"
    " @" \" _dog_"
    " !" \" _ex_"
    " >" \" _gt_"
    " <" \" _lt_"
    " =" \" _eq_"
    " +" \" _plus_"
    " -" \" _minus_"
    " *" \" _mul_"
    " /" \" _div_"
    " \" \" _slash_"
    " '" \" _q_"
    " ^"" \" _dq_"
    " :" \" _colon_"
    " ;" \" _endcolon_"
    " ." \" _dot_"
    " [" \" _lsq_"
    " ]" \" _rsq_"
    " {" \" _lfg_"
    " }" \" _rfg_"
    " (" \" _lcr_"
    " )" \" _rcr_"
    " ^^" \" _lid_"
    " ," \" _comma_"
  ;
  : dembroname->articlename dembroname->simplename swap+" article_" ;
  : dembroname->articlename.wiki dembroname->articlename +" .wiki" ;

  : articlebody->body ( B: x - B: y)
    " <code>" \" {{{"
    " </code>" \" }}}"
    " <inline>" \" `"
    " </inline>" \" `"
    " <article>" \" [article_"
    " </article>" \" ]"
  ;

  variable file
  bvariable folder
  bvariable *prefix

  : prefix+ ( B: x -- B: y) *prefix b@ bswap str+ ;
  : file@ file @ ;
  : open ( s) file-w file-open file ! ;
  // : open-article ( i) folder b@ " article" str+ int->str str+ " .wiki" str+ open ;
  : open-article ( i) folder b@ 
                      *help-names bdyn[]@ dembroname->articlename.wiki prefix+
                      str+ open ;
  : close file@ file-close ;
  : int. . ; 
  : . ( s) file@ file-str-write ; 
  : cr file@ file-cr ; 
  : header. ( i) " == " *help-names bdyn[]@ str+ "  ==" str+ . cr ; 
  : body. ( i) dup *help-articles bdyn[]@ bdup str0 str= 
               if bdrop *help-summary bdyn[]@ else drop then 
               articlebody->body . cr ;
  : article ( i) dup open-article dup header. body. close ;
  : generate-articles
    0 begin 
      dup *help-names bdyn# < 
    while 
      dup article 
      1+ 
    repeat drop
  ;
  : generate-group ( i)
    folder b@ 
    " group_" dup *help-group-names bdyn[]@ str+ 
    +" .wiki" prefix+ str+ open

    " === " . dup *help-group-names bdyn[]@ . "  ===" . cr
    dup *help-group-descriptions bdyn[]@ articlebody->body . cr
    0 begin 
      dup *help-names bdyn# < 
    while 
      over over *help-group dyn[]@ = if 
        "   # [" . dup *help-names bdyn[]@ bdup dembroname->articlename . 
            "  " . . " ] " . dup *help-summary bdyn[]@ . cr
      then 1+ 
    repeat drop drop
    close
  ;
  : generate-groups 
    0 begin 
      dup *help-group-names bdyn# < 
    while 
      dup generate-group
      1+ 
    repeat drop
  ;
  : generate-group-summary ( i)
    " ==== [" . dup *help-group-names " group_" bdyn[]@ bdup brrot str+ . "  " .
               . " ] ====" . cr cr
    dup *help-group-descriptions bdyn[]@ articlebody->body . cr cr
    0 begin 
      dup *help-names bdyn# < 
    while 
      over over *help-group dyn[]@ = if 
        " [" . dup *help-names bdyn[]@ bdup dembroname->articlename . 
            "  " . . " ] " .
      then 1+ 
    repeat drop drop cr
  ;
  : generate-main
    folder b@ " doc.wiki" prefix+ str+ open
    " = Документация =" . cr 
    0 begin 
      dup *help-group-names bdyn# < 
    while 
      dup generate-group-summary
      1+ 
    repeat drop
    close
  ;
  : generate-docs ( s-) folder b! 
                        generate-articles 
                        generate-groups 
                        generate-main ;
// {{{ one file
  : generate-as-one-file-group ( i-)
    " === " . dup *help-group-names bdyn[]@ . "  ===" . cr
    0 begin 
      dup *help-names bdyn# < 
    while 
      over over *help-group dyn[]@ = if 
        " *" . dup *help-names bdyn[]@ +" `" swap+" `" . " * " . 
        dup *help-articles bdyn[]@ 
        bdup str0 str= if 
                bdrop dup *help-summary bdyn[]@ swap+" <inline>" +" </inline>"
        then
        articlebody->body
        . cr " <br>" .
      then 1+ 
    repeat drop drop cr
  ;
  : generate-as-one-file ( s-)
    " doc.wiki" prefix+ str+ open
    0 begin 
      dup *help-group-names bdyn# < 
    while 
      dup generate-as-one-file-group
      1+ 
    repeat drop
    close
  ;
// }}}
  : prefix! ( B: s) *prefix b! ;
  // : generate-docs ( s-) 0 begin dup 100 < while dup . 1+ repeat ;
\namespace
