Tips of the day now implement the definition protocol

db4
Slava Pestov 2009-03-26 13:02:28 -05:00
parent 6ca02e9b37
commit 0eb415b671
2 changed files with 26 additions and 5 deletions

View File

@ -17,7 +17,14 @@ TIP: "You can write documentation for your own code using the " { $link "help" }
TIP: "You can write graphical applications using the " { $link "ui" } "." ;
TIP: "Power tools: " { $links see edit help about apropos time infer. } ;
TIP: "Tips of the day implement the " { $link "definition-protocol" } " and new tips of the day can be defined using the " { $link POSTPONE: TIP: } " parsing word." ;
HELP: TIP:
{ $syntax "TIP: content ;" }
{ $values { "content" "a markup element" } }
{ $description "Defines a new tip of the day." } ;
ARTICLE: "all-tips-of-the-day" "All tips of the day"
{ $tips-of-the-day } ;

View File

@ -1,16 +1,30 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: parser arrays namespaces sequences random help.markup kernel io
io.styles colors.constants ;
io.styles colors.constants definitions accessors ;
IN: help.tips
SYMBOL: tips
tips [ V{ } clone ] initialize
SYNTAX: TIP: parse-definition >array tips get push ;
TUPLE: tip < identity-tuple content loc ;
: a-tip ( -- tip ) tips get random ;
M: tip forget* tips get delq ;
M: tip where loc>> ;
M: tip set-where (>>loc) ;
: <tip> ( content -- tip ) f tip boa ;
: add-tip ( tip -- ) tips get push ;
SYNTAX: TIP:
parse-definition >array <tip>
[ save-location ] [ add-tip ] bi ;
: a-tip ( -- tip ) tips get random content>> ;
SYMBOL: tip-of-the-day-style
@ -35,4 +49,4 @@ H{
: tip-of-the-day. ( -- ) { $tip-of-the-day } print-content nl ;
: $tips-of-the-day ( element -- )
drop tips get [ nl nl ] [ print-element ] interleave ;
drop tips get [ nl nl ] [ content>> print-element ] interleave ;