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 !
added asset controller for displaying assets from the db

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@799 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Feb 12 22:39:50 -0800 2006
commit  86626ffac2ec106e100cda88aeb1f1111dff877d
tree    2b9d2dc97630a5107e69831390e244a55b318c0a
parent  790cc0ed9831a078fa3c95838c88ec6d5f9aa137
...
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
11
12
...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
...
36
37
38
 
 
 
 
 
 
 
 
 
 
 
39
40
41
0
@@ -7,6 +7,24 @@ class Attachment < ActiveRecord::Base
0
     def find_with_data(quantity, options = {})
0
       find quantity, options.merge(:select => 'attachments.*, db_files.data', :joins => 'LEFT OUTER JOIN db_files ON attachments.db_file_id = db_files.id')
0
     end
0
+
0
+ def find_by_full_path(full_path)
0
+ pieces = full_path.split '/'
0
+ filename = pieces.pop
0
+ path = pieces.join '/'
0
+ find_with_data :first, :conditions => ['path = ? and filename = ?', path, filename]
0
+ end
0
+ end
0
+
0
+ # Read from the model's attributes if it's available.
0
+ def data
0
+ read_attribute(:data) || (db_file_id ? db_file.data : nil)
0
+ end
0
+
0
+ # set the model's data attribute and attachment_data
0
+ def data=(value)
0
+ write_attribute :data, value
0
+ self.attachment_data = value
0
   end
0
 
0
   def full_path
0
@@ -18,17 +36,6 @@ class Attachment < ActiveRecord::Base
0
       base.validate :path_exists_and_valid?
0
     end
0
 
0
- # Read from the model's attributes if it's available.
0
- def data
0
- read_attribute(:data) || (db_file_id ? db_file.data : nil)
0
- end
0
-
0
- # set the model's data attribute and attachment_data
0
- def data=(value)
0
- write_attribute :data, value
0
- self.attachment_data = value
0
- end
0
-
0
     protected
0
     def path_exists_and_valid?
0
       errors.add(:path, ActiveRecord::Errors.default_error_messages[:blank]) if path.blank?
...
1
2
3
4
 
 
 
 
 
 
 
 
5
6
7
...
1
 
2
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -1,7 +1,14 @@
0
 ActionController::Routing::Routes.draw do |map|
0
- map.admin 'admin', :controller => 'admin/base', :action => 'index'
0
   map.feed 'feed/*categories', :controller => 'feed', :action => 'feed'
0
 
0
+ map.with_options :controller => 'assets', :action => 'show' do |map|
0
+ map.css 'stylesheets/*path', :dir => 'stylesheets'
0
+ map.js 'javascripts/*path', :dir => 'javascripts'
0
+ map.images 'images/*path', :dir => 'images'
0
+ end
0
+
0
+ map.admin 'admin', :controller => 'admin/base', :action => 'index'
0
+
0
   map.connect ':controller/:action/:id'
0
 
0
   map.comment ':year/:month/:day/:permalink/comment', :controller => 'comments', :action => 'create',
...
124
125
126
 
127
...
124
125
126
127
128
0
@@ -124,3 +124,4 @@ quentin:
0
   content_type: 'image/png'
0
   size: 1
0
   filename: foobar.png
0
+ path: images
0
\ No newline at end of file
...
12
13
14
 
 
 
 
 
 
15
...
12
13
14
15
16
17
18
19
20
21
0
@@ -12,4 +12,10 @@ class AttachmentTest < Test::Unit::TestCase
0
     assert a.id
0
     assert_equal 'foo/bar/baz', a.path
0
   end
0
+
0
+ def test_should_find_by_full_path
0
+ assert_equal attachments(:css), Attachment.find_by_full_path('stylesheets/style.css')
0
+ assert_equal attachments(:js), Attachment.find_by_full_path('javascripts/behavior.js')
0
+ assert_equal attachments(:quentin), Attachment.find_by_full_path('images/foobar.png')
0
+ end
0
 end

Comments

    No one has commented yet.