]> gitweb.factorcode.org Git - factor.git/commitdiff
html.streams: the 'image' character stream style now generates an <img> HTML element
authorKeith Lazuka <klazuka@gmail.com>
Tue, 22 Sep 2009 13:06:56 +0000 (09:06 -0400)
committerKeith Lazuka <klazuka@gmail.com>
Tue, 22 Sep 2009 13:06:56 +0000 (09:06 -0400)
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?

basis/html/html.factor
basis/html/streams/streams.factor

index e446c66d8c33445786bded6a659ad2a52a4257eb..12cf3549f4989045278c29fce4defa03174b894f 100644 (file)
@@ -22,3 +22,6 @@ IN: html
 
 : simple-link ( xml url -- xml' )
     url-encode swap [XML <a href=<->><-></a> XML] ;
+
+: simple-image ( url -- xml )
+    url-encode [XML <img src=<-> /> XML] ;
\ No newline at end of file
index 26a3d5f391bca3539c1cfa8d9fe84222bc733930..0ddc09bf5476bd68cc6e2497fee5dfc690f0da27 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2004, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel assocs io io.styles math math.order math.parser
-sequences strings make words combinators macros xml.syntax html fry
-destructors ;
+USING: accessors assocs combinators destructors fry html io
+io.backend io.pathnames io.styles kernel macros make math
+math.order math.parser namespaces sequences strings words xml
+xml.syntax ;
 IN: html.streams
 
 GENERIC: url-of ( object -- url )
@@ -87,9 +88,22 @@ MACRO: make-css ( pairs -- str )
 : emit-html ( quot stream -- )
     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 -- )
-    [ [ 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 ;