RE: image plugin

"Blake Winton" <blake-dlUKtbW3TlBcVw/[email protected]>
Newsgroups gmane.comp.web.pyblosxom.user
Message-ID <[email protected]>
> > py['image_template'] = '<a href="$dir/$file"><img src="$dir/$file"></a>'
> 
> May want to consider including height and width attributes 
> for img tag.  I'm fairly certain there's a Python module that
> will tell you such info. Although, is it worth the processing
> requirements just to include the height and width attributes
> for syntactic strictness?

And that sort of brings me to my next thought.  When I was writing
out my example I didn't really like the structured-ness of it.  It
seemed a little draconian to force all the images to have a small
version, but I couldn't figure out a good way to switch based on
the presence or absence of a key.  So, that, combined with the
width/height addition leads me to propose the following:

--image.glossary--
name::dir::thumb::file
image_one::photos2/events/2003/s4::small.jpg::no_headlights.jpg
image_two::photos2/events/2003/s4::::no_headlights.jpg
--/image.glossary--

--config--
def image_template_replacement_func( entry_data ):
    if ( entry_data['thumb'].strip() == "" ) :
        template = '<a href="%{dir}s/%{file}s">%{name}</a>'
    else :
        template = '<a href="%{dir}s/%{file}s"><img src="%{dir}s/%{thumb}s"'
+
                   ' width="%{width}s" height="%{height}s"></a>'
        entry_data['width']  = getImageWidth( '%{dir}s/%{thumb}s' )
        entry_data['height'] = getImageHeight( '%{dir}s/%{thumb}s' )
    return template % entry_data

py['image_template'] = image_template_replacement_func
py['acronym_template'] = '<a href="%{url}s"><abbr
desc="%{exp}s">${abbr}s</abbr></a>'
--/config--

--blog--
This is my blog with an $image(image_one) and another $image(image_two).
--/blog--

So, if the thing in the py dict is callable, call it and substitute in
the result, otherwise assume it's a string and substitute in the dict-
replaced % form...

Clear as mud?  Too powerful/slow/complex?

Later,
Blake.



-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.