public
Description: This contains various plugins for Feather
Clone URL: git://github.com/eldiablo/feather-plugins.git
Search Repo:
Click here to lend your support to: feather-plugins and make a donation at www.pledgie.com !
First crack at feather-tagging, and a few cleanup things on comments.
mleung (author)
Fri Apr 11 02:13:48 -0700 2008
commit  028917ed6df9505ddc63f4ab234ad69f6e9236ef
tree    c5c9fa42dddd405092acfe6a9aecad41c7bb1725
parent  3e504c9832fad1a35843468324e09e66ef6d52e2
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@
0
 </h5>
0
 <p><a href="#comment-form">Leave a response</a></p>
0
 <ol class="comments" id="comments">
0
-<!-- Put this in a partial -->
0
+<!-- Put this in a partial. Actually I think we should reopen the article model, and stick in has_many :comments. do that. -- Mike -->
0
 <% Comment.all_for_post(@article.id).each do |comment| %>
0
   <li id="comment-<%= comment.id %>" class="comment">
0
     <div class="author">
...
1
 
...
 
1
0
@@ -1,2 +1,2 @@
0
-<%= link_to "#{Comment.all_for_post(article.id, :count)} comments", article.permalink, :anchor => "comments" %><br />
0
+<%= link_to "#{Comment.all_for_post(article.id, :count)} comments", article.permalink, :anchor => "comments" %>
...
 
