You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that if I scope a tag cloud to a mime type, the tag cloud is styled based on the occurrence of tags across all assets, not just the assets of the scoped mime type.
For example, I'm working on a site that features photos that are tagged by artists, and magazines that are tagged by artists and topics. I want the magazine tag cloud to reflect the occurrence of artists' tags across magazines, rather than across magazines and photos.
This is the band-aid solution I've come up with, you could certainly make this slicker:
# in taggable_tags.rb
# I've added support for a 'for' attribute for specifying mime type
# ex. r:pdf_tags:cloud for="pdf" /
tag 'tags:cloud' do |tag|
if tag.locals.tags && tag.locals.tags.length > 1
options = tag.attr.dup
media_type = options.delete('for')
tag.locals.tags = Tag.for_cloud(tag.locals.tags, media_type).sort_by{|t| t.title.downcase}
# in tag.rb
named_scope :only_assets_of_type, lambda { |tags|
{
:conditions => ["tt.tagged_id IN (#{tags.map{'?'}.join(',')})", *tags.map{|t| t.is_a?(Tag) ? t.id : t}]
}
}
def self.for_cloud(tags, type=nil)
return tags if tags.empty? || tags.first.cloud_size
if type
sized(in_this_list(tags).with_count.only_assets_of_type(Asset.not_furniture.send(type.pluralize.intern)))
else
sized(in_this_list(tags).with_count)
end
end
I'm not sure if this kind of functionality is something you think belongs in the extension, or maybe this is an edge case.
Activity