beef-has_assets 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/app/controllers/admin/assets_controller.rb +159 -0
- data/app/helpers/admin/assets_helper.rb +34 -0
- data/app/models/asset.rb +72 -0
- data/app/models/asseting.rb +5 -0
- data/app/views/admin/assets/_browser.html.erb +25 -0
- data/app/views/admin/assets/_document.html.erb +12 -0
- data/app/views/admin/assets/_file_info.html.erb +51 -0
- data/app/views/admin/assets/_form.html.erb +26 -0
- data/app/views/admin/assets/_image.html.erb +19 -0
- data/app/views/admin/assets/_list.html.erb +12 -0
- data/app/views/admin/assets/_toggle.html.erb +4 -0
- data/app/views/admin/assets/index.html.erb +10 -0
- data/app/views/admin/assets/index.js.rjs +1 -0
- data/app/views/admin/assets/rename_category.js.rjs +1 -0
- data/app/views/admin/assets/show.html.erb +36 -0
- data/app/views/admin/assets/show.js.rjs +3 -0
- data/config/routes.rb +5 -0
- data/generators/asset_migration/asset_migration_generator.rb +11 -0
- data/generators/asset_migration/templates/migration.rb +30 -0
- data/generators/assets_admin_files/asset_admin_files_generator.rb +19 -0
- data/generators/assets_admin_files/templates/public/flash/swfupload.swf +0 -0
- data/generators/assets_admin_files/templates/public/javascripts/admin/assets.js +383 -0
- data/generators/assets_admin_files/templates/public/javascripts/swfupload.js +980 -0
- data/generators/assets_admin_files/templates/public/javascripts/upload_progress.js +179 -0
- data/has_assets.gemspec +76 -0
- data/lib/custom_redcloth_tags.rb +18 -0
- data/lib/flash_sesion_cookie_middleware.rb +16 -0
- data/lib/geometry_crop.rb +51 -0
- data/lib/has_assets.rb +28 -0
- data/lib/imagescience_crop.rb +40 -0
- data/lib/swfupload.rb +32 -0
- data/rails/init.rb +19 -0
- data/test/has_assets_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +94 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Steve England
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "has_assets"
|
8
|
+
gem.summary = %Q{Rails Engine. Adds uploadable assets to a model and admin area for files}
|
9
|
+
gem.email = "steve@wearebeef.co.uk"
|
10
|
+
gem.homepage = "http://github.com/beef/assets"
|
11
|
+
gem.authors = ["Steve England"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "has_assets #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,159 @@
|
|
1
|
+
class Admin::AssetsController < Admin::BaseController
|
2
|
+
|
3
|
+
protect_from_forgery :except => [:destroy, :rename_category]
|
4
|
+
|
5
|
+
# GET /assets
|
6
|
+
# GET /assets.xml
|
7
|
+
def index
|
8
|
+
@asset_types = Asset.grouped_by_category
|
9
|
+
@grouping = 'by_category'
|
10
|
+
|
11
|
+
respond_to do |format|
|
12
|
+
format.html { render :action => 'index'}
|
13
|
+
format.xml { @asset_types.to_xml }
|
14
|
+
format.js { render :action => 'index'}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
alias :by_category :index
|
19
|
+
|
20
|
+
def by_content_type
|
21
|
+
@asset_types = Asset.grouped_by_content_type
|
22
|
+
@grouping = 'by_content_type'
|
23
|
+
|
24
|
+
respond_to do |format|
|
25
|
+
format.html { render :action => 'index'}
|
26
|
+
format.xml { @asset_types.to_xml }
|
27
|
+
format.js { render :action => 'index'}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def by_description
|
32
|
+
@asset_types = Asset.grouped_by_description
|
33
|
+
@grouping = 'by_description'
|
34
|
+
|
35
|
+
respond_to do |format|
|
36
|
+
format.html { render :action => 'index'}
|
37
|
+
format.xml { @asset_types.to_xml }
|
38
|
+
format.js { render :action => 'index'}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def descriptions
|
43
|
+
@descriptions = Asset.not_thumbnails.find(:all, :select => 'description', :group => 'description', :order => 'description', :conditions => 'description IS NOT NULL')
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
format.json { render :json => @descriptions.collect{ |a| a.description }}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def categories
|
51
|
+
@categories = Asset.not_thumbnails.find(:all, :select => 'category', :group => 'category', :order => 'category', :conditions => 'category IS NOT NULL')
|
52
|
+
|
53
|
+
respond_to do |format|
|
54
|
+
format.json { render :json => @categories.collect{ |a| a.category }}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# GET /assets/1
|
59
|
+
# GET /assets/1.xml
|
60
|
+
def show
|
61
|
+
@asset = Asset.find(params[:id])
|
62
|
+
|
63
|
+
respond_to do |format|
|
64
|
+
format.js
|
65
|
+
format.xml { render :xml => @asset }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# POST /assets
|
70
|
+
# POST /assets.xml
|
71
|
+
def create
|
72
|
+
@asset = Asset.new(params[:asset])
|
73
|
+
|
74
|
+
respond_to do |format|
|
75
|
+
if @asset.save
|
76
|
+
flash[:notice] = 'Asset was successfully created.'
|
77
|
+
format.html { redirect_to(admin_assets_url) }
|
78
|
+
format.xml { render :xml => @asset, :status => :created, :location => admin_asset_url(@asset) }
|
79
|
+
format.js { render :json => @asset, :status => 200, :location => admin_asset_url(@asset) }
|
80
|
+
else
|
81
|
+
format.html { render :action => "new" }
|
82
|
+
format.xml { render :xml => @asset.errors, :status => :unprocessable_entity }
|
83
|
+
format.js { render :json => @asset.errors, :status => :unprocessable_entity }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# PUT /assets/1
|
89
|
+
# PUT /assets/1.xml
|
90
|
+
def update
|
91
|
+
@asset = Asset.find(params[:id])
|
92
|
+
|
93
|
+
respond_to do |format|
|
94
|
+
if @asset.update_attributes(params[:asset])
|
95
|
+
format.html do
|
96
|
+
flash[:notice] = 'Asset was successfully updated.'
|
97
|
+
redirect_to(admin_assets_url)
|
98
|
+
end
|
99
|
+
format.xml { head :ok }
|
100
|
+
format.js { head :ok }
|
101
|
+
else
|
102
|
+
format.html { render :action => "edit" }
|
103
|
+
format.xml { render :xml => @asset.errors, :status => :unprocessable_entity }
|
104
|
+
format.js { render :json => @asset.errors, :status => :unprocessable_entity }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def select_thumbnail
|
110
|
+
@asset = Asset.find(params[:id])
|
111
|
+
respond_to do |wants|
|
112
|
+
wants.html { render :action => 'replace_thumbnail' }
|
113
|
+
wants.js
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def replace_thumbnail
|
118
|
+
@asset = Asset.find(params[:id])
|
119
|
+
@asset.create_or_update_thumbnail(params[:asset][:uploaded_data],:square,Asset.attachment_options[:thumbnails][:square])
|
120
|
+
respond_to do |format|
|
121
|
+
format.html do
|
122
|
+
flash[:notice] = 'Thumbnail was successfully updated.'
|
123
|
+
redirect_to admin_assets_path
|
124
|
+
end
|
125
|
+
format.js { render :json => @asset, :status => 200 }
|
126
|
+
end
|
127
|
+
|
128
|
+
rescue Technoweenie::AttachmentFu::ThumbnailError => m
|
129
|
+
|
130
|
+
respond_to do |format|
|
131
|
+
format.html { flash[:error] = m }
|
132
|
+
format.js { render :json => [m] }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def rename_category
|
137
|
+
respond_to do |format|
|
138
|
+
format.js do
|
139
|
+
@asset = Asset.find(params[:id])
|
140
|
+
@old_category_name = @asset.category
|
141
|
+
@new_category_name = params[:name]
|
142
|
+
Asset.update_all({:category => @new_category_name}, {:category => @old_category_name}) unless @new_category_name.blank?
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# DELETE /assets/1
|
148
|
+
# DELETE /assets/1.xml
|
149
|
+
def destroy
|
150
|
+
@asset = Asset.find(params[:id])
|
151
|
+
@asset.destroy
|
152
|
+
|
153
|
+
respond_to do |format|
|
154
|
+
format.html { redirect_to(admin_assets_url) }
|
155
|
+
format.js { render :nothing => true }
|
156
|
+
format.xml { head :ok }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Admin::AssetsHelper
|
2
|
+
|
3
|
+
def asset_list(content_node)
|
4
|
+
unless content_node.assets.empty?
|
5
|
+
list = render( :partial => '/admin/assets/list', :locals => { :content_node => content_node } )
|
6
|
+
end
|
7
|
+
content_tag :div, list, :id => 'attach-asset-list'
|
8
|
+
end
|
9
|
+
|
10
|
+
def asset_browser(for_content = false)
|
11
|
+
render :partial => '/admin/assets/browser',
|
12
|
+
:locals => { :asset_types => Asset.grouped_by_category,
|
13
|
+
:for_content => for_content }
|
14
|
+
end
|
15
|
+
|
16
|
+
def asset_upload_form
|
17
|
+
render :partial => '/admin/assets/form'
|
18
|
+
end
|
19
|
+
|
20
|
+
def toggle_grouping_links
|
21
|
+
render :partial => 'admin/assets/toggle'
|
22
|
+
end
|
23
|
+
|
24
|
+
def admin_assets_path_with_session_information
|
25
|
+
session_key = ActionController::Base.session_options[:key]
|
26
|
+
admin_assets_path(session_key => cookies[session_key], request_forgery_protection_token => form_authenticity_token)
|
27
|
+
end
|
28
|
+
|
29
|
+
def replace_thumbnail_admin_asset_path_with_session_information(asset)
|
30
|
+
session_key = ActionController::Base.session_options[:key]
|
31
|
+
replace_thumbnail_admin_asset_path(asset, session_key => cookies[session_key], request_forgery_protection_token => form_authenticity_token)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/app/models/asset.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
class Asset < ActiveRecord::Base
|
2
|
+
has_attachment :storage => :file_system,
|
3
|
+
:path_prefix => 'public/assets',
|
4
|
+
:max_size => 5.megabytes,
|
5
|
+
:resize_to => '900',
|
6
|
+
:thumbnails => { :large => '480x480', :medium => '230x230', :project_large => '750x422!', :project_medium => '250x141!', :thumb => '184', :user_image => '194x194!', :square => '75x75!' }
|
7
|
+
|
8
|
+
has_many :assetings, :dependent => :delete_all
|
9
|
+
belongs_to :assetable, :polymorphic => true
|
10
|
+
|
11
|
+
named_scope :not_thumbnails, :conditions => 'parent_id IS NULL', :order => 'filename'
|
12
|
+
named_scope :images, :conditions => "content_type LIKE 'image%'", :order => 'filename'
|
13
|
+
named_scope :documents, :conditions => "content_type NOT LIKE 'image%'", :order => 'filename'
|
14
|
+
|
15
|
+
validates_as_attachment
|
16
|
+
# validates_presence_of :description, :unless => :is_thumbnail?
|
17
|
+
|
18
|
+
attr_accessor :position
|
19
|
+
attr_accessible :category, :description, :uploaded_data
|
20
|
+
|
21
|
+
def description
|
22
|
+
read_attribute('description').blank? ? 'No Description' : super
|
23
|
+
end
|
24
|
+
|
25
|
+
def category
|
26
|
+
read_attribute('category').blank? ? 'No Folder' : super
|
27
|
+
end
|
28
|
+
|
29
|
+
def is_thumbnail?
|
30
|
+
!parent_id.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def file_type
|
34
|
+
self.content_type.split("/")[1]
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_image?
|
38
|
+
content_type =~ /image/
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.grouped_by_content_type
|
42
|
+
self.not_thumbnails.group_by(&:content_type).sort
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.grouped_by_category
|
46
|
+
self.not_thumbnails.group_by(&:category).sort
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.categories
|
50
|
+
self.find(:all, :group => "category", :select => "category", :order => 'category')
|
51
|
+
end
|
52
|
+
|
53
|
+
def sizes
|
54
|
+
sizes = []
|
55
|
+
if is_image? and not is_thumbnail?
|
56
|
+
sizes << [ 'fullsize', public_filename ]
|
57
|
+
attachment_options[:thumbnails].each_key do |key|
|
58
|
+
sizes << [key.to_s, public_filename(key)]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
sizes
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_json(options = {})
|
65
|
+
methods = [:public_filename]
|
66
|
+
methods << :sizes if is_image?
|
67
|
+
options.reverse_merge! :methods => methods
|
68
|
+
super options
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<% content_for :header do %>
|
2
|
+
<%= javascript_include_tag 'admin/assets', 'swfupload', 'upload_progress' %>
|
3
|
+
<% end -%>
|
4
|
+
|
5
|
+
<dl id="asset-browser">
|
6
|
+
<% asset_types.each do |asset_type, assets| %>
|
7
|
+
<dt class="<%= asset_type.split('/').first.parameterize %>" id="<%= asset_type.parameterize %>-<%= assets.first.id %>"><%= asset_type %></dt>
|
8
|
+
<dd id="<%= asset_type.parameterize %>-description">
|
9
|
+
<h3 class="type-heading"><%= asset_type %></h3>
|
10
|
+
<ul id="<%= asset_type.parameterize %>-list" class="asset-list">
|
11
|
+
<% for asset in assets -%>
|
12
|
+
<li class="<%= asset.content_type.gsub('/', ' ') %>" id="browser-asset-<%= asset.id %>">
|
13
|
+
<% if asset.content_type =~ /image/ -%>
|
14
|
+
<%= render :partial => "admin/assets/image", :locals => { :asset => asset, :for_content => for_content } %>
|
15
|
+
<% else -%>
|
16
|
+
<%= render :partial => "admin/assets/document", :locals => { :asset => asset, :for_content => for_content } %>
|
17
|
+
<% end -%>
|
18
|
+
</li>
|
19
|
+
<% end -%>
|
20
|
+
</ul>
|
21
|
+
</dd>
|
22
|
+
<% end -%>
|
23
|
+
</dl>
|
24
|
+
<%= javascript_tag "new AssetBrowser('#{@grouping}', '#{params[:folder]}');" %>
|
25
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%= link_to_function truncate(asset.filename,{:length => 50}), "AssetBrowser.openInfo(#{asset.id}, this)" %> - <%= asset.description %>
|
2
|
+
<div>
|
3
|
+
<%= link_to_function "View Info<br/>", "AssetBrowser.openInfo(#{asset.id}, this)" %>
|
4
|
+
<% if for_content -%>
|
5
|
+
<%= link_to_function "Insert<br/>", "addAsset(#{asset.id})" %>
|
6
|
+
<%= link_to_function "Attach", "AssetBrowser.addAssetToContentNode(#{asset.to_json}.#{asset.class.name.demodulize.underscore})" %>
|
7
|
+
<% elsif controller.controller_name != 'assets' %>
|
8
|
+
<%= link_to_function "Detach", "AssetBrowser.removeAssetFromContentNode(#{asset.id})" %>
|
9
|
+
<% else %>
|
10
|
+
<%= link_to_function "Delete", "AssetBrowser.assetAction(#{asset.to_json}.#{asset.class.name.demodulize.underscore})" %>
|
11
|
+
<% end -%>
|
12
|
+
</div>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<h3><%=h @asset.filename %></h3>
|
2
|
+
|
3
|
+
<%= link_to_function 'close', 'AssetBrowser.closeInfo()' %>
|
4
|
+
<% if @asset.image? %>
|
5
|
+
<p>
|
6
|
+
<%= image_tag @asset.public_filename(:medium), :title => 'Main Image' %>
|
7
|
+
</p>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% form_for([:admin, @asset]) do |f| %>
|
11
|
+
<%= f.error_messages %>
|
12
|
+
<p>
|
13
|
+
<%= f.label :category, 'Folder' %><br />
|
14
|
+
<%= f.text_field :category %>
|
15
|
+
</p>
|
16
|
+
<div class="auto_complete" id="asset_category_complete" style="display:none"></div>
|
17
|
+
|
18
|
+
<p>
|
19
|
+
<%= f.label :decription %><br />
|
20
|
+
<%= f.text_field :description %>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<p>
|
24
|
+
<%= f.submit "Update", :disable_with => 'Updating...' %>
|
25
|
+
</p>
|
26
|
+
<% end %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<p>
|
30
|
+
<b>Size:</b>
|
31
|
+
<%= number_to_human_size(@asset.size) %>
|
32
|
+
</p>
|
33
|
+
|
34
|
+
<p>
|
35
|
+
<b>Content type:</b>
|
36
|
+
<%=h @asset.content_type %>
|
37
|
+
</p>
|
38
|
+
|
39
|
+
<% if @asset.image? %>
|
40
|
+
|
41
|
+
<p>
|
42
|
+
<b>Height:</b>
|
43
|
+
<%=h @asset.height %>
|
44
|
+
</p>
|
45
|
+
|
46
|
+
<p>
|
47
|
+
<b>Width:</b>
|
48
|
+
<%=h @asset.width %>
|
49
|
+
</p>
|
50
|
+
|
51
|
+
<% end %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<div>
|
2
|
+
<% form_for(:asset, :url => admin_assets_path_with_session_information, :html => { :multipart => true, :id => 'asset-upload-form' } ) do |f| %>
|
3
|
+
<%= f.error_messages %>
|
4
|
+
<p>
|
5
|
+
<%= f.label :category, 'Folder' %><br />
|
6
|
+
<%= f.text_field :category %>
|
7
|
+
</p>
|
8
|
+
<div class="auto_complete" id="asset_category_complete" style="display:none"></div>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
<%= f.label :decription %><br />
|
12
|
+
<%= f.text_field :description %>
|
13
|
+
</p>
|
14
|
+
|
15
|
+
<div id="upload-elements">
|
16
|
+
<p>
|
17
|
+
<%= f.label :uploaded_data, "File" %><br />
|
18
|
+
<%= f.file_field :uploaded_data %>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<%= f.submit "Upload", :disable_with => 'Uploading...' %>
|
23
|
+
</p>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%= image_tag asset.public_filename(:square) %>
|
2
|
+
<div>
|
3
|
+
<h4><%= truncate(asset.filename,{:length => 50}) %></h4>
|
4
|
+
<%= link_to_function "View Info", "AssetBrowser.openInfo(#{asset.id}, this)" %><br />
|
5
|
+
|
6
|
+
<% if for_content -%>
|
7
|
+
<%= link_to_function "Attach", "AssetBrowser.addAssetToContentNode(#{asset.to_json}.#{asset.class.name.demodulize.underscore})" %>
|
8
|
+
<h4>Insert Image</h4>
|
9
|
+
<%= link_to_function "Large", "addAsset(#{asset.id}, 'large' )" %> | <%= link_to_function "Medium ", "addAsset(#{asset.id}, 'medium' )" %> | <%= link_to_function "Small ", "addAsset(#{asset.id}, 'thumb' )" %>
|
10
|
+
|
11
|
+
<% elsif controller.controller_name != 'assets' %>
|
12
|
+
|
13
|
+
<%= link_to_function "Detach", "AssetBrowser.removeAssetFromContentNode(#{asset.id})" %>
|
14
|
+
<h4>Insert Image</h4>
|
15
|
+
<%= link_to_function "Large", "addAsset(#{asset.id}, 'large' )" %> | <%= link_to_function "Medium ", "addAsset(#{asset.id}, 'medium' )" %> | <%= link_to_function "Small ", "addAsset(#{asset.id}, 'thumb' )" %>
|
16
|
+
<% else %>
|
17
|
+
<%= link_to_function "Delete", "AssetBrowser.assetAction(#{asset.to_json}.#{asset.class.name.demodulize.underscore})" %>
|
18
|
+
<% end -%>
|
19
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2><%= content_node.class.name.titleize %> Files</h2>
|
2
|
+
<ul class="asset-list" id="asset-list">
|
3
|
+
<% for asset in content_node.assets -%>
|
4
|
+
<li id="asset-<%= asset.id %>" class="<%= asset.content_type.gsub('/','-') %>">
|
5
|
+
<% if asset.content_type =~ /image/ -%>
|
6
|
+
<%= render :partial => "admin/assets/image", :locals => { :asset => asset, :for_content => false } %>
|
7
|
+
<% else -%>
|
8
|
+
<%= render :partial => "admin/assets/document", :locals => { :asset => asset, :for_content => false } %>
|
9
|
+
<% end -%>
|
10
|
+
</li>
|
11
|
+
<% end -%>
|
12
|
+
</ul>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<ul class="choices">
|
2
|
+
<li><%= link_to 'Browse folders', by_category_admin_assets_path, :id => 'toggle-grouping', :onclick => 'AssetBrowser.reload("by_category"); return false;' %></li>
|
3
|
+
<li><%= link_to 'Group by file type', by_content_type_admin_assets_path, :id => 'toggle-grouping', :onclick => 'AssetBrowser.reload("by_content_type"); return false;' %></li>
|
4
|
+
</ul>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h1>Browse for Files</h1>
|
2
|
+
<%= toggle_grouping_links %>
|
3
|
+
<div id="main-browser">
|
4
|
+
<%= render :partial => 'browser', :locals => { :asset_types => @asset_types, :for_content => false } %>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<% content_for :sub_content do %>
|
8
|
+
<h2>Upload File</h2>
|
9
|
+
<%= asset_upload_form %>
|
10
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
page.replace 'asset-browser', :partial => '/admin/assets/browser', :locals => { :asset_types => @asset_types, :for_content => (params[:for_content] == 'true' )}
|
@@ -0,0 +1 @@
|
|
1
|
+
page << 'AssetBrowser.reload()';
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<h1>Showing assets <%=h @asset.filename %></h1>
|
2
|
+
|
3
|
+
<% if @asset.image? %>
|
4
|
+
<p>
|
5
|
+
<%= image_tag @asset.public_filename(:medium) %>
|
6
|
+
</p>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<p>
|
10
|
+
<b>Description:</b>
|
11
|
+
<%=h @asset.description %>
|
12
|
+
</p>
|
13
|
+
|
14
|
+
<p>
|
15
|
+
<b>Size:</b>
|
16
|
+
<%=h bytesToMeg(@resource.size) %>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p>
|
20
|
+
<b>Content type:</b>
|
21
|
+
<%=h @asset.content_type %>
|
22
|
+
</p>
|
23
|
+
|
24
|
+
<% if @asset.image? %>
|
25
|
+
|
26
|
+
<p>
|
27
|
+
<b>Height:</b>
|
28
|
+
<%=h @asset.height %>
|
29
|
+
</p>
|
30
|
+
|
31
|
+
<p>
|
32
|
+
<b>Width:</b>
|
33
|
+
<%=h @asset.width %>
|
34
|
+
</p>
|
35
|
+
|
36
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
map.namespace(:admin) do |admin|
|
3
|
+
admin.resources :assets, :collection => { :by_content_type => :get, :descriptions => :get, :by_category => :get, :categories => :get }, :member => { :set_lead => :put, :rename_category => :post }
|
4
|
+
end
|
5
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class CreateAssets < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :assets do |t|
|
4
|
+
t.string :filename, :category, :description, :content_type
|
5
|
+
t.integer :size, :height , :width
|
6
|
+
t.references :parent, :assetable
|
7
|
+
t.string :assetable_type, :limit => 20
|
8
|
+
t.string :thumbnail
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :assets, :content_type
|
14
|
+
|
15
|
+
create_table :assetings do |t|
|
16
|
+
t.references :asset, :assetable
|
17
|
+
t.string :assetable_type, :limit => 20
|
18
|
+
t.integer :position, :default => 1, :null => false
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :assetings, :asset_id
|
23
|
+
add_index :assetings, [:assetable_id, :assetable_type]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.down
|
27
|
+
drop_table :assetings
|
28
|
+
drop_table :assets
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class AssetAdminFilesGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
m.directory File.join("public", "javascripts", "admin")
|
6
|
+
m.directory File.join("public", "stylesheets", "admin")
|
7
|
+
m.directory File.join("public", "flash")
|
8
|
+
|
9
|
+
|
10
|
+
["public/flash/swfupload.swf",
|
11
|
+
"public/javascripts/admin/assets.js",
|
12
|
+
"public/javascripts/swfupload.js",
|
13
|
+
"public/javascripts/upload_progress.js"].each do |file|
|
14
|
+
m.file file, file
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
Binary file
|