unwwwritten
TODO or not todo, that is the question
Posted November 3rd, 2008 at 2:23 pm EST by S. Brent Faulkner — View Comments
Well, I guess it's time to re-address the todo list for this site.
support for multiple markup methods
Bluecloth and Redcloth take care of markdown and textile for me. There's more to do for this, but my most recent implementation is in my has_markup plugin. This uses a gem I created to do code colouring within markup. I'll be replacing that with an alternative in the near future.
sidebar
As you can see at the right, there is a sidebar (and has been for some time). The implementation is relatively simple. The main layout includes the following...
1 <div id="sidebar"> 2 <%= yield :sidebar %> 3 </div>
Additionally, I added the following application helper...
1 def sidebar(title, container, options = {}) 2 id = options.delete(:id) || title.titleize.gsub(/ /,'').underscore 3 content_tag 'div', :id => id, :class => 'sidebar_item' do 4 content = "" 5 content << content_tag('h4', title) unless title.blank? 6 if container.blank? 7 content << yield 8 else 9 content << content_tag(container) { yield } 10 end 11 end 12 end
Then, I added specific helpers for the various sidebars needed in my application. For example, a helper to include links to projects is...
1 def projects_sidebar(title, projects) 2 sidebar(title, 'ul') do 3 projects.collect do |project| 4 content_tag('li') { link_to(project.name, project) } 5 end.join("\n") 6 end 7 end
Now, from any given layout I can render the project sidebar item as follows...
1 <% content_for :sidebar do -%> 2 <%= projects_sidebar('other projects', @projects) 3 <% end -%>
tagging of posts
This is pretty standard stuff... I added two models - Tag (for the tags) and Tagging (a join table to associate posts with tags).
tag cloud showing tag frequency with links to posts
More code, less filling...
1 TAG_FREQUENCY_CLASSES = %w(low medium-low medium medium-high high) 2 3 def tag_cloud_sidebar(post = nil) 4 tag_ids = [] 5 tag_ids = post.tag_ids unless post.nil? 6 7 tags = Tag.find(:all, 8 :select => 'tags.id, tags.name, tags.permalink, count(tag_id) as count', 9 :from => 'taggings', 10 :joins => 'INNER JOIN tags ON tags.id = taggings.tag_id', 11 :group => 'tags.id, tags.permalink, tags.name', 12 :order => 'tags.name') 13 14 min = max = 0 15 tags.each do |t| 16 count = t.count = t.count.to_i 17 min = count if count < min || min == 0 18 max = count if count > max 19 end 20 21 division = (max - min + 1) / 5.0 22 23 sidebar('tags', 'p') do 24 tags.collect do |tag| 25 link_class = TAG_FREQUENCY_CLASSES[((tag.count-min)/division).to_i] 26 link_class += ' tagged' if tag_ids.include?(tag.id) 27 link = link_to(tag.name, tag_posts_url(tag), :class => link_class) 28 end.join(' ') 29 end 30 end
related posts
This is all in the query...
1 SELECT DISTINCT posts.* FROM posts LEFT OUTER JOIN taggings ON taggings.post_id = posts.id WHERE post_id != ? AND tag_id IN (?) ORDER BY posts.created_at DESC LIMIT ?
github integration for projects
this may deserve a post of its own
atom/rss feeds
thanks, rails!
instead of using captcha or comment moderation, use email verification (or a verified user account) to publish comments
using disqus instead - dead simple
blog comments powered by Disqus