...
1
0
@@ -1 +1,2 @@
0
+Bud1‡sfwi0blobviewsfwi0blobPÎòvviewsfwswlong¥viewsfwvhshor~  @€ @€ @€ @ E‡DSDB ` @€ @€ @
...
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1 +1,11 @@
0
+class Tags < Application
0
+ # TODO: Make a base plugin controller that has this in it.
0
+ include_plugin_views __FILE__
0
+
0
+ def show(id)
0
+ @tag = Tag.first(:name => id)
0
+ display @tag
0
+ end
0
+
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
0
@@ -1 +1,27 @@
0
+require File.join(File.join(File.dirname(__FILE__), "controllers"), "tags")
0
+require File.join(File.join(File.dirname(__FILE__), "models"), "tag")
0
+require File.join(File.join(File.dirname(__FILE__), "models"), "tagging")
0
+
0
+# This reopens the article class, and adds a bunch of tagging support code.
0
+require File.join(File.join(File.dirname(__FILE__), "lib"), "article")
0
+# This reopens the global_helpers module, and adds the tag cloud stuff.
0
+require File.join(File.join(File.dirname(__FILE__), "lib"), "global_helpers")
0
+
0
+
0
+# Failing out atm
0
+# Hooks::Events.register_event(:after_create_article) do |article|
0
+# article.create_tags
0
+# end
0
+
0
+Merb::Router.prepend do |r|
0
+ r.match('/tags/:id').to(:controller => 'tags', :action =>'show').name(:tag)
0
+end
0
+
0
+Hooks::View.register_view do
0
+ [
0
+ { :name => "article_form_fields", :partial => "tag_field" },
0
+ { :name => "meta_section", :partial => "tag_list" }
0
+ { :name => "sidebar", :partial => "tag_could" }
0
+ ]
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -1 +1,39 @@
0
+# Reopen the article model and wang in the stuff we need.
0
+class Article
0
+ # We define this tags attribute so when the form posts, the params for
0
+ # tags get set, and we can subsequently access it later on.
0
+ attr_accessor :tag_list
0
+
0
+ has_many :taggings
0
+ # Datamapper's version of has_many :through. Not quite as pretty, but it'll get the job done. Or not...
0
+ # This is supposed to work but it just returns a #<DataMapper::Support::TypedSet[Tag]: {}>
0
+ # has_and_belongs_to_many :tags,
0
+ # :join_table => "taggings",
0
+ # :left_foreign_key => "article_id",
0
+ # :right_foreign_key => "tag_id",
0
+ # :class => "Tag"
0
+
0
+ def create_tags
0
+ return if @tag_list.nil? || @tag_list.empty?
0
+ # Wax all the existing taggings.
0
+ self.taggings.each {|t| t.destroy! }
0
+ @tag_list.split(",").each do |t|
0
+ unless t.empty?
0
+ # Hmm, can we do transactions with DM? I'm sure there's a way.
0
+ tag = Tag.create(:name => t.strip)
0
+ Tagging.create(:article_id => self.id, :tag_id => tag.id)
0
+ end
0
+ end
0
+ end
0
+
0
+ after_save do |article|
0
+ article.create_tags
0
+ end
0
+
0
+ # This is probably slower than habtm, but that's not working as stated above.
0
+ def tags
0
+ taggings.map { |tagging| tagging.tag.name }.join(", ")
0
+ end
0
+
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -1 +1,18 @@
0
+module Merb
0
+ module GlobalHelpers
0
+
0
+ def tag_cloud(tags, classes)
0
+ max, min = 0, 0
0
+ tags.each do |t|
0
+ max = t.count.to_i if t.count.to_i > max
0
+ min = t.count.to_i if t.count.to_i < min
0
+ end
0
+ divisor = ((max - min) / classes.size) + 1
0
+ tags.each do |t|
0
+ yield t.name, classes[(t.count.to_i - min) / divisor]
0
+ end
0
+ end
0
+ end
0
+
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
0
@@ -1 +1,17 @@
0
+plugin:
0
+ name: feather-tagging
0
+ author: Michael Leung
0
+ version: 1.0
0
+ homepage: http://featherblog.com
0
+ about: This plugin provides tag support to articles.
0
+ contents:
0
+ .:
0
+ - init.rb
0
+ controllers:
0
+ .:
0
+ - tags.rb
0
+ models:
0
+ .:
0
+ - tag.rb
0
+ - tagging.rb
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -1 +1,15 @@
0
+class Tag < DataMapper::Base
0
+ property :name, :string
0
+ has_and_belongs_to_many :taggings
0
+
0
+ # Has many through would be nice here.
0
+ def articles
0
+ Article.all(:id => taggings.map{|t| t.article_id }) # So tempted to use symbol to_proc but, it's slow. Damn.
0
+ end
0
+
0
+ def to_param
0
+ name
0
+ end
0
+
0
+end
...
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
0
@@ -1 +1,8 @@
0
+class Tagging < DataMapper::Base
0
+ property :article_id, :integer
0
+ property :tag_id, :integer
0
+
0
+ belongs_to :article
0
+ belongs_to :tag
0
+end
...
 
 
 
...
1
2
3
0
@@ -1 +1,4 @@
0
+<p>
0
+ <%= text_control :tag_list, :size => 50, :value => @article.tags, :label => 'Tags (comma separated):' %>
0
+</p>
...
 
 
 
...
1
2
3
0
@@ -1 +1,4 @@
0
+<% unless article.tags.empty? %>
0
+ | tagged with: <%= article.taggings.collect { |tagging| link_to(tagging.tag.name, url(:tag, tagging.tag)) }.join(", ") %>
0
+<% end %>
...
 
 
 
 
...
1
2
3
4
0
@@ -1 +1,5 @@
0
+<!-- We need a way to get these classes in the style sheet. -->
0
+<% tag_cloud @tags, %w(tag1 tag2 tag3 tag4 tag5) do |name, css_class| %>
0
+ <%= link_to(name, tag_path(name), :class => css_class) %>
0
+<% end %>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -1 +1,14 @@
0
+<% throw_content :title do %>
0
+ Articles tagged with <%= @tag.name %>
0
+<% end %>
0
+
0
+<h1>Articles Tagged with '<%= @tag.name %>'</h1>
0
+
0
+<!-- -->
0
+
0
+<% unless @tag.articles.empty? %>
0
+ <%= partial('articles/article', :with => @tag.articles) %>
0
+<% else %>
0
+ No articles found for <%= @tag.name %>.
0
+<% end %>

Comments

    No one has commented yet.