From d552ce8ef60a1fef9fdaf9725ef17bfe1a29c392 Mon Sep 17 00:00:00 2001 From: Keith Lazuka Date: Tue, 22 Sep 2009 09:06:56 -0400 Subject: [PATCH] html.streams: the 'image' character stream style now generates an 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? --- basis/html/html.factor | 3 +++ basis/html/streams/streams.factor | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/basis/html/html.factor b/basis/html/html.factor index e446c66d8c..12cf3549f4 100644 --- a/basis/html/html.factor +++ b/basis/html/html.factor @@ -22,3 +22,6 @@ IN: html : simple-link ( xml url -- xml' ) url-encode swap [XML ><-> XML] ; + +: simple-image ( url -- xml ) + url-encode [XML /> XML] ; \ No newline at end of file diff --git a/basis/html/streams/streams.factor b/basis/html/streams/streams.factor index 26a3d5f391..0ddc09bf54 100644 --- a/basis/html/streams/streams.factor +++ b/basis/html/streams/streams.factor @@ -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 ;