[Borges-users] HtmlBuilder#image_url_anchor and HtmlRenderer#image_anchor

Kaspar Schiess eule at space.ch
Fri Apr 23 15:03:42 EDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all,

I propose the addition of

HtmlBuilder#image_url_anchor
~ Output a link enclosing an image tag.

HtmlRenderer#image_anchor
~ Output a link enclosing an image tag, executing block when clicked.

see also enclosed patch. I have unit tests for these two methods ready
and can check in if this finds your approval.

Eric: Yes, I guess this is the correct way of having changes to Borges
reviewed. I will take this road in the future, even if a bit more
cumbersome. Thanks for hinting at it.

kaspar - code philosopher

- -- stolen off the net --
And that, of course, is how it really is; trying to get rid of something
by sleeping is just as useless as trying to obtain something by sleeping.
		-- Soren Kierkegaard, "Philosophical Fragments"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAiWiOFifl4CA0ImQRAsYIAJ9fZjgyAQ0O2g6OBeh+Q/CK4P2I7QCgph3F
Tv/3tgUeKU766sQ9xBikjqc=
=Vvfy
-----END PGP SIGNATURE-----
-------------- next part --------------
diff -u old/HtmlBuilder.rb new/HtmlBuilder.rb
--- old/HtmlBuilder.rb	Thu Apr 22 14:04:34 2004
+++ new/HtmlBuilder.rb	Fri Apr 23 20:49:53 2004
@@ -166,6 +166,19 @@
     @attributes[:alt] = alt
     tag :img
   end
+  
+  ## 
+  # Add an anchor on an <img> with +src+ as its src attribute. If +alt+ is
+  # specified, it is used as the image's alternate text,
+  # otherwise the alt attribute is left empty. 
+  
+  def image_url_anchor(url, src, alt='')
+    url_anchor(url) do 
+      # no thin blue line on iexplorer
+      @attributes[:border] = 0
+      image(src, alt)
+    end
+  end
 
   ##
   # Creates a new HtmlBuilder.
diff -u old/HtmlRenderer.rb new/HtmlRenderer.rb
--- old/HtmlRenderer.rb	Thu Apr 22 14:04:34 2004
+++ new/HtmlRenderer.rb	Fri Apr 23 20:53:30 2004
@@ -105,6 +105,17 @@
     block.call
     close
   end
+  
+  ##
+  # Creates a link with image from img_url as content. The link 
+  # executes +block+ when executed. Image has alt text of +alt+. 
+  
+  def image_anchor(img_url, alt='', &block)
+    open_anchor(&block)
+    attributes[:border] = 0
+    image(img_url, alt)
+    close
+  end
 
   def initialize(rendering_context)
     @rendering_context = rendering_context


More information about the Borges-users mailing list