]> gitweb.factorcode.org Git - factor.git/blob - basis/html/templates/chloe/components/components.factor
assocs.extras: Move some often-used words to core
[factor.git] / basis / html / templates / chloe / components / components.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs classes.singleton classes.tuple
4 html.components html.templates.chloe.compiler
5 html.templates.chloe.syntax kernel namespaces parser quotations
6 sequences ;
7 IN: html.templates.chloe.components
8
9 : render-quot ( -- quot )
10     string-context? get
11     [ render-string ]
12     [ render ]
13     ? ;
14
15 GENERIC: component-tag ( tag class -- )
16
17 M: singleton-class component-tag
18     [ "name" required-attr compile-attr ]
19     [ literalize render-quot [code-with] ]
20     bi* ;
21
22 : compile-component-attrs ( tag class -- )
23     [ attrs>> [ main>> "name" = ] reject-keys ] dip
24     [ all-slots swap '[ name>> _ at compile-attr ] each ]
25     [ [ boa ] [code-with] ]
26     bi ;
27
28 M: tuple-class component-tag
29     [ drop "name" required-attr compile-attr ]
30     [ compile-component-attrs ] 2bi
31     render-quot [code] ;
32
33 SYNTAX: COMPONENT:
34     scan-word
35     [ name>> ] [ '[ _ component-tag ] ] bi
36     define-chloe-tag ;