Atom template Rails builder template
Ruby posted 10 months ago by christian
1 atom_feed(:url => formatted_posts_url(:atom)) do |feed| 2 feed.title(@category.name) 3 feed.updated(@posts.first ? @posts.first.created_at : Time.now.utc) 4 5 for post in @posts 6 feed.entry(post) do |entry| 7 entry.title(post.title) 8 entry.content(post.body_html, :type => 'html') 9 entry.updated post.updated_at 10 11 for tag in post.tags 12 entry.category :term => url_for(tag), :label => tag.name 13 end 14 end 15 end 16 end
How to implement collapsible content (folders, categories, jimmy the cat) with jQuery
JavaScript posted about 1 year ago by christian
This here is a quick-and-dirty implementation of folders for jQuery:
Markup
Any markup following the naming conventions should work, for example:
1 <ul class="collapsible"> 2 <li> 3 <a href="" class="toggle-button">This be the folder</a> 4 <ul style="display:none" class="collapsible-content"> 5 <li>This be the folder content</li> 6 <li>This be the folder content</li> 7 </ul> 8 </li> 9 </ul>
JavaScript
1 /** 2 * Collapsible categories implementation. 3 * 4 */ 5 var category = { 6 find_category: function(target) { 7 var category = target; 8 // This isn't the category, so look for it 9 if(!target.hasClass('collapsible')) { 10 category = target.closest('.collapsible'); 11 } 12 return category; 13 }, 14 collapse: function(target) { 15 var category = this.find_category(target); 16 category.find('.collapsible-content').hide(); 17 category.removeClass('expanded'); 18 category.addClass('collapsed'); 19 }, 20 expand: function(target) { 21 var category = this.find_category(target); 22 category.find('.collapsible-content').show(); 23 category.addClass('expanded'); 24 category.removeClass('collapsed'); 25 }, 26 toggle: function(target) { 27 var category = this.find_category(target); 28 29 var is_expanded = category.hasClass('expanded'); 30 31 if(is_expanded) { 32 this.collapse(category); 33 } else { 34 this.expand(category); 35 } 36 } 37 }
Usage
1 $('.toggle-button').live('click', function() { 2 category.toggle($(this)); 3 return false; 4 });
Recurse through a Ruby tree
CSS posted about 1 year ago by christian
The model:
1 class Category 2 ... 3 def recurse 4 yield(self) 5 6 children.each do |child| 7 child.recurse {|sibling| yield sibling} 8 end 9 end 10 end
The recusion:
1 Category.root.recurse do |child| 2 puts child 3 end