1 ! Copyright (C) 2008, 2010 Slava Pestov, Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel namespaces io math.parser assocs classes
4 classes.tuple words arrays sequences splitting mirrors
5 hashtables combinators continuations math strings inspector
6 fry locals calendar calendar.format xml.entities xml.data
7 validators urls present xml.writer xml.syntax xml
8 xmode.code2html lcs.diff2html farkup io.streams.string
9 html html.streams html.forms ;
12 GENERIC: render* ( value name renderer -- xml )
14 : render>xml ( name renderer -- xml )
17 dup validation-error-state?
18 [ [ message>> render-error ] [ value>> ] bi ]
25 : render ( name renderer -- )
26 render>xml write-xml ;
30 GENERIC: write-nested ( obj -- )
32 M: string write-nested write ;
34 M: sequence write-nested [ write-nested ] each ;
38 : render-string ( name renderer -- )
39 render>xml write-nested ;
49 drop [XML <input value=<-> name=<-> type="hidden"/> XML] ;
51 : render-field ( value name size type -- xml )
52 [XML <input value=<-> name=<-> size=<-> type=<->/> XML] ;
56 : <field> ( -- field )
60 size>> "text" render-field ;
62 TUPLE: password size ;
64 : <password> ( -- password )
68 ! Don't send passwords back to the user
69 [ drop "" ] 2dip size>> "password" render-field ;
72 TUPLE: textarea rows cols ;
74 : <textarea> ( -- renderer )
77 M:: textarea render* ( value name area -- xml )
84 cols=<-cols->><-value-></textarea>
88 TUPLE: choice size multiple choices ;
90 : <choice> ( -- choice )
93 : render-option ( text selected? -- xml )
95 [XML <option selected=<->><-></option> XML] ;
97 : render-options ( value choice -- xml )
98 [ choices>> value ] [ multiple>> ] bi
99 [ swap ] [ swap 1array ] if
100 '[ dup _ member? render-option ] map ;
102 M:: choice render* ( value name choice -- xml )
103 choice size>> :> size
104 choice multiple>> "true" and :> multiple
105 value choice render-options :> contents
109 multiple=<-multiple->><-contents-></select> XML] ;
112 TUPLE: checkbox label ;
114 : <checkbox> ( -- checkbox )
118 [ "true" and ] [ ] [ label>> ] tri*
121 checked=<-> name=<->><-></input> XML] ;
124 GENERIC: link-title ( obj -- string )
125 GENERIC: link-href ( obj -- url )
127 M: string link-title ;
128 M: string link-href ;
133 TUPLE: simple-link title href ;
135 C: <simple-link> simple-link
137 M: simple-link link-title title>> ;
138 M: simple-link link-href href>> ;
144 [ target>> ] [ [ link-href ] [ link-title ] bi ] bi*
145 [XML <a target=<-> href=<->><-></a> XML] ;
147 ! XMode code component
154 [ string-lines ] [ drop ] [ mode>> value ] tri* htmlize-lines ;
157 TUPLE: farkup no-follow disable-images parsed ;
159 : <farkup> ( -- farkup )
162 : string>boolean ( string -- boolean )
172 [ no-follow>> [ string>boolean link-no-follow? set ] when* ]
173 [ disable-images>> [ string>boolean disable-images? set ] when* ]
174 [ parsed>> string>boolean [ (write-farkup) ] [ farkup>xml ] if ]
178 ! Inspector component
182 2drop [ describe ] with-html-writer ;
185 SINGLETON: comparison
187 M: comparison render*
193 M: html render* 2drop dup string? [ <unescaped> ] when ;
198 M: xml render* 2drop ;