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 !
added a basic file upload plugin, allowing custom files such as images to 
be served and hosted alongside your blog
eldiablo (author)
Fri Apr 18 18:16:15 -0700 2008
commit  3c2e3fe848768fded1405b915eaa319f6552bf60
tree    3dbce64fb1c874aecd2830e0f069d09da23d21b7
parent  4c3f4653c489c5cd975a6f9505d5684161782fbb
0
...
10
11
12
 
...
10
11
12
13
0
@@ -10,4 +10,5 @@
0
 feather-snippets: this allows custom and dynamic creation of snippets to add to the blog template
0
 feather-styles: this allows custom stylesheets to be defined and automatically included so as to override default blog styling
0
 feather-tagging: this provides tagging for articles, and a tag cloud for the blog sidebar
0
+feather-uploads: this allows for custom files to be uploaded and served
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
39
40
41
42
43
44
45
46
47
48
49
50
0
@@ -1 +1,51 @@
0
+module Admin
0
+ class Uploads < Base
0
+ include_plugin_views __FILE__
0
+
0
+ before :find_upload, :only => %w(delete show)
0
+
0
+ def index
0
+ @uploads = Upload.all
0
+ display @uploads
0
+ end
0
+
0
+ def new
0
+ @upload = Upload.new
0
+ display @upload
0
+ end
0
+
0
+ def create(upload)
0
+ @upload = Upload.new(upload)
0
+ @upload.url = (@upload.url[0...1] == "/" ? @upload.url : "/#{@upload.url}")
0
+ @upload.url = (@upload.url[0...6] == "/files" ? @upload.url : "/files#{@upload.url}")
0
+ FileUtils.mkdir_p Merb.dir_for(:public) / File.dirname(@upload.url)
0
+ unless params[:file].nil? || params[:file][:tempfile].nil?
0
+ @upload.size = params[:file][:size]
0
+ @upload.content_type = params[:file][:content_type]
0
+ FileUtils.mv(params[:file][:tempfile].path, (Merb.dir_for(:public) / @upload.url))
0
+ end
0
+ @upload.created_at = Time.now
0
+ if @upload.save
0
+ redirect url(:admin_upload)
0
+ else
0
+ render :new
0
+ end
0
+ end
0
+
0
+ def delete
0
+ @upload.destroy!
0
+ File.delete(Merb.dir_for(:public) / @upload.url)
0
+ redirect url(:admin_uploads)
0
+ end
0
+
0
+ def show
0
+ display @upload
0
+ end
0
+
0
+ private
0
+ def find_upload
0
+ @upload = Upload[params[:id]]
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1 +1,11 @@
0
+require File.join(File.join(File.join(File.dirname(__FILE__), "controllers"), "admin"), "uploads")
0
+require File.join(File.join(File.dirname(__FILE__), "models"), "upload")
0
+
0
+Merb::Router.prepend do |r|
0
+ r.namespace :admin do |admin|
0
+ admin.resources :uploads
0
+ end
0
+end
0
+
0
+Hooks::Menu.add_menu_item "Uploads", "/admin/uploads"
...
 
...
1
0
@@ -1 +1,2 @@
0
+Database::migrate(Upload)
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,29 @@
0
+plugin:
0
+ name: feather-uploads
0
+ author: El Draper
0
+ version: 1.0
0
+ homepage: http://featherblog.com
0
+ about: This plugin adds the ability for the user to upload and manage files
0
+ contents:
0
+ .:
0
+ - init.rb
0
+ - install.rb
0
+ controllers:
0
+ admin:
0
+ - uploads.rb
0
+ models:
0
+ .:
0
+ - upload.rb
0
+ views:
0
+ .:
0
+ admin:
0
+ .:
0
+ uploads:
0
+ .:
0
+ - _form.html.erb
0
+ - _upload.html.erb
0
+ - edit.html.erb
0
+ - index.html.erb
0
+ - new.html.erb
0
+ - show.html.erb
...
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1 +1,11 @@
0
+class Upload < DataMapper::Base
0
+ property :url, :string, :nullable => false, :length => 255
0
+ property :content_type, :string, :nullable => false, :length => 255
0
+ property :size, :integer
0
+ property :created_at, :datetime, :nullable => false
0
+
0
+ validates_presence_of :url, :key => "uniq_url"
0
+ validates_presence_of :content_type, :key => "uniq_content_type"
0
+ validates_presence_of :size, :key => "uniq_size"
0
+end
...
 
 
...
1
2
0
@@ -1 +1,3 @@
0
+<%= text_control :url, :label => "URL:" %>
0
+<%= file_field :name => "file", :label => "File:" %>
...
 
 
 
 
 
 
...
1
2
3
4
5
6
0
@@ -1 +1,7 @@
0
+<tr>
0
+ <td><%= link_to upload.url, url(:admin_upload, upload) %></td>
0
+ <td><%= upload.content_type %></td>
0
+ <td><%= upload.size %></td>
0
+ <td><%= link_to 'Delete', url(:delete_admin_upload, upload), {:method => :delete, :onclick => "return confirm('Are you sure?')"} %></td>
0
+</tr>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -1 +1,21 @@
0
+<% throw_content :right do %>
0
+ <h4>View Uploads</h4>
0
+ <p>
0
+ Uploads allow you to serve custom files such as images.
0
+ </p>
0
+<% end %>
0
+
0
+<h1>View Uploads</h1>
0
+
0
+<table>
0
+ <tr>
0
+ <th>URL</th>
0
+ <th>Content-Type</th>
0
+ <th>Size</th>
0
+ <th>&nbsp;</th>
0
+ </tr>
0
+ <%= partial('admin/uploads/upload', :with => @uploads) %>
0
+</table>
0
+<br />
0
+<%= link_to "Upload new file", url(:new_admin_upload) %>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1 +1,16 @@
0
+<% throw_content :right do %>
0
+ <p>
0
+ Upload a new file here.
0
+ </p>
0
+<% end %>
0
+
0
+<%= error_messages_for @upload %>
0
+<h1>New Upload</h1>
0
+
0
+<% form_for :upload, :action => url(:admin_upload, @upload), :enctype => "multipart/form-data" do %>
0
+ <%= partial 'form' %>
0
+ <p><%= submit_button 'Upload file' %> or <%= link_to 'Cancel', url(:admin_uploads) %></p>
0
+<% end %>
0
+
0
+<%= link_to "Back to uploads", url(:admin_uploads) %>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
+<% throw_content :right do %>
0
+ <h4>View Upload</h4>
0
+ <p>
0
+ Here you can view the details of an existing file upload.
0
+ </p>
0
+<% end %>
0
+
0
+<h1>View Upload</h1>
0
+
0
+<p>
0
+ URL: <%= @upload.url %>
0
+</p>
0
+
0
+<p>
0
+ Content-Type: <%= @upload.content_type %>
0
+</p>
0
+
0
+<p>
0
+ Size: <%= @upload.size %>
0
+</p>
0
+
0
+<p>
0
+ <%= link_to "View", @upload.url %>
0
+</p>
0
+
0
+<%= link_to "Back to uploads", url(:admin_uploads) %>

Comments

    No one has commented yet.