factor-work/triangle-beer-league/triangle-beer-league.factor

87 lines
2.3 KiB
Factor
Raw Permalink Normal View History

2024-01-27 13:27:34 -05:00
USING: accessors namespaces kernel sequences arrays urls present farkup combinators classes ;
2023-09-08 16:24:48 -04:00
USING: math.parser math.text.english ;
2023-09-06 12:40:23 -04:00
USING: io.sockets.secure io.servers ;
2023-09-08 16:24:48 -04:00
USING: furnace.actions furnace.boilerplate furnace.utilities furnace.chloe-tags ;
USING: calendar calendar.english ;
USING: html.forms ;
2023-09-06 12:40:23 -04:00
USING: http.server http.server.dispatchers http.server.static ;
2023-09-08 16:24:48 -04:00
USING: triangle-beer-league.daysmart ;
2023-09-06 12:40:23 -04:00
IN: triangle-beer-league
SYMBOLS: key-password key-file dh-file ;
2024-01-27 13:27:34 -05:00
! DTOs
TUPLE: game start-time home away summary show-summary? show-times? ;
TUPLE: schedule header games ;
2023-09-08 16:24:48 -04:00
2023-09-06 12:40:23 -04:00
TUPLE: tbl < dispatcher ;
2024-01-27 13:27:34 -05:00
: team-schedule>time-string ( schedule -- str )
[ start>> ] [ end>> ] bi
[ timestamp>relative-hh:mm "pm" append ] bi@
2array " - " join ;
2023-09-06 12:40:23 -04:00
2023-09-08 16:24:48 -04:00
: timestamp>day-header ( timestamp -- str )
[ day-of-week day-name ]
[ month>> month-name ]
[ day>> dup number>string swap ordinal-suffix append ] tri
3array " " join ;
2024-01-27 13:27:34 -05:00
: summary>string ( summary -- str )
[
[ away-score>> ] [ home-score>> ] bi 2array " - " join
]
[ "" ] if* ;
: tbl-game-schedules>tbl-games ( game-schedules -- games )
[
{
[ team-schedule>time-string ]
[ home>> color>> ]
[ away>> color>> ]
[ summary>> summary>string ]
} cleave dup empty? not dup not game boa
] map ;
2023-09-08 16:24:48 -04:00
: tbl-games>schedule ( game-schedules -- schedules )
2024-01-27 13:27:34 -05:00
[
[ first timestamp>day-header ]
[ second tbl-game-schedules>tbl-games ] bi schedule boa
] map ;
: <splash-action> ( -- action )
<page-action>
{ tbl "tbl" } >>template ;
2023-09-08 16:24:48 -04:00
2023-09-06 12:40:23 -04:00
: <schedule-action> ( -- action )
<page-action>
2023-09-10 17:05:18 -04:00
[
t "show-header?" set-value
2024-01-27 13:27:34 -05:00
tbl-game-schedules tbl-games>schedule "schedule" set-value
2023-09-10 17:05:18 -04:00
] >>init
2023-09-06 12:40:23 -04:00
{ tbl "schedule" } >>template ;
2023-09-06 16:35:05 -04:00
: <tbl> ( -- responder )
2023-09-06 12:40:23 -04:00
tbl new-dispatcher
2023-09-08 16:24:48 -04:00
"resource:work/triangle-beer-league" <static> >>default
2023-09-08 16:54:42 -04:00
<splash-action> "" add-responder
2023-09-08 16:24:48 -04:00
<schedule-action> "schedule" add-responder
<boilerplate>
{ tbl "tbl-common" } >>template ;
2023-09-06 12:40:23 -04:00
: <tbl-website-server> ( -- threaded-server )
<http-server>
2023-09-06 16:35:05 -04:00
f >>secure
8080 >>insecure ;
2023-09-06 12:40:23 -04:00
: start-tbl-site ( -- server )
2023-09-06 16:35:05 -04:00
<tbl> main-responder set-global
2023-09-06 12:40:23 -04:00
<tbl-website-server> start-server ;
2023-09-06 16:21:20 -04:00
: start-tbl ( -- )
start-tbl-site wait-for-server ;
MAIN: start-tbl