]> gitweb.factorcode.org Git - factor.git/blob - basis/help/tips/tips.factor
colors: merge colors.constants and colors.hex.
[factor.git] / basis / help / tips / tips.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays colors definitions help.markup
4 help.stylesheet io io.styles kernel literals namespaces parser
5 random sequences ui.theme ;
6 IN: help.tips
7
8 SYMBOL: tips
9
10 tips [ V{ } clone ] initialize
11
12 TUPLE: tip < identity-tuple content loc ;
13
14 M: tip forget* tips get remove-eq! drop ;
15
16 M: tip where loc>> ;
17
18 M: tip set-where loc<< ;
19
20 : <tip> ( content -- tip ) f tip boa ;
21
22 : add-tip ( tip -- ) tips get push ;
23
24 SYNTAX: TIP:
25     parse-array-def <tip>
26     [ save-location ] [ add-tip ] bi ;
27
28 : a-tip ( -- tip ) tips get random ;
29
30 SYMBOL: tip-of-the-day-style
31 H{
32     { page-color $ tip-background-color }
33     { inset { 5 5 } }
34     { wrap-margin $ wrap-margin-full }
35 } tip-of-the-day-style set-global
36
37 : $tip-title ( tip -- )
38     [
39         heading-style get [
40             [ "Tip of the day" ] dip write-object
41         ] with-style
42     ] ($block) ;
43
44 : $tip-of-the-day ( element -- )
45     drop
46     [
47         tip-of-the-day-style get
48         [
49             last-element off
50             a-tip [ $tip-title ] [ content>> print-element nl ] bi
51             "— " print-element "all-tips-of-the-day" ($link)
52         ]
53         with-nesting
54     ] ($heading) ;
55
56 : tip-of-the-day. ( -- ) { $tip-of-the-day } print-content nl ;
57
58 : $tips-of-the-day ( element -- )
59     drop tips get [ nl nl ] [ content>> print-element ] interleave ;
60
61 INSTANCE: tip definition-mixin