| 
									
										
										
										
											2010-04-12 21:17:21 -04:00
										 |  |  | ! Copyright (C) 2008, 2010 Slava Pestov, Daniel Ehrenberg | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | USING: accessors kernel namespaces io math.parser assocs classes | 
					
						
							| 
									
										
										
										
											2008-06-15 03:38:12 -04:00
										 |  |  | classes.tuple words arrays sequences splitting mirrors | 
					
						
							|  |  |  | hashtables combinators continuations math strings inspector | 
					
						
							| 
									
										
										
										
											2009-01-27 17:54:41 -05:00
										 |  |  | fry locals calendar calendar.format xml.entities xml.data | 
					
						
							| 
									
										
										
										
											2009-02-05 22:17:03 -05:00
										 |  |  | validators urls present xml.writer xml.syntax xml | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  | xmode.code2html lcs.diff2html farkup io.streams.string | 
					
						
							| 
									
										
										
										
											2009-01-30 20:28:16 -05:00
										 |  |  | html html.streams html.forms ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | IN: html.components | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  | GENERIC: render* ( value name renderer -- xml )
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-06 11:54:13 -05:00
										 |  |  | : render>xml ( name renderer -- xml )
 | 
					
						
							| 
									
										
										
										
											2008-06-15 03:38:12 -04:00
										 |  |  |     prepare-value | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         dup validation-error? | 
					
						
							| 
									
										
										
										
											2009-01-31 22:56:39 -05:00
										 |  |  |         [ [ message>> render-error ] [ value>> ] bi ] | 
					
						
							| 
									
										
										
										
											2008-06-15 03:38:12 -04:00
										 |  |  |         [ f swap ] | 
					
						
							|  |  |  |         if
 | 
					
						
							|  |  |  |     ] 2dip
 | 
					
						
							| 
									
										
										
										
											2009-01-31 22:56:39 -05:00
										 |  |  |     render* | 
					
						
							| 
									
										
										
										
											2009-02-06 11:54:13 -05:00
										 |  |  |     swap 2array ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : render ( name renderer -- )
 | 
					
						
							|  |  |  |     render>xml write-xml ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 22:15:58 -04:00
										 |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: write-nested ( obj -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: string write-nested write ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: sequence write-nested [ write-nested ] each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : render-string ( name renderer -- )
 | 
					
						
							|  |  |  |     render>xml write-nested ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | SINGLETON: label | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  | M: label render* | 
					
						
							|  |  |  |     2drop present ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | SINGLETON: hidden | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  | M: hidden render* | 
					
						
							| 
									
										
										
										
											2009-01-31 21:44:17 -05:00
										 |  |  |     drop [XML <input value=<-> name=<-> type="hidden"/> XML] ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  | : render-field ( value name size type -- xml )
 | 
					
						
							|  |  |  |     [XML <input value=<-> name=<-> size=<-> type=<->/> XML] ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | TUPLE: field size ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <field> ( -- field )
 | 
					
						
							|  |  |  |     field new ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  | M: field render* | 
					
						
							|  |  |  |     size>> "text" render-field ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | TUPLE: password size ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <password> ( -- password )
 | 
					
						
							|  |  |  |     password new ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: password render* | 
					
						
							|  |  |  |     #! Don't send passwords back to the user | 
					
						
							|  |  |  |     [ drop "" ] 2dip size>> "password" render-field ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Text areas | 
					
						
							| 
									
										
										
										
											2008-05-23 20:16:21 -04:00
										 |  |  | TUPLE: textarea rows cols ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <textarea> ( -- renderer )
 | 
					
						
							|  |  |  |     textarea new ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 17:54:41 -05:00
										 |  |  | M:: textarea render* ( value name area -- xml )
 | 
					
						
							|  |  |  |     area rows>> :> rows | 
					
						
							|  |  |  |     area cols>> :> cols | 
					
						
							|  |  |  |     [XML | 
					
						
							|  |  |  |          <textarea | 
					
						
							|  |  |  |             name=<-name-> | 
					
						
							|  |  |  |             rows=<-rows-> | 
					
						
							|  |  |  |             cols=<-cols->><-value-></textarea> | 
					
						
							|  |  |  |     XML] ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Choice | 
					
						
							| 
									
										
										
										
											2008-05-23 20:16:21 -04:00
										 |  |  | TUPLE: choice size multiple choices ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <choice> ( -- choice )
 | 
					
						
							|  |  |  |     choice new ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  | : render-option ( text selected? -- xml )
 | 
					
						
							|  |  |  |     "selected" and swap
 | 
					
						
							|  |  |  |     [XML <option selected=<->><-></option> XML] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : render-options ( value choice -- xml )
 | 
					
						
							|  |  |  |     [ choices>> value ] [ multiple>> ] bi
 | 
					
						
							|  |  |  |     [ swap ] [ swap 1array ] if
 | 
					
						
							|  |  |  |     '[ dup _ member? render-option ] map ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M:: choice render* ( value name choice -- xml )
 | 
					
						
							|  |  |  |     choice size>> :> size | 
					
						
							|  |  |  |     choice multiple>> "true" and :> multiple | 
					
						
							|  |  |  |     value choice render-options :> contents
 | 
					
						
							|  |  |  |     [XML <select | 
					
						
							|  |  |  |         name=<-name-> | 
					
						
							|  |  |  |         size=<-size-> | 
					
						
							|  |  |  |         multiple=<-multiple->><-contents-></select> XML] ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Checkboxes | 
					
						
							|  |  |  | TUPLE: checkbox label ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <checkbox> ( -- checkbox )
 | 
					
						
							|  |  |  |     checkbox new ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: checkbox render* | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  |     [ "true" and ] [ ] [ label>> ] tri*
 | 
					
						
							|  |  |  |     [XML <input | 
					
						
							|  |  |  |         type="checkbox" | 
					
						
							|  |  |  |         checked=<-> name=<->><-></input> XML] ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Link components | 
					
						
							|  |  |  | GENERIC: link-title ( obj -- string )
 | 
					
						
							|  |  |  | GENERIC: link-href ( obj -- url )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-05 01:18:36 -04:00
										 |  |  | M: string link-title ;
 | 
					
						
							|  |  |  | M: string link-href ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: url link-title ;
 | 
					
						
							|  |  |  | M: url link-href ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 21:17:21 -04:00
										 |  |  | TUPLE: simple-link title href ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | C: <simple-link> simple-link | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: simple-link link-title title>> ;
 | 
					
						
							|  |  |  | M: simple-link link-href href>> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-29 05:10:00 -04:00
										 |  |  | TUPLE: link target ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: link render* | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  |     nip swap
 | 
					
						
							|  |  |  |     [ target>> ] [ [ link-href ] [ link-title ] bi ] bi*
 | 
					
						
							|  |  |  |     [XML <a target=<-> href=<->><-></a> XML] ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-23 23:32:39 -04:00
										 |  |  | ! XMode code component | 
					
						
							|  |  |  | TUPLE: code mode ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <code> ( -- code )
 | 
					
						
							|  |  |  |     code new ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: code render* | 
					
						
							|  |  |  |     [ string-lines ] [ drop ] [ mode>> value ] tri* htmlize-lines ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Farkup component | 
					
						
							| 
									
										
										
										
											2008-09-22 01:36:07 -04:00
										 |  |  | TUPLE: farkup no-follow disable-images parsed ;
 | 
					
						
							| 
									
										
										
										
											2008-06-14 01:31:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-23 23:01:26 -04:00
										 |  |  | : <farkup> ( -- farkup )
 | 
					
						
							|  |  |  |     farkup new ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-14 01:31:10 -04:00
										 |  |  | : string>boolean ( string -- boolean )
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         { "true" [ t ] } | 
					
						
							|  |  |  |         { "false" [ f ] } | 
					
						
							| 
									
										
										
										
											2008-09-22 03:46:10 -04:00
										 |  |  |         { f [ f ] } | 
					
						
							| 
									
										
										
										
											2008-06-14 01:31:10 -04:00
										 |  |  |     } case ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 23:32:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: farkup render* | 
					
						
							| 
									
										
										
										
											2008-06-14 01:31:10 -04:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2008-09-22 01:36:07 -04:00
										 |  |  |         nip
 | 
					
						
							| 
									
										
										
										
											2008-06-14 01:31:10 -04:00
										 |  |  |         [ no-follow>> [ string>boolean link-no-follow? set ] when* ] | 
					
						
							| 
									
										
										
										
											2008-09-22 01:36:07 -04:00
										 |  |  |         [ disable-images>> [ string>boolean disable-images? set ] when* ] | 
					
						
							| 
									
										
										
										
											2009-01-27 01:03:42 -05:00
										 |  |  |         [ parsed>> string>boolean [ (write-farkup) ] [ farkup>xml ] if ] | 
					
						
							| 
									
										
										
										
											2008-09-22 01:36:07 -04:00
										 |  |  |         tri
 | 
					
						
							| 
									
										
										
										
											2008-06-14 01:31:10 -04:00
										 |  |  |     ] with-scope ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 23:32:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Inspector component | 
					
						
							|  |  |  | SINGLETON: inspector | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: inspector render* | 
					
						
							| 
									
										
										
										
											2009-01-31 21:44:17 -05:00
										 |  |  |     2drop [ describe ] with-html-writer ;
 | 
					
						
							| 
									
										
										
										
											2008-05-23 23:32:39 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-27 01:01:27 -04:00
										 |  |  | ! Diff component | 
					
						
							|  |  |  | SINGLETON: comparison | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: comparison render* | 
					
						
							|  |  |  |     2drop htmlize-diff ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-23 18:33:31 -04:00
										 |  |  | ! HTML component | 
					
						
							|  |  |  | SINGLETON: html | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-29 14:33:04 -05:00
										 |  |  | M: html render* 2drop <unescaped> ;
 | 
					
						
							| 
									
										
										
										
											2009-02-12 02:31:54 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! XML component | 
					
						
							|  |  |  | SINGLETON: xml | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: xml render* 2drop ;
 |