2008-05-02 22:18:49 -04:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-09-08 02:11:09 -04:00
|
|
|
USING: accessors kernel sequences combinators kernel fry
|
2008-09-19 19:46:54 -04:00
|
|
|
namespaces make classes.tuple assocs splitting words arrays io
|
2008-12-15 02:13:35 -05:00
|
|
|
io.files io.files.info io.encodings.utf8 io.streams.string
|
|
|
|
unicode.case mirrors math urls present multiline quotations xml
|
2009-02-08 23:12:11 -05:00
|
|
|
logging call
|
2009-02-05 22:17:03 -05:00
|
|
|
xml.data xml.writer xml.syntax strings
|
2008-06-15 03:38:12 -04:00
|
|
|
html.forms
|
2009-01-30 20:28:16 -05:00
|
|
|
html
|
2008-05-23 20:16:21 -04:00
|
|
|
html.components
|
2008-05-24 02:28:48 -04:00
|
|
|
html.templates
|
2008-09-08 02:11:09 -04:00
|
|
|
html.templates.chloe.compiler
|
|
|
|
html.templates.chloe.components
|
2008-06-01 18:22:39 -04:00
|
|
|
html.templates.chloe.syntax ;
|
2008-05-24 02:28:48 -04:00
|
|
|
IN: html.templates.chloe
|
2008-04-15 07:10:08 -04:00
|
|
|
|
|
|
|
TUPLE: chloe path ;
|
|
|
|
|
|
|
|
C: <chloe> chloe
|
|
|
|
|
2008-09-08 02:11:09 -04:00
|
|
|
CHLOE: chloe compile-children ;
|
2008-06-01 18:22:39 -04:00
|
|
|
|
2008-09-08 02:11:09 -04:00
|
|
|
CHLOE: title compile-children>string [ set-title ] [code] ;
|
2008-05-02 22:18:49 -04:00
|
|
|
|
2008-06-01 18:22:39 -04:00
|
|
|
CHLOE: write-title
|
2008-04-15 07:10:08 -04:00
|
|
|
drop
|
2008-06-02 16:00:03 -04:00
|
|
|
"head" tag-stack get member?
|
|
|
|
"title" tag-stack get member? not and
|
2009-02-05 15:34:55 -05:00
|
|
|
[ get-title [XML <title><-></title> XML] ]
|
|
|
|
[ get-title ] ?
|
|
|
|
[xml-code] ;
|
2008-04-15 07:10:08 -04:00
|
|
|
|
2008-06-01 18:22:39 -04:00
|
|
|
CHLOE: style
|
2008-09-08 02:11:09 -04:00
|
|
|
dup "include" optional-attr [
|
|
|
|
utf8 file-contents [ add-style ] [code-with]
|
2008-04-15 07:10:08 -04:00
|
|
|
] [
|
2008-09-08 02:11:09 -04:00
|
|
|
compile-children>string [ add-style ] [code]
|
|
|
|
] ?if ;
|
2008-04-15 07:10:08 -04:00
|
|
|
|
2008-06-01 18:22:39 -04:00
|
|
|
CHLOE: write-style
|
2008-09-23 17:32:10 -04:00
|
|
|
drop [
|
2009-02-05 15:34:55 -05:00
|
|
|
get-style
|
|
|
|
[XML <style type="text/css"> <-> </style> XML]
|
|
|
|
] [xml-code] ;
|
2008-04-15 07:10:08 -04:00
|
|
|
|
2008-09-08 02:11:09 -04:00
|
|
|
CHLOE: even
|
|
|
|
[ "index" value even? swap when ] process-children ;
|
2008-04-15 07:10:08 -04:00
|
|
|
|
2008-09-08 02:11:09 -04:00
|
|
|
CHLOE: odd
|
|
|
|
[ "index" value odd? swap when ] process-children ;
|
2008-05-26 01:47:27 -04:00
|
|
|
|
2008-05-26 03:54:53 -04:00
|
|
|
: (bind-tag) ( tag quot -- )
|
|
|
|
[
|
2008-09-08 02:11:09 -04:00
|
|
|
[ "name" required-attr compile-attr ] keep
|
|
|
|
] dip process-children ; inline
|
2008-05-26 03:54:53 -04:00
|
|
|
|
2008-06-01 18:22:39 -04:00
|
|
|
CHLOE: each [ with-each-value ] (bind-tag) ;
|
2008-05-26 03:54:53 -04:00
|
|
|
|
2008-06-01 18:22:39 -04:00
|
|
|
CHLOE: bind-each [ with-each-object ] (bind-tag) ;
|
|
|
|
|
2008-06-15 03:38:12 -04:00
|
|
|
CHLOE: bind [ with-form ] (bind-tag) ;
|
2008-05-26 03:54:53 -04:00
|
|
|
|
2008-06-01 18:22:39 -04:00
|
|
|
CHLOE: comment drop ;
|
2008-05-23 20:16:21 -04:00
|
|
|
|
2008-09-08 02:11:09 -04:00
|
|
|
CHLOE: call-next-template
|
|
|
|
drop reset-buffer \ call-next-template , ;
|
2008-05-23 20:16:21 -04:00
|
|
|
|
2008-11-13 22:49:37 -05:00
|
|
|
CHLOE: validation-errors
|
|
|
|
drop [ render-validation-errors ] [code] ;
|
|
|
|
|
2008-06-04 20:54:05 -04:00
|
|
|
: attr>word ( value -- word/f )
|
2008-06-18 04:26:50 -04:00
|
|
|
":" split1 swap lookup ;
|
2008-06-04 20:54:05 -04:00
|
|
|
|
2008-09-08 02:11:09 -04:00
|
|
|
: if>quot ( tag -- quot )
|
|
|
|
[
|
|
|
|
[ "code" optional-attr [ attr>word [ , ] [ f , ] if* ] [ t , ] if* ]
|
|
|
|
[ "value" optional-attr [ , \ value , ] [ t , ] if* ]
|
|
|
|
bi
|
|
|
|
\ and ,
|
|
|
|
] [ ] make ;
|
2008-06-04 20:54:05 -04:00
|
|
|
|
2008-09-08 02:11:09 -04:00
|
|
|
CHLOE: if dup if>quot [ swap when ] append process-children ;
|
2008-06-04 20:54:05 -04:00
|
|
|
|
2008-09-29 05:10:00 -04:00
|
|
|
COMPONENT: label
|
|
|
|
COMPONENT: link
|
|
|
|
COMPONENT: inspector
|
|
|
|
COMPONENT: comparison
|
|
|
|
COMPONENT: html
|
|
|
|
COMPONENT: hidden
|
|
|
|
COMPONENT: farkup
|
|
|
|
COMPONENT: field
|
|
|
|
COMPONENT: textarea
|
|
|
|
COMPONENT: password
|
|
|
|
COMPONENT: choice
|
|
|
|
COMPONENT: checkbox
|
|
|
|
COMPONENT: code
|
2008-05-23 20:16:21 -04:00
|
|
|
|
2008-09-19 19:46:54 -04:00
|
|
|
SYMBOL: template-cache
|
2008-09-08 03:52:42 -04:00
|
|
|
|
2008-09-19 19:46:54 -04:00
|
|
|
H{ } template-cache set-global
|
2008-09-08 03:52:42 -04:00
|
|
|
|
2008-09-19 19:46:54 -04:00
|
|
|
TUPLE: cached-template path last-modified quot ;
|
2008-09-08 02:11:09 -04:00
|
|
|
|
2008-09-19 19:46:54 -04:00
|
|
|
: load-template ( chloe -- cached-template )
|
|
|
|
path>> ".xml" append
|
|
|
|
[ ]
|
|
|
|
[ file-info modified>> ]
|
|
|
|
[ utf8 <file-reader> read-xml compile-template ] tri
|
|
|
|
\ cached-template boa ;
|
|
|
|
|
|
|
|
\ load-template DEBUG add-input-logging
|
|
|
|
|
|
|
|
: cached-template ( chloe -- cached-template/f )
|
|
|
|
template-cache get at* [
|
|
|
|
[
|
|
|
|
[ path>> file-info modified>> ]
|
|
|
|
[ last-modified>> ]
|
|
|
|
bi =
|
|
|
|
] keep and
|
|
|
|
] when ;
|
|
|
|
|
|
|
|
: template-quot ( chloe -- quot )
|
|
|
|
dup cached-template [ ] [
|
|
|
|
[ load-template dup ] keep
|
|
|
|
template-cache get set-at
|
|
|
|
] ?if quot>> ;
|
|
|
|
|
|
|
|
: reset-cache ( -- )
|
|
|
|
template-cache get clear-assoc ;
|
2008-04-15 07:10:08 -04:00
|
|
|
|
2008-04-22 22:08:27 -04:00
|
|
|
M: chloe call-template*
|
2009-02-08 23:12:11 -05:00
|
|
|
template-quot call( -- ) ;
|
2008-04-16 00:36:27 -04:00
|
|
|
|
|
|
|
INSTANCE: chloe template
|