radiant-assets-extension 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -1
- data/app/controllers/admin/assets_controller.rb +0 -1
- data/app/helpers/assets_helper.rb +51 -8
- data/app/models/asset.rb +37 -0
- data/app/models/asset_tags.rb +23 -9
- data/app/views/admin/assets/_grid.html.erb +16 -0
- data/app/views/admin/assets/_list.html.erb +22 -0
- data/app/views/admin/assets/edit.html.erb +9 -9
- data/app/views/admin/assets/index.html.erb +3 -17
- data/app/views/admin/assets/new.html.erb +1 -1
- data/app/views/admin/assets/remove.html.erb +4 -2
- data/db/migrate/20110225023017_rename_model_class.rb +9 -0
- data/lib/radiant-assets-extension/version.rb +1 -1
- data/public/stylesheets/admin/extensions/assets/assets.css +51 -2
- metadata +8 -5
- data/app/models/image.rb +0 -4
data/README
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
Provides simple image handling, incl. on-the-fly resizing. Intended as a
|
4
4
|
replacement for paperclipped in the long run, but very barebones right now.
|
5
5
|
|
6
|
+
Supports uploading of images as well as other files.
|
7
|
+
|
6
8
|
== Radius Tags
|
7
9
|
|
8
10
|
<r:images size="300x" />
|
@@ -14,6 +16,5 @@ request.
|
|
14
16
|
|
15
17
|
== Todo
|
16
18
|
|
17
|
-
- Handling of non-image uploads
|
18
19
|
- Attaching Assets to Pages
|
19
20
|
- Easy/Automatic migration from paperclipped
|
@@ -1,16 +1,21 @@
|
|
1
1
|
module AssetsHelper
|
2
|
-
def
|
3
|
-
|
4
|
-
content_tag(:span,
|
2
|
+
def asset_listing(asset)
|
3
|
+
icon(asset) +
|
4
|
+
content_tag(:span, asset.to_s, :class=>'title')
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
7
|
+
def icon(asset, size=30)
|
8
|
+
asset.image? ? square_thumb(asset, size) : text_icon(asset, size)
|
9
|
+
end
|
10
|
+
|
11
|
+
def text_icon(asset, size=30)
|
12
|
+
css = "width:#{size}px;height:#{size}px;line-height:#{size}px"
|
13
|
+
content_tag(:span, asset.format, :class => "icon #{asset.format}", :style => css)
|
10
14
|
end
|
11
15
|
|
12
|
-
def
|
13
|
-
|
16
|
+
def square_thumb(image, size=30)
|
17
|
+
src = image.upload.thumb("#{size}x#{size}#").url
|
18
|
+
image_tag(src, :width=>size, :height => size, :class => "thumbnail #{image.format}")
|
14
19
|
end
|
15
20
|
|
16
21
|
def image_tag(*args)
|
@@ -21,4 +26,42 @@ module AssetsHelper
|
|
21
26
|
super(*args)
|
22
27
|
end
|
23
28
|
end
|
29
|
+
|
30
|
+
def display(asset)
|
31
|
+
if @asset.image?
|
32
|
+
content_tag :div, image_tag(@asset), :class => "image frame #{@asset.format}"
|
33
|
+
elsif @asset.audio?
|
34
|
+
audio_player(@asset)
|
35
|
+
elsif @asset.video?
|
36
|
+
video_player(@asset)
|
37
|
+
elsif @asset.format == :pdf
|
38
|
+
content_tag :iframe, '', :src => @asset.upload.url, :class => "pdf frame"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def video_player(asset)
|
43
|
+
content_tag :video, :controls => 'controls' do
|
44
|
+
content_tag :source, '', :src => @asset.upload.url, :type => @asset.upload.mime_type
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def audio_player(asset)
|
49
|
+
%Q{<audio src="#{asset.upload.url}" type="#{asset.upload.mime_type}" controls="controls">}
|
50
|
+
end
|
51
|
+
|
52
|
+
def link_to_remove(asset)
|
53
|
+
link_to 'Remove', remove_admin_asset_path(asset), :class => 'action remove', :title => 'Remove Asset'
|
54
|
+
end
|
55
|
+
|
56
|
+
def list_view?
|
57
|
+
params[:view] == 'list'
|
58
|
+
end
|
59
|
+
|
60
|
+
def view_toggle
|
61
|
+
if list_view?
|
62
|
+
link_to 'Grid view', admin_assets_path(:view => 'grid')
|
63
|
+
else
|
64
|
+
link_to 'List view', admin_assets_path(:view => 'list')
|
65
|
+
end
|
66
|
+
end
|
24
67
|
end
|
data/app/models/asset.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
class Asset < ActiveRecord::Base
|
2
|
+
# HACK: incomplete
|
3
|
+
AUDIO_FORMATS = [:wav, :mp3, :m4a, :ogg]
|
4
|
+
VIDEO_FORMATS = [:mp4, :avi]
|
5
|
+
|
6
|
+
image_accessor :upload
|
7
|
+
validates_presence_of :upload
|
8
|
+
|
9
|
+
def format
|
10
|
+
# HACK: relying on extension instead of using analyser and upload.format
|
11
|
+
# analyser can throw us into very long loop when trying to identify
|
12
|
+
# non-image files like word docs
|
13
|
+
upload.ext.to_sym
|
14
|
+
rescue UnableToHandle
|
15
|
+
:generic
|
16
|
+
end
|
17
|
+
|
18
|
+
def image?
|
19
|
+
# PDF is listed as supported by imagemagick but thumbnailing etc. doesn't
|
20
|
+
# work reliably so we treat it as a non-image
|
21
|
+
return false if format == :pdf
|
22
|
+
image_formats = Dragonfly::Encoding::ImageMagickEncoder.new.supported_formats
|
23
|
+
image_formats.include?(format)
|
24
|
+
end
|
25
|
+
|
26
|
+
def audio?
|
27
|
+
AUDIO_FORMATS.include?(format)
|
28
|
+
end
|
29
|
+
|
30
|
+
def video?
|
31
|
+
VIDEO_FORMATS.include?(format)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
caption || upload.name
|
36
|
+
end
|
37
|
+
end
|
data/app/models/asset_tags.rb
CHANGED
@@ -28,7 +28,7 @@ module AssetTags
|
|
28
28
|
# resizing proportionally
|
29
29
|
tag 'image' do |tag|
|
30
30
|
assert_id_given(tag)
|
31
|
-
image =
|
31
|
+
image = find_asset(tag)
|
32
32
|
%{<img src="#{image.url}" width="#{image.width}" height="#{image.height}">}
|
33
33
|
end
|
34
34
|
|
@@ -42,7 +42,7 @@ module AssetTags
|
|
42
42
|
}
|
43
43
|
tag 'asset' do |tag|
|
44
44
|
assert_id_given(tag)
|
45
|
-
tag.locals.asset =
|
45
|
+
tag.locals.asset = find_asset(tag)
|
46
46
|
tag.expand
|
47
47
|
end
|
48
48
|
|
@@ -51,15 +51,29 @@ module AssetTags
|
|
51
51
|
Renders the #{attribute} of the current asset
|
52
52
|
}
|
53
53
|
tag "asset:#{attribute}" do |tag|
|
54
|
-
tag.locals.asset
|
54
|
+
tag.locals.asset.send(attribute.to_sym)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
desc %{
|
59
|
-
Renders the caption of the current
|
59
|
+
Renders the caption of the current asset
|
60
60
|
}
|
61
61
|
tag 'asset:caption' do |tag|
|
62
|
-
tag.locals.asset
|
62
|
+
tag.locals.asset.caption
|
63
|
+
end
|
64
|
+
|
65
|
+
desc %{
|
66
|
+
Renders contents if the current asset is an image
|
67
|
+
}
|
68
|
+
tag 'asset:if_image' do |tag|
|
69
|
+
tag.expand if tag.locals.asset.image?
|
70
|
+
end
|
71
|
+
|
72
|
+
desc %{
|
73
|
+
Renders contents if the current asset isn't an image
|
74
|
+
}
|
75
|
+
tag 'asset:unless_image' do |tag|
|
76
|
+
tag.expand unless tag.locals.asset.image?
|
63
77
|
end
|
64
78
|
|
65
79
|
%w[landscape portrait].each do |orientation|
|
@@ -83,12 +97,12 @@ private
|
|
83
97
|
raise TagError, 'Please supply an id attribute' unless tag.attr['id']
|
84
98
|
end
|
85
99
|
|
86
|
-
def
|
87
|
-
|
100
|
+
def find_asset(tag)
|
101
|
+
asset = Asset.find(tag.attr['id'])
|
88
102
|
if(tag.attr['size'])
|
89
|
-
|
103
|
+
asset.upload.process(:resize, tag.attr['size'])
|
90
104
|
else
|
91
|
-
|
105
|
+
asset.upload
|
92
106
|
end
|
93
107
|
end
|
94
108
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<ul id="assets">
|
2
|
+
<% unless @assets.empty? %>
|
3
|
+
<% @assets.each do |asset| %>
|
4
|
+
<li>
|
5
|
+
<% link_to edit_admin_asset_path(asset) do %>
|
6
|
+
<%= icon(asset, 120) %>
|
7
|
+
<span class="id">ID: <%= asset.id %></span>
|
8
|
+
<span class="caption"><%= asset %></span>
|
9
|
+
<% end %>
|
10
|
+
<%= link_to_remove(asset) %>
|
11
|
+
</li>
|
12
|
+
<% end %>
|
13
|
+
<% else %>
|
14
|
+
<li class='empty'>No Assets</li>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<table class="index" id="assets">
|
2
|
+
<thead>
|
3
|
+
<th class="name">Name</th>
|
4
|
+
<th class="format">Type</th>
|
5
|
+
<th class="size">Size</th>
|
6
|
+
<th class="actions">Modify</th>
|
7
|
+
</thead>
|
8
|
+
<tbody>
|
9
|
+
<% unless @assets.empty? %>
|
10
|
+
<% @assets.each do |asset| %>
|
11
|
+
<tr>
|
12
|
+
<td class="name"><%= asset_listing(asset) %></td>
|
13
|
+
<td class="format"><%= asset.format.to_s.mb_chars.upcase %></td>
|
14
|
+
<td class="size"><%= number_to_human_size(asset.upload.size) %></td>
|
15
|
+
<td class="actions"><%= link_to_remove(asset) %></td>
|
16
|
+
</tr>
|
17
|
+
<% end %>
|
18
|
+
<% else %>
|
19
|
+
<tr><td class="empty" colspan="3"></td></tr>
|
20
|
+
<% end %>
|
21
|
+
</tbody>
|
22
|
+
</table>
|
@@ -2,27 +2,27 @@
|
|
2
2
|
|
3
3
|
<h1>Edit Asset</h1>
|
4
4
|
|
5
|
-
<% form_for
|
5
|
+
<% form_for [:admin, @asset], :html => {'data-onsubmit_status' => onsubmit_status(@asset)} do |f| %>
|
6
6
|
<div class="form_area">
|
7
7
|
<p class="title">
|
8
8
|
Caption: <%= f.text_field :caption %>
|
9
9
|
</p>
|
10
10
|
<table>
|
11
11
|
<tbody>
|
12
|
-
<tr><th>Name</th><td><%= @
|
13
|
-
|
14
|
-
<tr><th>
|
12
|
+
<tr><th>Name</th><td><%= @asset.upload.name %></td></tr>
|
13
|
+
<% if @asset.image? %>
|
14
|
+
<tr><th>Width</th><td><%= @asset.upload.width %></td></tr>
|
15
|
+
<tr><th>Height</th><td><%= @asset.upload.height %></td></tr>
|
16
|
+
<% end %>
|
15
17
|
</tbody>
|
16
18
|
</table>
|
17
19
|
<!-- FIXME: doesn't work at the moment -->
|
18
20
|
<!-- <%= f.file_field :upload %> -->
|
19
|
-
|
20
|
-
<%= image_tag @image %>
|
21
|
-
</div>
|
21
|
+
<%= display(@asset) %>
|
22
22
|
</div>
|
23
23
|
<p class="buttons">
|
24
|
-
<%= save_model_button(@
|
25
|
-
<%= save_model_and_continue_editing_button(@
|
24
|
+
<%= save_model_button(@asset) %>
|
25
|
+
<%= save_model_and_continue_editing_button(@asset) %>
|
26
26
|
or <%= link_to 'Cancel', admin_assets_url %>
|
27
27
|
</p>
|
28
28
|
<% end %>
|
@@ -1,27 +1,13 @@
|
|
1
1
|
<% include_stylesheet 'admin/extensions/assets/assets' %>
|
2
2
|
|
3
3
|
<div class="outset">
|
4
|
-
|
5
|
-
<% unless @images.empty? %>
|
6
|
-
<% @images.each do |image| %>
|
7
|
-
<li>
|
8
|
-
<% link_to edit_admin_asset_path(image) do %>
|
9
|
-
<%= square_thumb(image, 120) %>
|
10
|
-
<span class="id">ID: <%= image.id %></span>
|
11
|
-
<span class="caption"><%= image.caption %></span>
|
12
|
-
<% end %>
|
13
|
-
<%= link_to 'Remove', remove_admin_asset_path(image), :class => 'action remove', :title => 'Remove Asset' %>
|
14
|
-
</li>
|
15
|
-
<% end %>
|
16
|
-
<% else %>
|
17
|
-
<li class='empty'>No Assets</li>
|
18
|
-
<% end %>
|
19
|
-
</ul>
|
4
|
+
<%= render :partial => list_view? ? 'list' : 'grid' %>
|
20
5
|
</div>
|
21
6
|
|
22
7
|
<div id="actions">
|
23
|
-
<%= pagination_for(@
|
8
|
+
<%= pagination_for(@assets) %>
|
24
9
|
<ul>
|
25
10
|
<li class="new"><%= link_to 'Upload New Asset', new_admin_asset_path %></li>
|
11
|
+
<li><%= view_toggle %></li>
|
26
12
|
</ul>
|
27
13
|
</div>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<h1>Upload New Asset</h1>
|
2
|
-
<% form_for
|
2
|
+
<% form_for [:admin, @asset], :html => {:multipart => true, 'data-onsubmit_status'=>'Uploading Asset…'} do |f| %>
|
3
3
|
<%= f.file_field :upload %>
|
4
4
|
<p class="buttons">
|
5
5
|
<%= f.submit 'Upload Asset', :class=>'button' %>
|
@@ -1,3 +1,5 @@
|
|
1
|
+
<% include_stylesheet 'admin/extensions/assets/assets' %>
|
2
|
+
|
1
3
|
<h1>Remove Asset</h1>
|
2
4
|
<p>
|
3
5
|
Are you sure you want to <strong class="warning">permanently remove</strong>
|
@@ -5,10 +7,10 @@
|
|
5
7
|
</p>
|
6
8
|
|
7
9
|
<table class="index" id="assets">
|
8
|
-
<tr><td class="name"><%=
|
10
|
+
<tr><td class="name"><%= asset_listing(@asset) %></td></tr>
|
9
11
|
</table>
|
10
12
|
|
11
|
-
<% form_for
|
13
|
+
<% form_for [:admin, @asset], :html => {:method => :delete, 'data-onsubmit_status'=>'Removing asset…'} do |f| %>
|
12
14
|
<p class="buttons">
|
13
15
|
<%= f.submit 'Delete asset', :class=>'button' %>
|
14
16
|
or <%= link_to 'Cancel', admin_assets_path %>
|
@@ -3,6 +3,41 @@
|
|
3
3
|
overflow: auto;
|
4
4
|
}
|
5
5
|
|
6
|
+
.pdf.frame {
|
7
|
+
width: 100%;
|
8
|
+
height: 30em;
|
9
|
+
}
|
10
|
+
|
11
|
+
.index th.size {
|
12
|
+
min-width: 5em;
|
13
|
+
}
|
14
|
+
|
15
|
+
table.index .size {
|
16
|
+
text-align: right;
|
17
|
+
padding-right: 5px;
|
18
|
+
}
|
19
|
+
|
20
|
+
#assets .icon {
|
21
|
+
display: block;
|
22
|
+
float: left;
|
23
|
+
text-align: center;
|
24
|
+
background: #ccc;
|
25
|
+
text-transform: uppercase;
|
26
|
+
}
|
27
|
+
|
28
|
+
table#assets .icon {
|
29
|
+
display: block;
|
30
|
+
float: left;
|
31
|
+
}
|
32
|
+
|
33
|
+
table#assets .icon, table#assets .thumbnail {
|
34
|
+
margin-right: 5px;
|
35
|
+
}
|
36
|
+
|
37
|
+
table#assets .icon {
|
38
|
+
font-size: 75%;
|
39
|
+
}
|
40
|
+
|
6
41
|
#assets, #assets li {
|
7
42
|
display: block;
|
8
43
|
list-style: none;
|
@@ -15,6 +50,12 @@
|
|
15
50
|
margin-right: 1px;
|
16
51
|
margin-bottom: 1px;
|
17
52
|
position: relative;
|
53
|
+
overflow: hidden;
|
54
|
+
}
|
55
|
+
|
56
|
+
#assets li a {
|
57
|
+
color: inherit;
|
58
|
+
text-decoration: none;
|
18
59
|
}
|
19
60
|
|
20
61
|
#assets li .id,
|
@@ -44,23 +85,31 @@
|
|
44
85
|
font-weight: bold;
|
45
86
|
}
|
46
87
|
|
88
|
+
#assets li .remove,
|
89
|
+
table#assets .remove::before {
|
90
|
+
background: url('/images/admin/minus.png') no-repeat top left;
|
91
|
+
}
|
92
|
+
|
47
93
|
#assets li .remove {
|
48
94
|
right: 2px;
|
49
|
-
background: url('/images/admin/minus.png') no-repeat top left;
|
50
95
|
width: 12px;
|
51
96
|
height: 12px;
|
52
97
|
text-indent: -1000em;
|
53
98
|
overflow: hidden;
|
54
99
|
}
|
55
100
|
|
101
|
+
table#assets .remove::before,
|
56
102
|
#actions .new a::before {
|
57
103
|
content: '';
|
58
104
|
width: 12px;
|
59
105
|
height: 12px;
|
60
106
|
padding-right: 3px;
|
61
|
-
position: relative;
|
107
|
+
position: relative;
|
62
108
|
top: 2px;
|
63
109
|
display: block;
|
64
110
|
display: inline-block;
|
111
|
+
}
|
112
|
+
|
113
|
+
#actions .new a::before {
|
65
114
|
background: url('/images/admin/plus.png') no-repeat left bottom;
|
66
115
|
}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-assets-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerrit Kaiser
|
@@ -66,8 +66,10 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- app/controllers/admin/assets_controller.rb
|
68
68
|
- app/helpers/assets_helper.rb
|
69
|
+
- app/models/asset.rb
|
69
70
|
- app/models/asset_tags.rb
|
70
|
-
- app/
|
71
|
+
- app/views/admin/assets/_grid.html.erb
|
72
|
+
- app/views/admin/assets/_list.html.erb
|
71
73
|
- app/views/admin/assets/edit.html.erb
|
72
74
|
- app/views/admin/assets/index.html.erb
|
73
75
|
- app/views/admin/assets/new.html.erb
|
@@ -79,6 +81,7 @@ files:
|
|
79
81
|
- cucumber.yml
|
80
82
|
- db/migrate/20110224001246_add_images_table.rb
|
81
83
|
- db/migrate/20110225021327_add_caption.rb
|
84
|
+
- db/migrate/20110225023017_rename_model_class.rb
|
82
85
|
- features/support/env.rb
|
83
86
|
- features/support/paths.rb
|
84
87
|
- lib/radiant-assets-extension.rb
|
@@ -93,7 +96,7 @@ has_rdoc: true
|
|
93
96
|
homepage: http://ext.radiantcms.org/extensions/269-assets
|
94
97
|
licenses: []
|
95
98
|
|
96
|
-
post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-assets-extension', :version => '0.0.
|
99
|
+
post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-assets-extension', :version => '0.0.4'\n "
|
97
100
|
rdoc_options: []
|
98
101
|
|
99
102
|
require_paths:
|
data/app/models/image.rb
DELETED