radiant-clipped-extension 1.0.9 → 1.0.10
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/app/models/asset.rb +29 -21
- data/app/models/asset_type.rb +13 -1
- data/lib/asset_tags.rb +20 -36
- data/lib/paperclip/geometry_transformation.rb +7 -6
- data/lib/radiant-clipped-extension.rb +1 -1
- data/public/javascripts/admin/assets.js +1 -0
- data/public/stylesheets/sass/admin/assets.sass +7 -5
- data/spec/lib/asset_tags_spec.rb +7 -2
- metadata +4 -4
data/app/models/asset.rb
CHANGED
@@ -71,8 +71,8 @@ class Asset < ActiveRecord::Base
|
|
71
71
|
return asset_type.icon(style_name)
|
72
72
|
end
|
73
73
|
|
74
|
-
def has_style?(style_name)
|
75
|
-
paperclip_styles.keys.include?(style_name.to_sym)
|
74
|
+
def has_style?(style_name='original')
|
75
|
+
style_name == 'original' || paperclip_styles.keys.include?(style_name.to_sym)
|
76
76
|
end
|
77
77
|
|
78
78
|
def basename
|
@@ -102,49 +102,57 @@ class Asset < ActiveRecord::Base
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def geometry(style_name='original')
|
105
|
+
raise Paperclip::StyleError, "Requested style #{style_name} is not defined for this asset." unless has_style?(style_name)
|
105
106
|
@geometry ||= {}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
begin
|
108
|
+
@geometry[style_name] ||= if style_name.to_s == 'original'
|
109
|
+
original_geometry
|
110
|
+
else
|
111
|
+
style = self.asset.styles[style_name.to_sym]
|
112
|
+
original_geometry.transformed_by(style.geometry) # this can return dimensions for fully specified style sizes but not for relative sizes when there are no original dimensions
|
113
|
+
end
|
114
|
+
rescue Paperclip::TransformationError => e
|
115
|
+
Rails.logger.warn "geometry transformation error: #{e}"
|
116
|
+
original_geometry # returns a blank geometry if the real geometry cannot be calculated
|
112
117
|
end
|
113
118
|
end
|
114
119
|
|
115
120
|
def aspect(style_name='original')
|
116
|
-
|
121
|
+
geometry(style_name).aspect
|
117
122
|
end
|
118
123
|
|
119
124
|
def orientation(style_name='original')
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
125
|
+
a = aspect(style_name)
|
126
|
+
case
|
127
|
+
when a == nil?
|
128
|
+
'unknown'
|
129
|
+
when a < 1.0
|
130
|
+
'vertical'
|
131
|
+
when a > 1.0
|
132
|
+
'horizontal'
|
133
|
+
else
|
134
|
+
'square'
|
127
135
|
end
|
128
136
|
end
|
129
137
|
|
130
138
|
def width(style_name='original')
|
131
|
-
|
139
|
+
geometry(style_name).width.to_i
|
132
140
|
end
|
133
141
|
|
134
142
|
def height(style_name='original')
|
135
|
-
|
143
|
+
geometry(style_name).height.to_i
|
136
144
|
end
|
137
145
|
|
138
146
|
def square?(style_name='original')
|
139
|
-
|
147
|
+
geometry(style_name).square?
|
140
148
|
end
|
141
149
|
|
142
150
|
def vertical?(style_name='original')
|
143
|
-
|
151
|
+
geometry(style_name).vertical?
|
144
152
|
end
|
145
153
|
|
146
154
|
def horizontal?(style_name='original')
|
147
|
-
|
155
|
+
geometry(style_name).horizontal?
|
148
156
|
end
|
149
157
|
|
150
158
|
def dimensions_known?
|
data/app/models/asset_type.rb
CHANGED
@@ -37,7 +37,7 @@ class AssetType
|
|
37
37
|
Asset.send :named_scope, plural.to_sym, :conditions => condition
|
38
38
|
Asset.send :named_scope, "not_#{plural}".to_sym, :conditions => non_condition
|
39
39
|
|
40
|
-
|
40
|
+
self.define_radius_tags
|
41
41
|
@@types.push self
|
42
42
|
@@type_lookup[@name] = self
|
43
43
|
end
|
@@ -164,6 +164,18 @@ class AssetType
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
+
def define_radius_tags
|
168
|
+
type = self.name
|
169
|
+
Page.class_eval {
|
170
|
+
tag "asset:if_#{type}" do |tag|
|
171
|
+
tag.expand if find_asset(tag, tag.attr.dup).send("#{type}?".to_sym)
|
172
|
+
end
|
173
|
+
tag "asset:unless_#{type}" do |tag|
|
174
|
+
tag.expand unless find_asset(tag, tag.attr.dup).send("#{type}?".to_sym)
|
175
|
+
end
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
167
179
|
# class methods
|
168
180
|
|
169
181
|
def self.for(attachment)
|
data/lib/asset_tags.rb
CHANGED
@@ -7,11 +7,6 @@ module AssetTags
|
|
7
7
|
deprecated_tag "assets:#{name}", :substitute => "asset:#{name}", :deadline => '2.0'
|
8
8
|
end
|
9
9
|
|
10
|
-
Asset.known_types.each do |known_type|
|
11
|
-
deprecated_tag "assets:if_#{known_type}", :substitute => "asset:if_#{known_type}", :deadline => '2.0'
|
12
|
-
deprecated_tag "assets:unless_#{known_type}", :substitute => "asset:unless_#{known_type}", :deadline => '2.0'
|
13
|
-
end
|
14
|
-
|
15
10
|
desc %{
|
16
11
|
The namespace for referencing images and assets.
|
17
12
|
|
@@ -20,7 +15,12 @@ module AssetTags
|
|
20
15
|
}
|
21
16
|
tag 'asset' do |tag|
|
22
17
|
tag.locals.asset = find_asset unless tag.attr.empty?
|
23
|
-
|
18
|
+
begin
|
19
|
+
tag.expand
|
20
|
+
rescue Paperclip::StyleError => e
|
21
|
+
Rails.logger.warn "style processing error with asset ##{tag.locals.asset.id}: #{e}"
|
22
|
+
raise TagError, e
|
23
|
+
end
|
24
24
|
end
|
25
25
|
|
26
26
|
desc %{
|
@@ -111,7 +111,7 @@ module AssetTags
|
|
111
111
|
|
112
112
|
|
113
113
|
desc %{
|
114
|
-
Renders the value for a top padding for
|
114
|
+
Renders the value for a top padding for a thumbnail. Put the thumbnail in a
|
115
115
|
container with specified height and using this tag you can vertically
|
116
116
|
align the image within its container.
|
117
117
|
|
@@ -132,9 +132,9 @@ module AssetTags
|
|
132
132
|
}
|
133
133
|
tag 'asset:top_padding' do |tag|
|
134
134
|
asset, options = asset_and_options(tag)
|
135
|
-
raise TagError, 'Asset is not an image' unless asset.image?
|
136
135
|
raise TagError, "'container' attribute required" unless options['container']
|
137
136
|
size = options['size'] ? options.delete('size') : 'icon'
|
137
|
+
raise TagError, "asset #{tag.locals.asset.title} has no '#{size}' thumbnail" unless tag.locals.asset.has_style?(size)
|
138
138
|
container = options.delete('container')
|
139
139
|
((container.to_i - asset.height(size).to_i)/2).to_s
|
140
140
|
end
|
@@ -154,12 +154,14 @@ module AssetTags
|
|
154
154
|
end
|
155
155
|
|
156
156
|
desc %{
|
157
|
-
Returns a string representing the orientation of the asset, which must be
|
157
|
+
Returns a string representing the orientation of the asset, which must be imageable.
|
158
|
+
(ie, it is an image or it has been processed to produce an image).
|
159
|
+
Can be 'horizontal', 'vertical' or 'square'.
|
158
160
|
}
|
159
161
|
tag 'asset:orientation' do |tag|
|
160
162
|
asset, options = asset_and_options(tag)
|
161
|
-
raise TagError, 'Asset is not an image' unless asset.image?
|
162
163
|
size = options['size'] ? options.delete('size') : 'original'
|
164
|
+
raise TagError, "asset #{tag.locals.asset.title} has no '#{size}' thumbnail" unless tag.locals.asset.has_style?(size)
|
163
165
|
asset.orientation(size)
|
164
166
|
end
|
165
167
|
|
@@ -168,8 +170,8 @@ module AssetTags
|
|
168
170
|
}
|
169
171
|
tag 'asset:aspect' do |tag|
|
170
172
|
asset, options = asset_and_options(tag)
|
171
|
-
raise TagError, 'Asset is not an image' unless asset.image?
|
172
173
|
size = options['size'] ? options.delete('size') : 'original'
|
174
|
+
raise TagError, "asset #{tag.locals.asset.title} has no '#{size}' thumbnail" unless tag.locals.asset.has_style?(size)
|
173
175
|
asset.aspect(size)
|
174
176
|
end
|
175
177
|
|
@@ -193,21 +195,6 @@ module AssetTags
|
|
193
195
|
end
|
194
196
|
|
195
197
|
#TODO: could use better docs for Asset#other? case explaining what types it covers
|
196
|
-
Asset.known_types.each do |known_type|
|
197
|
-
desc %{
|
198
|
-
Renders the contents only of the asset is of the type #{known_type}
|
199
|
-
}
|
200
|
-
tag "asset:if_#{known_type}" do |tag|
|
201
|
-
tag.expand if find_asset(tag, tag.attr.dup).send("#{known_type}?".to_sym)
|
202
|
-
end
|
203
|
-
|
204
|
-
desc %{
|
205
|
-
Renders the contents only of the asset is not of the type #{known_type}
|
206
|
-
}
|
207
|
-
tag "asset:unless_#{known_type}" do |tag|
|
208
|
-
tag.expand unless find_asset(tag, tag.attr.dup).send("#{known_type}?".to_sym)
|
209
|
-
end
|
210
|
-
end
|
211
198
|
|
212
199
|
[:title, :caption, :asset_file_name, :extension, :asset_content_type, :asset_file_size, :id].each do |method|
|
213
200
|
desc %{
|
@@ -233,22 +220,19 @@ module AssetTags
|
|
233
220
|
|
234
221
|
Using the optional @size@ attribute, different sizes can be display.
|
235
222
|
"thumbnail" and "icon" sizes are built in, but custom ones can be set
|
236
|
-
|
237
|
-
settings.
|
223
|
+
by changing `assets.thumbnails.[type]` in the Radiant::Config settings.
|
238
224
|
|
239
225
|
*Usage:*
|
240
226
|
<pre><code><r:asset:image [name="asset name" or id="asset id"] [size="icon|thumbnail|whatever"]></code></pre>
|
241
227
|
}
|
242
228
|
tag 'asset:image' do |tag|
|
243
229
|
tag.locals.asset, options = asset_and_options(tag)
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
%{<img src="#{url}" #{attributes unless attributes.empty?} />} rescue nil
|
251
|
-
end
|
230
|
+
size = options.delete('size') || 'original'
|
231
|
+
raise TagError, "asset #{tag.locals.asset.title} has no '#{size}' thumbnail" unless tag.locals.asset.has_style?(size)
|
232
|
+
options['alt'] ||= tag.locals.asset.title
|
233
|
+
attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
|
234
|
+
url = tag.locals.asset.thumbnail(size)
|
235
|
+
%{<img src="#{url}" #{attributes} />} rescue nil
|
252
236
|
end
|
253
237
|
|
254
238
|
desc %{
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Paperclip
|
2
2
|
|
3
|
-
class TransformationError < PaperclipError
|
4
|
-
end
|
3
|
+
class TransformationError < PaperclipError; end
|
4
|
+
class StyleError < PaperclipError; end
|
5
5
|
|
6
6
|
class Geometry
|
7
7
|
|
@@ -17,13 +17,14 @@ module Paperclip
|
|
17
17
|
# This saves us having to go back to the file, which is expensive with S3.
|
18
18
|
# We understand all the Imagemagick geometry arguments described at http://www.imagemagick.org/script/command-line-processing.php#geometry
|
19
19
|
# including both '^' and paperclip's own '#' modifier.
|
20
|
+
#
|
20
21
|
def transformed_by (other)
|
21
|
-
raise TransformationError, "geometry is not transformable without both width and height" if self.height == 0 or self.width == 0
|
22
22
|
other = Geometry.parse(other) unless other.is_a? Geometry
|
23
|
-
|
23
|
+
# if the two geometries are similar, or the destination geometry is a fixed size, the resulting dimensions are fixed
|
24
|
+
return other.without_modifier if self =~ other || ['#', '!', '^'].include?(other.modifier)
|
25
|
+
# otherwise, we apply the transformation
|
26
|
+
raise TransformationError, "geometry is not transformable without both width and height" if self.height == 0 or self.width == 0
|
24
27
|
case other.modifier
|
25
|
-
when '#', '!', '^'
|
26
|
-
other.without_modifier
|
27
28
|
when '>'
|
28
29
|
(other.width < self.width || other.height < self.height) ? scaled_to_fit(other) : self
|
29
30
|
when '<'
|
@@ -90,6 +90,7 @@ Asset.Insert = Behavior.create({
|
|
90
90
|
onclick: function(e) {
|
91
91
|
if (e) e.stop();
|
92
92
|
var part_name = TabControlBehavior.instances[0].controller.selected.caption;
|
93
|
+
if (part_name.indexOf(' ')) part_name = part_name.replace(' ', '-');
|
93
94
|
var textbox = $('part_' + part_name + '_content');
|
94
95
|
var tag_parts = this.element.getAttribute('rel').split('_');
|
95
96
|
var tag_name = tag_parts[0];
|
@@ -54,6 +54,10 @@ p.asset
|
|
54
54
|
width: 180px
|
55
55
|
padding: 2px 8px 2px 20px
|
56
56
|
|
57
|
+
#assets_table.assets
|
58
|
+
overflow: auto
|
59
|
+
|
60
|
+
|
57
61
|
#upload_holders
|
58
62
|
display: none
|
59
63
|
|
@@ -174,15 +178,13 @@ p.asset
|
|
174
178
|
|
175
179
|
#assets_table.assets
|
176
180
|
position: relative
|
177
|
-
|
181
|
+
font-size: 75%
|
178
182
|
p
|
179
183
|
padding: 40px
|
180
184
|
top: 45px
|
181
185
|
color: silver
|
182
186
|
text-align: center
|
183
|
-
font:
|
184
|
-
size: 75%
|
185
|
-
style: oblique
|
187
|
+
font-style: oblique
|
186
188
|
ul
|
187
189
|
clear: both
|
188
190
|
li.asset
|
@@ -194,7 +196,7 @@ p.asset
|
|
194
196
|
clear: left
|
195
197
|
width: 100%
|
196
198
|
height: 3em
|
197
|
-
padding: 0.5em
|
199
|
+
padding: 0.5em 0
|
198
200
|
span, a
|
199
201
|
display: block
|
200
202
|
float: left
|
data/spec/lib/asset_tags_spec.rb
CHANGED
@@ -61,8 +61,8 @@ describe AssetTags do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it "asset:image" do
|
64
|
-
page.should render(%{<r:asset:image id="#{asset_id(:test1)}" />}).as( %{<img src="#{asset.thumbnail}" alt=
|
65
|
-
page.should render(%{<r:asset:image size="icon" id="#{asset_id(:test1)}" />}).as( %{<img src="#{asset.thumbnail('icon')}" alt=
|
64
|
+
page.should render(%{<r:asset:image id="#{asset_id(:test1)}" />}).as( %{<img src="#{asset.thumbnail}" alt="#{asset.title}" />} )
|
65
|
+
page.should render(%{<r:asset:image size="icon" id="#{asset_id(:test1)}" />}).as( %{<img src="#{asset.thumbnail('icon')}" alt="#{asset.title}" />} )
|
66
66
|
end
|
67
67
|
|
68
68
|
it "asset:caption" do
|
@@ -96,6 +96,11 @@ describe AssetTags do
|
|
96
96
|
page.should render(%{<r:asset:aspect id="#{asset_id(:test1)}" />}).as( 2.to_f.to_s )
|
97
97
|
page.should render(%{<r:asset:aspect id="#{asset_id(:test1)}" size="icon" />}).as( 1.to_f.to_s )
|
98
98
|
end
|
99
|
+
|
100
|
+
it "asset:if_image" do
|
101
|
+
page.should render(%{<r:asset:if_image name="test1">foo</r:asset:if_image>}).as( "foo" )
|
102
|
+
page.should render(%{<r:asset:if_image name="video">foo</r:asset:if_image>}).as( "" )
|
103
|
+
end
|
99
104
|
|
100
105
|
end
|
101
106
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-clipped-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 10
|
10
|
+
version: 1.0.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Keith Bingman
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-09-
|
21
|
+
date: 2011-09-13 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: acts_as_list
|