html.streams: the 'image' character stream style now generates an <img> HTML element
NOTE: You must manually copy your image resources to your web server
      such that the images are available from the "/images" root URL.
	  For example, if your resource is "vocab:definitions/icons/normal-word.tiff"
	  then it should be copied such that it is available via the following URL:
	  "http://myserver.org/images/basis/definitions/icon/normal-word.tiff"
	  (the original path is first normalized and then the Factor root prefix
	   is stripped away).
NOTE: Factor's definition-icons are in TIFF format, which appears to be
	  supported out-of-the-box by very few web browsers (namely Safari).
	  Perhaps we should switch from TIFF to GIF or PNG? Are these vocabs
	  ready to be used?
			
			
				db4
			
			
		
							parent
							
								
									c4ed7f38b7
								
							
						
					
					
						commit
						d552ce8ef6
					
				| 
						 | 
					@ -22,3 +22,6 @@ IN: html
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: simple-link ( xml url -- xml' )
 | 
					: simple-link ( xml url -- xml' )
 | 
				
			||||||
    url-encode swap [XML <a href=<->><-></a> XML] ;
 | 
					    url-encode swap [XML <a href=<->><-></a> XML] ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: simple-image ( url -- xml )
 | 
				
			||||||
 | 
					    url-encode [XML <img src=<-> /> XML] ;
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,9 @@
 | 
				
			||||||
! Copyright (C) 2004, 2009 Slava Pestov.
 | 
					! Copyright (C) 2004, 2009 Slava Pestov.
 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					! See http://factorcode.org/license.txt for BSD license.
 | 
				
			||||||
USING: accessors kernel assocs io io.styles math math.order math.parser
 | 
					USING: accessors assocs combinators destructors fry html io
 | 
				
			||||||
sequences strings make words combinators macros xml.syntax html fry
 | 
					io.backend io.pathnames io.styles kernel macros make math
 | 
				
			||||||
destructors ;
 | 
					math.order math.parser namespaces sequences strings words xml
 | 
				
			||||||
 | 
					xml.syntax ;
 | 
				
			||||||
IN: html.streams
 | 
					IN: html.streams
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GENERIC: url-of ( object -- url )
 | 
					GENERIC: url-of ( object -- url )
 | 
				
			||||||
| 
						 | 
					@ -87,9 +88,22 @@ MACRO: make-css ( pairs -- str )
 | 
				
			||||||
: emit-html ( quot stream -- )
 | 
					: emit-html ( quot stream -- )
 | 
				
			||||||
    dip data>> push ; inline
 | 
					    dip data>> push ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: image-resource-path ( path -- images-path )
 | 
				
			||||||
 | 
					    normalize-path current-directory get drop-prefix drop
 | 
				
			||||||
 | 
					    "/images" prepend ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: img-tag ( xml style -- xml )
 | 
				
			||||||
 | 
					    image swap at [ nip image-resource-path simple-image ] when* ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: format-html-span ( string style stream -- )
 | 
					: format-html-span ( string style stream -- )
 | 
				
			||||||
    [ [ span-tag ] [ href-link-tag ] [ object-link-tag ] tri ]
 | 
					    [
 | 
				
			||||||
    emit-html ;
 | 
					        {
 | 
				
			||||||
 | 
					            [ span-tag ]
 | 
				
			||||||
 | 
					            [ href-link-tag ]
 | 
				
			||||||
 | 
					            [ object-link-tag ]
 | 
				
			||||||
 | 
					            [ img-tag ]
 | 
				
			||||||
 | 
					        } cleave
 | 
				
			||||||
 | 
					    ] emit-html ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TUPLE: html-span-stream < html-sub-stream ;
 | 
					TUPLE: html-span-stream < html-sub-stream ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue