Archive

Posts Tagged ‘liquid’

Mephisto Tag Cloud Plugin

February 25th, 2007

Because the French one disappeared off the face of the earth, I took it upon myself to make a tag cloud Liquid plugin. Here’s the scoop. I downloaded Rick’s MeasureMap Plugin and went to town converting it.

Add this to your sidebar in your liquid template of choice:


{% for tag in site.tags %}
  {{ tag | size_tag }}
{% endfor %}

And you should have some awesome tag_cloud action. You can specify an upper limit as well:


{{ tag | size_tag: 3 }}

That code allows for up to 4em font size. I don’t recommend this because it’s ludicrous. The default upper limit is 2em, which makes the font size range between 1em and 2em. Suggestions are welcome.

Get it here:


svn co https://modzer0.cs.uaf.edu/repos/hank/code/rails/mephisto/mephisto_tag_cloud

Or install it like this:


./script/plugin install https://modzer0.cs.uaf.edu/repos/hank/code/rails/mephisto/mephisto_tag_cloud

Works for me – let me know if you have any difficulties.

Update: French one re-appears!

Well, he’s back. It was down a while back. You can see his version here. I like mine better. :P

Update: Better SELECT Statement

Thanks to Todd for pointing out that the tags were applying to not only published articles, but drafts as well, which produced false tag counts. He also pointed out that they were applying to revisions, which was unacceptable. I think I fixed the problems using some straight up SQL:


    def size_tag(tag, largest = 2, smallest = 0.5)
      number = ActiveRecord::Base.count_by_sql(
        ["SELECT COUNT(*) FROM taggings,
            tags, contents WHERE
            tags.name = ? AND taggings.tag_id = tags.id
            AND contents.id = taggings.taggable_id
            AND contents.published_at IS NOT NULL;", tag])
      size = sprintf("%0.2f", number.to_f / 5)
      size = size.to_f > largest ? largest : size.to_f < smallest ? smallest : size

This is simple – I’m just adding some conditions that filter unpublished articles and revisions (which I don’t think actually appear in the contents table anyway). In a test, the linux tag returned 35 results the old way, 34 without the checking of published_id, and 33 as it is above. I think it’s filtering, but Todd will have to confirm this.


Uncategorized , , , ,