08/10/2009
I just made a little tweak to the gallery_tags.rb from the Gallery Extension.
It makes it easy to show a gallery somewhere on any page, if that page
has a base gallery set. You can also hide a potential surrounding div if
it is not needed (not containing a gallery). For example:
<r:gallery fail_silently="true"><div id="gallery">
<r:gallery:lightbox />
</div></r:gallery>
Without the hack, (and the fail_silently attribute) you would get a nasty "undefined method `items' for
nil:NilClass" if there was no base gallery set on that page.
Of course, it would also work if you are specifying a gallery by name
or id, instead of relying on a base gallery being set.
And all it took was;
tag "gallery" do |tag| tag.locals.gallery = find_gallery(tag)
- tag.expand
+ tag.expand unless tag.locals.gallery.nil? && tag.attr['fail_silently']
end
11/09/2009
When you syndicate Radiant content, you may hit the problem of internal
links, or img src attributes pointing to invalid paths on a syndicator's
domain. So, for example, an aggregator may link to http://aggregator.com/about-us
instead of http://your-site.com/about-us. The simple fix is ofcourse to
use absolute URLs for all your href and src attributes, but that is not
default behavior in Radiant (or most CMSes as far as i know).
If you are using paperclipped, and use <r:asset /> tags to display
images, you could fix their src attributes in script console or via the
Settings extension by doing:
Radiant::Config["assets.url"] = "http://your-site.com/:class/:id/:basename:no_original_style.:extension"
But that still leaves you with the fact that <r:url />, <r:link
/> and some other radius tags output relative urls. Heck, you may even
have a few clients that are smart enough to write urls by hand! Here's
a method that will convert all relative URLs to absolute ones;
def fix_for_syndication(text, host) text.gsub(/href=('|")([^(http:|mailto:)].*?)('|")/,
'href="' + host + '\2"').gsub(/src=('|")([^http:].*?)('|")/, 'src="' +
host + '\2"') end
From there you can make a simple radius tag to use where-ever you output
stuff to an RSS feed;
tag 'fix_links_for_syndication' do |tag| fix_for_syndication(tag.expand,
"#{tag.globals.page.request.protocol}#{tag.globals.page.request.host_with_port}")
end
I used this in
one of our own extensions (works-for-us'ish), use at your own risk;
probably not compatible with the standard 'blog' extension for example.