public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
add asset drop

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2317 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Oct 03 23:04:20 -0700 2006
commit  9e8a69f27696509e90a14f3382289090103a8f07
tree    d61f986379b1bbae028639b4047f9349fce21120
parent  c74d46232e3cede6a31bf68734fc4c686b68eddc
...
61
62
63
 
 
 
 
64
65
66
...
61
62
63
64
65
66
67
68
69
70
0
@@ -61,6 +61,10 @@ class ArticleDrop < BaseDrop
0
   def changes_feed_url
0
     @changes_feed_url ||= url + '/changes.xml'
0
   end
0
+
0
+ def tags
0
+ @tags ||= @source.tags.collect &:to_liquid
0
+ end
0
 
0
   protected
0
     def body_for_mode(mode)
...
31
32
33
 
 
 
 
 
 
 
 
 
 
 
 
34
35
...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
0
@@ -31,4 +31,16 @@ module DropFilters
0
       articles.collect! { |a| a.to_liquid :site => @context['site'].source, :mode => :single }
0
     end
0
   end
0
+
0
+ def tagged_articles(tags)
0
+ @context['site'].source.articles.find(:all, :include => :tags, :conditions => ['tags.name in (?)', Tag.parse(tags)], :order => 'contents.created_at desc').collect(&:to_liquid)
0
+ end
0
+
0
+ def assets_by_type(type)
0
+ @context['site'].source.assets.find_all_by_content_types([type.to_sym], :all, :order => 'created_at desc').collect(&:to_liquid)
0
+ end
0
+
0
+ def tagged_assets(tags)
0
+ @context['site'].source.assets.find(:all, :include => :tags, :conditions => ['tags.name in (?)', Tag.parse(tags)], :order => 'assets.created_at desc').collect(&:to_liquid)
0
+ end
0
 end
0
\ No newline at end of file
...
76
77
78
 
 
 
 
79
80
81
...
76
77
78
79
80
81
82
83
84
85
0
@@ -76,6 +76,10 @@ class Asset < ActiveRecord::Base
0
     define_method("#{content}?") { self.class.send("#{content}?", content_type) }
0
   end
0
 
0
+ def to_liquid
0
+ AssetDrop.new self
0
+ end
0
+
0
   protected
0
     def rename_unique_filename
0
       if (@old_filename || new_record?) && errors.empty? && site_id && filename
...
47
48
49
50
51
52
53
...
47
48
49
 
50
51
52
0
@@ -47,7 +47,6 @@ class Site < ActiveRecord::Base
0
   
0
   has_many :cached_pages
0
   
0
- has_many :assets, :as => :attachable, :order => 'created_at desc'
0
   has_many :assets, :order => 'created_at desc', :conditions => 'parent_id is null'
0
 
0
   has_many :memberships, :dependent => :destroy
...
83
84
85
 
 
 
 
86
...
83
84
85
86
87
88
89
90
0
@@ -83,4 +83,8 @@ class ArticleDropTest < Test::Unit::TestCase
0
     t = Time.now.utc - 3.days
0
     assert_equal "/#{t.year}/#{t.month}/#{t.day}/welcome-to-mephisto/changes.xml", @article.changes_feed_url
0
   end
0
+
0
+ specify "should show taggable tags" do
0
+ assert_equal %w(rails), contents(:another).to_liquid.tags
0
+ end
0
 end
...
1
2
3
 
4
5
6
...
55
56
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
...
1
2
 
3
4
5
6
...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
0
@@ -1,6 +1,6 @@
0
 require File.dirname(__FILE__) + '/../test_helper'
0
 context "Drop Filters" do
0
- fixtures :sites, :sections, :contents, :assigned_sections
0
+ fixtures :sites, :sections, :contents, :assigned_sections, :assets
0
   include DropFilters, CoreFilters
0
 
0
   def setup
0
@@ -55,4 +55,27 @@ context "Drop Filters" do
0
     assert_models_equal sections(:home).articles.find_all_in_month(Time.now.year, Time.now.month), monthly_articles(sections(:home).to_liquid).collect(&:source)
0
   end
0
 
0
+ specify "should find movies" do
0
+ assert_models_equal [assets(:swf), assets(:mov)], assets_by_type('movie').collect(&:source)
0
+ end
0
+
0
+ specify "should find audio" do
0
+ assert_models_equal [assets(:mp3)], assets_by_type('audio').collect(&:source)
0
+ end
0
+
0
+ specify "should find images" do
0
+ assert_models_equal [assets(:png), assets(:gif)], assets_by_type('image').collect(&:source)
0
+ end
0
+
0
+ specify "should find others" do
0
+ assert_models_equal [assets(:word), assets(:pdf)], assets_by_type('other').collect(&:source)
0
+ end
0
+
0
+ specify "should find assets by tag" do
0
+ assert_models_equal [contents(:welcome)], tagged_articles("rails").collect(&:source)
0
+ end
0
+
0
+ specify "should find assets by tag" do
0
+ assert_models_equal [assets(:gif)], tagged_assets("ruby").collect(&:source)
0
+ end
0
 end

Comments

    No one has commented yet.