radiant-clipped-extension 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +230 -0
- data/Rakefile +109 -0
- data/app/controllers/admin/assets_controller.rb +60 -0
- data/app/controllers/admin/page_attachments_controller.rb +18 -0
- data/app/helpers/admin/assets_helper.rb +16 -0
- data/app/models/asset.rb +224 -0
- data/app/models/asset_tags.rb +384 -0
- data/app/models/asset_type.rb +170 -0
- data/app/models/old_page_attachment.rb +26 -0
- data/app/models/page_attachment.rb +21 -0
- data/app/views/admin/assets/_asset.html.haml +12 -0
- data/app/views/admin/assets/_asset_table.html.haml +30 -0
- data/app/views/admin/assets/_errors.html.haml +3 -0
- data/app/views/admin/assets/_form.html.haml +20 -0
- data/app/views/admin/assets/_page_assets.html.haml +12 -0
- data/app/views/admin/assets/_search.html.haml +17 -0
- data/app/views/admin/assets/_search_results.html.haml +17 -0
- data/app/views/admin/assets/edit.html.haml +40 -0
- data/app/views/admin/assets/index.html.haml +19 -0
- data/app/views/admin/assets/new.html.haml +24 -0
- data/app/views/admin/assets/refresh.html.haml +14 -0
- data/app/views/admin/assets/remove.html.haml +16 -0
- data/app/views/admin/configuration/_edit.html.haml +8 -0
- data/app/views/admin/configuration/_show.html.haml +12 -0
- data/app/views/admin/page_attachments/_attachment.html.haml +25 -0
- data/app/views/admin/page_parts/_page_part.html.haml +21 -0
- data/app/views/admin/pages/_asset_popups.html.haml +42 -0
- data/app/views/admin/pages/_assets.html.haml +11 -0
- data/app/views/admin/removed/_assets_bucket.html.haml +8 -0
- data/app/views/admin/removed/_assets_container.html.haml +58 -0
- data/app/views/admin/removed/_bucket.html.haml +11 -0
- data/app/views/admin/removed/_bucket_asset.html.haml +9 -0
- data/app/views/admin/removed/_show_bucket_link.html.haml +4 -0
- data/app/views/admin/removed/_upload_to_page.html.haml +12 -0
- data/app/views/admin/removed/bucket/_iframe.html.haml +1 -0
- data/artwork/icons.png +0 -0
- data/clipped_extension.rb +89 -0
- data/config/initializers/interpolation.rb +6 -0
- data/config/initializers/processors.rb +43 -0
- data/config/initializers/radiant_config.rb +34 -0
- data/config/locales/en.yml +108 -0
- data/config/locales/nl.yml +105 -0
- data/config/routes.rb +8 -0
- data/cucumber.yml +1 -0
- data/db/migrate/001_create_assets.rb +12 -0
- data/db/migrate/002_create_paperclip_attributes.rb +13 -0
- data/db/migrate/003_create_user_observer.rb +13 -0
- data/db/migrate/004_create_page_attachments.rb +19 -0
- data/db/migrate/005_rename_users.rb +13 -0
- data/db/migrate/20090316132151_disable_file_types.rb +20 -0
- data/db/migrate/20110513205050_asset_uuid.rb +11 -0
- data/db/migrate/20110606111250_update_configuration.rb +28 -0
- data/db/migrate/20110609101438_dimensions.rb +13 -0
- data/features/support/env.rb +11 -0
- data/features/support/paths.rb +22 -0
- data/lib/clipped_admin_ui.rb +32 -0
- data/lib/page_asset_associations.rb +13 -0
- data/lib/paperclip/frame_grab.rb +73 -0
- data/lib/paperclip/geometry_transformation.rb +79 -0
- data/lib/radiant-clipped-extension.rb +2 -0
- data/lib/radiant-clipped-extension/version.rb +3 -0
- data/lib/tasks/clipped_extension_tasks.rake +126 -0
- data/lib/tasks/paperclip_tasks.rake +79 -0
- data/public/flash/ZeroClipboard.swf +0 -0
- data/public/images/admin/assets/add.png +0 -0
- data/public/images/admin/assets/archive_icon.png +0 -0
- data/public/images/admin/assets/audio_icon.png +0 -0
- data/public/images/admin/assets/audio_thumbnail.png +0 -0
- data/public/images/admin/assets/c_icon.png +0 -0
- data/public/images/admin/assets/copy.png +0 -0
- data/public/images/admin/assets/css_icon.png +0 -0
- data/public/images/admin/assets/database_icon.png +0 -0
- data/public/images/admin/assets/delete.png +0 -0
- data/public/images/admin/assets/document_icon.png +0 -0
- data/public/images/admin/assets/document_thumbnail.png +0 -0
- data/public/images/admin/assets/flash_icon.png +0 -0
- data/public/images/admin/assets/flash_thumbnail.png +0 -0
- data/public/images/admin/assets/font_icon.png +0 -0
- data/public/images/admin/assets/gzip_icon.png +0 -0
- data/public/images/admin/assets/html_icon.png +0 -0
- data/public/images/admin/assets/image_icon.png +0 -0
- data/public/images/admin/assets/image_thumbnail.png +0 -0
- data/public/images/admin/assets/java_icon.png +0 -0
- data/public/images/admin/assets/page_edit.png +0 -0
- data/public/images/admin/assets/perl_icon.png +0 -0
- data/public/images/admin/assets/php_icon.png +0 -0
- data/public/images/admin/assets/presentation_icon.png +0 -0
- data/public/images/admin/assets/python_icon.png +0 -0
- data/public/images/admin/assets/reorder_assets.png +0 -0
- data/public/images/admin/assets/ruby_icon.png +0 -0
- data/public/images/admin/assets/script_icon.png +0 -0
- data/public/images/admin/assets/spreadsheet_icon.png +0 -0
- data/public/images/admin/assets/tar_icon.png +0 -0
- data/public/images/admin/assets/unknown_icon.png +0 -0
- data/public/images/admin/assets/unknown_thumbnail.png +0 -0
- data/public/images/admin/assets/video_icon.png +0 -0
- data/public/images/admin/assets/video_thumbnail.png +0 -0
- data/public/images/admin/assets/xml_icon.png +0 -0
- data/public/images/admin/assets/zip_icon.png +0 -0
- data/public/javascripts/admin/assets.js +296 -0
- data/public/stylesheets/sass/admin/assets.sass +209 -0
- data/radiant-clipped-extension.gemspec +33 -0
- data/spec/controllers/admin/assets_controller_spec.rb +50 -0
- data/spec/controllers/admin/page_attachments_controller_spec.rb +50 -0
- data/spec/datasets/assets_dataset.rb +35 -0
- data/spec/fixtures/test.flv +0 -0
- data/spec/lib/asset_tags_spec.rb +101 -0
- data/spec/lib/frame_grab_spec.rb +17 -0
- data/spec/lib/geometry_transformation_spec.rb +63 -0
- data/spec/models/asset_spec.rb +72 -0
- data/spec/models/asset_type_spec.rb +63 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +36 -0
- data/wireframes/edit-page-assets-2.bmml +453 -0
- data/wireframes/edit-page-assets-2.png +0 -0
- data/wireframes/edit-page-assets-3.bmml +454 -0
- data/wireframes/edit-page-assets-3.png +0 -0
- data/wireframes/edit-page-assets.bmml +433 -0
- data/wireframes/edit-page-assets.png +0 -0
- data/wireframes/edit-page.bmml +174 -0
- data/wireframes/edit-page.png +0 -0
- metadata +249 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "radiant-clipped-extension/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "radiant-clipped-extension"
|
7
|
+
s.version = RadiantClippedExtension::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Keith Bingman", "Benny Degezelle", "William Ross", "John W. Long"]
|
10
|
+
s.email = ["radiant@radiantcms.org"]
|
11
|
+
s.homepage = "http://radiantcms.org"
|
12
|
+
s.summary = %q{Assets for Radiant CMS}
|
13
|
+
s.description = %q{Assets extension on based Keith Bingman's excellent Paperclipped extension.}
|
14
|
+
|
15
|
+
ignores = if File.exist?('.gitignore')
|
16
|
+
File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
|
17
|
+
else
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
s.files = Dir['**/*'] - ignores
|
21
|
+
s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
|
22
|
+
# s.executables = Dir['bin/*'] - ignores
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
|
25
|
+
s.post_install_message = %{
|
26
|
+
Add this to your radiant project with:
|
27
|
+
config.gem 'radiant-clipped-extension', :version => '~>#{RadiantClippedExtension::VERSION}'
|
28
|
+
}
|
29
|
+
|
30
|
+
s.add_dependency 'acts_as_list', "~> 0.1.2"
|
31
|
+
s.add_dependency 'paperclip', "~> 2.3.11"
|
32
|
+
s.add_dependency 'uuidtools', "~> 2.1.2"
|
33
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::AssetsController do
|
4
|
+
dataset :users, :assets
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
ActionController::Routing::Routes.reload
|
8
|
+
login_as :designer
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be a ResourceController" do
|
12
|
+
controller.should be_kind_of(Admin::ResourceController)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should handle Assets" do
|
16
|
+
controller.class.model_class.should == Asset
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "index" do
|
20
|
+
describe "before filtration" do
|
21
|
+
before do
|
22
|
+
get :index
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should render the index view" do
|
26
|
+
response.should be_success
|
27
|
+
response.should render_template('index')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "on ajax filtration" do
|
32
|
+
before do
|
33
|
+
xml_http_request :get, :index, :filter => ['video']
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should render the table partial" do
|
37
|
+
response.body.should_not have_text('<head>')
|
38
|
+
response.content_type.should == 'text/javascript'
|
39
|
+
response.should_not render_template('index')
|
40
|
+
response.should render_template('admin/assets/_asset_table')
|
41
|
+
assigns(:assets).should include(assets(:video))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Admin::PageAttachmentsController do
|
4
|
+
dataset :users, :home_page, :assets
|
5
|
+
integrate_views
|
6
|
+
|
7
|
+
it "should be a ResourceController" do
|
8
|
+
controller.should be_kind_of(Admin::ResourceController)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should handle PageAttachments" do
|
12
|
+
controller.class.model_class.should == PageAttachment
|
13
|
+
controller.send(:model_symbol).should == :page_attachment
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "on call to new" do
|
17
|
+
before :each do
|
18
|
+
login_as :existing
|
19
|
+
@asset = assets(:video)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "with valid asset id" do
|
23
|
+
it "should return a nested form for asset-attachment" do
|
24
|
+
xhr :get, :new, :page_id => page_id(:home), :asset_id => @asset.id
|
25
|
+
response.should be_success
|
26
|
+
response.should render_template('admin/page_attachments/_attachment')
|
27
|
+
response.body.should =~ /attachment_#{@asset.uuid}/
|
28
|
+
response.body.should =~ /page_page_attachments_attributes_#{@asset.uuid}/
|
29
|
+
response.body.should =~ /<input class="attacher"/
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "without asset id" do
|
34
|
+
it "should respond blankly" do
|
35
|
+
get :new, :format => :js
|
36
|
+
response.should be_success
|
37
|
+
response.body.should be_blank
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "with invalid asset id" do
|
42
|
+
it "should respond blankly" do
|
43
|
+
get :new, :asset_id => 'foo', :format => :js
|
44
|
+
response.should be_success
|
45
|
+
response.body.should be_blank
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class AssetsDataset < Dataset::Base
|
2
|
+
uses :home_page
|
3
|
+
|
4
|
+
def load
|
5
|
+
create_page "pictured", :slug => 'pictured' do
|
6
|
+
create_asset "test1", :caption => "testing"
|
7
|
+
create_asset "test2", :caption => "also testing"
|
8
|
+
end
|
9
|
+
create_asset "video", :asset_content_type => 'video/mpeg', :asset_file_name => 'asset.mpg'
|
10
|
+
create_asset "audio", :asset_content_type => 'audio/mp3', :asset_file_name => 'asset.mp3'
|
11
|
+
create_asset "document", :asset_content_type => 'application/msword', :asset_file_name => 'asset.doc'
|
12
|
+
end
|
13
|
+
|
14
|
+
helpers do
|
15
|
+
def create_asset(name, attributes={})
|
16
|
+
attributes =
|
17
|
+
create_record :asset, name.symbolize, {
|
18
|
+
:title => name,
|
19
|
+
:asset_file_name => 'asset.jpg',
|
20
|
+
:asset_content_type => 'image/jpeg',
|
21
|
+
:asset_file_size => '46248',
|
22
|
+
:original_height => 200,
|
23
|
+
:original_width => 400,
|
24
|
+
:uuid => UUIDTools::UUID.timestamp_create.to_s
|
25
|
+
}.merge(attributes)
|
26
|
+
if @current_page_id
|
27
|
+
create_record :page_attachment, "#{name}_attachment".symbolize, {
|
28
|
+
:page_id => @current_page_id,
|
29
|
+
:asset_id => asset_id(name.symbolize)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
Binary file
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe AssetTags do
|
4
|
+
dataset :assets
|
5
|
+
let(:page) { pages(:pictured) }
|
6
|
+
let(:asset) { assets(:test2) }
|
7
|
+
|
8
|
+
context "Asset tags" do
|
9
|
+
%w{width height caption asset_file_name asset_content_type asset_file_size id filename image flash url link extension page:title page:url}.each do |name|
|
10
|
+
it "should have the new singular 'asset:#{name}' tag and method" do
|
11
|
+
page.tags.include?("asset:#{name}").should be_true
|
12
|
+
page.respond_to?("tag:asset:#{name}".to_sym).should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have the old plural 'assets:#{name}' tag and method" do
|
16
|
+
page.tags.include?("assets:#{name}").should be_true
|
17
|
+
page.respond_to?("tag:assets:#{name}".to_sym).should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should deprecate the old plural 'assets:#{name}' tag" do
|
21
|
+
ActiveSupport::Deprecation.should_receive(:warn).at_least(:once)
|
22
|
+
page.should render("<r:assets:first><r:assets:#{name} /></r:assets:first>")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "rendering tag" do
|
28
|
+
it "assets:each" do
|
29
|
+
page.should render('<r:assets:each><r:asset:id />,</r:assets:each>').as( "#{asset_id(:test2)},#{asset_id(:test1)}," )
|
30
|
+
end
|
31
|
+
|
32
|
+
it "assets:first" do
|
33
|
+
page.should render('<r:assets:first><r:asset:id /></r:assets:first>').as( "#{asset_id(:test2)}" )
|
34
|
+
end
|
35
|
+
|
36
|
+
it "assets:last" do
|
37
|
+
page.should render('<r:assets:last><r:asset:id /></r:assets:last>').as( "#{asset_id(:test1)}" )
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should retreive an asset by name" do
|
41
|
+
page.should render('<r:asset:id name="video" />').as( "#{asset_id(:video)}" )
|
42
|
+
end
|
43
|
+
|
44
|
+
it "asset:name" do
|
45
|
+
page.should render('<r:assets:first><r:asset:name /></r:assets:first>').as( asset.title )
|
46
|
+
end
|
47
|
+
|
48
|
+
it "asset:filename" do
|
49
|
+
page.should render('<r:assets:first><r:asset:filename /></r:assets:first>').as( asset.asset_file_name )
|
50
|
+
end
|
51
|
+
|
52
|
+
it "asset:url" do
|
53
|
+
page.should render('<r:assets:first><r:asset:url /></r:assets:first>').as( asset.thumbnail )
|
54
|
+
page.should render('<r:assets:first><r:asset:url size="icon" /></r:assets:first>').as( asset.thumbnail('icon') )
|
55
|
+
end
|
56
|
+
|
57
|
+
it "asset:link" do
|
58
|
+
page.should render('<r:assets:first><r:asset:link /></r:assets:first>').as( %{<a href="#{asset.thumbnail}">#{asset.title}</a>} )
|
59
|
+
page.should render('<r:assets:first><r:asset:link size="icon" /></r:assets:first>').as( %{<a href="#{asset.thumbnail('icon')}">#{asset.title}</a>} )
|
60
|
+
end
|
61
|
+
|
62
|
+
it "asset:image" do
|
63
|
+
page.should render('<r:assets:first><r:asset:image /></r:assets:first>').as( %{<img src="#{asset.thumbnail}" alt='#{asset.title}' />} )
|
64
|
+
page.should render('<r:assets:first><r:asset:image size="icon" /></r:assets:first>').as( %{<img src="#{asset.thumbnail('icon')}" alt='#{asset.title}' />} )
|
65
|
+
end
|
66
|
+
|
67
|
+
it "asset:caption" do
|
68
|
+
page.should render('<r:assets:first><r:asset:caption /></r:assets:first>').as( asset.caption )
|
69
|
+
end
|
70
|
+
|
71
|
+
it "asset:top_padding" do
|
72
|
+
page.should render('<r:assets:first><r:asset:top_padding container="500" /></r:assets:first>').as( "229" )
|
73
|
+
end
|
74
|
+
|
75
|
+
it "asset:top_padding for a specified style" do
|
76
|
+
page.should render('<r:assets:first><r:asset:top_padding container="500" size="thumbnail" /></r:assets:first>').as( "200" )
|
77
|
+
end
|
78
|
+
|
79
|
+
it "asset:width" do
|
80
|
+
page.should render('<r:assets:first><r:asset:width /></r:assets:first>').as( "400" )
|
81
|
+
page.should render('<r:assets:first><r:asset:width size="icon" /></r:assets:first>').as( "42" )
|
82
|
+
end
|
83
|
+
|
84
|
+
it "asset:height" do
|
85
|
+
page.should render('<r:assets:first><r:asset:height /></r:assets:first>').as( "200" )
|
86
|
+
page.should render('<r:assets:first><r:asset:height size="icon" /></r:assets:first>').as( "42" )
|
87
|
+
end
|
88
|
+
|
89
|
+
it "asset:orientation" do
|
90
|
+
page.should render('<r:assets:first><r:asset:orientation /></r:assets:first>').as( "horizontal" )
|
91
|
+
page.should render('<r:assets:first><r:asset:orientation size="icon" /></r:assets:first>').as( "square" )
|
92
|
+
end
|
93
|
+
|
94
|
+
it "asset:aspect" do
|
95
|
+
page.should render('<r:assets:first><r:asset:aspect /></r:assets:first>').as( 2.to_f.to_s )
|
96
|
+
page.should render('<r:assets:first><r:asset:aspect size="icon" /></r:assets:first>').as( 1.to_f.to_s )
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Paperclip::FrameGrab do
|
4
|
+
dataset :assets
|
5
|
+
let(:file) { File.new(File.join( File.dirname(__FILE__), "..", "fixtures", "test.flv")) }
|
6
|
+
let(:asset) { assets(:video) }
|
7
|
+
|
8
|
+
if Radiant.config['assets.create_video_thumbnails?']
|
9
|
+
context "processing video attachment" do
|
10
|
+
it "should create png icon and thumbnail"
|
11
|
+
it "should create jpeg file at configured size"
|
12
|
+
it "should squish if configured size is specific"
|
13
|
+
it "should preserve aspect ratio if configured size is >"
|
14
|
+
it "should resize then crop if configured size is #"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Paperclip::Geometry do
|
4
|
+
let(:original) { Paperclip::Geometry.new(1200,600) }
|
5
|
+
let(:small) { Paperclip::Geometry.new(100, 50) }
|
6
|
+
let(:scaled) {Paperclip::Geometry.new(300, 150) }
|
7
|
+
let(:incomplete) { Paperclip::Geometry.parse("300x") }
|
8
|
+
let(:simple) { Paperclip::Geometry.parse("300x200") }
|
9
|
+
let(:cropper) { Paperclip::Geometry.parse("300x200#") }
|
10
|
+
let(:if_bigger) { Paperclip::Geometry.parse("300x200>") }
|
11
|
+
let(:if_smaller) { Paperclip::Geometry.parse("300x200<") }
|
12
|
+
let(:percentage) { Paperclip::Geometry.parse("25%") }
|
13
|
+
let(:area) { Paperclip::Geometry.parse("180000@") }
|
14
|
+
|
15
|
+
context "=~" do
|
16
|
+
it "should compare sizes" do
|
17
|
+
(original =~ small).should be_false
|
18
|
+
(original =~ Paperclip::Geometry.new(1200,600)).should be_true
|
19
|
+
end
|
20
|
+
it "should ignore modifiers" do
|
21
|
+
(simple =~ cropper).should be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context "==" do
|
25
|
+
it "should compare sizes and modifiers" do
|
26
|
+
(original == Paperclip::Geometry.new(1200,600)).should be_true
|
27
|
+
(simple == cropper).should be_false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "stripping modifier" do
|
32
|
+
it "should return the same geometry with no modifier" do
|
33
|
+
cropper.without_modifier.should == simple
|
34
|
+
if_bigger.without_modifier.should == simple
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "calculating thumbnail dimensions" do
|
39
|
+
it "should raise an exception if called on a partial geometry" do
|
40
|
+
lambda{incomplete * simple}.should raise_error(Paperclip::TransformationError)
|
41
|
+
end
|
42
|
+
it "should not raise an exception if called on a complete geometry" do
|
43
|
+
lambda{original * simple}.should_not raise_error
|
44
|
+
end
|
45
|
+
it "should calculate the result of applying another geometry" do
|
46
|
+
(original * simple).should == scaled
|
47
|
+
(original * cropper).should == cropper.without_modifier
|
48
|
+
(original * if_bigger).should == scaled
|
49
|
+
(original * if_smaller).should == original
|
50
|
+
(small * if_smaller).should == scaled
|
51
|
+
(small * cropper).should == cropper.without_modifier
|
52
|
+
(original * percentage).should == scaled
|
53
|
+
(original * area).should == scaled
|
54
|
+
end
|
55
|
+
it "should cope with a partial-geometry argument" do
|
56
|
+
(original * incomplete).should == scaled
|
57
|
+
end
|
58
|
+
it "should instantiate a non-geometry argument" do
|
59
|
+
(original * "300x200").should == scaled
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Asset do
|
4
|
+
|
5
|
+
def default_attributes
|
6
|
+
{
|
7
|
+
:asset_file_name => 'asset.jpg',
|
8
|
+
:asset_content_type => 'image/jpeg',
|
9
|
+
:asset_file_size => '46248'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
def new_asset(overrides={})
|
13
|
+
Asset.new default_attributes.merge(overrides)
|
14
|
+
end
|
15
|
+
def create_asset(overrides={})
|
16
|
+
Asset.create! default_attributes.merge(overrides)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should be valid when instantiated' do
|
20
|
+
new_asset.should be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be valid when saved' do
|
24
|
+
create_asset.should be_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#thumbnail' do
|
28
|
+
describe 'without argument' do
|
29
|
+
it 'should return paperclip asset url for image' do
|
30
|
+
image = new_asset :asset_content_type => 'image/jpeg'
|
31
|
+
image.stub! :asset => mock('asset', :url => '/y/z/e.jpg')
|
32
|
+
image.thumbnail.should == '/y/z/e.jpg'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return paperclip asset url for non-image' do
|
36
|
+
asset = new_asset :asset_content_type => 'application/pdf'
|
37
|
+
asset.stub! :asset => mock('asset', :url => '/y/z/e.pdf')
|
38
|
+
asset.thumbnail.should == '/y/z/e.pdf'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'with size=original' do
|
43
|
+
it 'should return paperclip asset url for image' do
|
44
|
+
image = new_asset :asset_content_type => 'image/jpeg'
|
45
|
+
image.stub! :asset => mock('asset', :url => '/y/z/e.jpg')
|
46
|
+
image.thumbnail('original').should == '/y/z/e.jpg'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return paperclip asset url for non-image' do
|
50
|
+
asset = new_asset :asset_content_type => 'application/pdf'
|
51
|
+
asset.stub! :asset => mock('asset', :url => '/y/z/e.pdf')
|
52
|
+
asset.thumbnail('original').should == '/y/z/e.pdf'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should return resized image for images when given size' do
|
57
|
+
image = new_asset :asset_content_type => 'image/jpeg'
|
58
|
+
image.stub! :asset => mock('asset')
|
59
|
+
image.stub! :has_style? => true
|
60
|
+
image.asset.stub!(:content_type).and_return('image/jpeg')
|
61
|
+
image.asset.stub!(:url).with(:thumbnail).and_return('/re/sized/image_thumbnail.jpg')
|
62
|
+
image.thumbnail('thumbnail').should == '/re/sized/image_thumbnail.jpg'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return icon for non-image with a given size' do
|
66
|
+
document = new_asset :asset_content_type => 'application/msword'
|
67
|
+
document.thumbnail('icon').should == "/images/admin/assets/document_icon.png"
|
68
|
+
document.thumbnail('anything_but_icon').should == "/images/admin/assets/document_icon.png"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
class Dummy < Processor
|
5
|
+
def initialize file, options = {}, attachment = nil
|
6
|
+
super
|
7
|
+
something = options[:something]
|
8
|
+
end
|
9
|
+
def make
|
10
|
+
@file
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
AssetType.new :simple, :mime_types => %w[test/this test/that]
|
16
|
+
AssetType.new :complex, :processors => [:dummy], :styles => {:something => "99x99>"}, :mime_types => %w[test/complex], :icon => 'document'
|
17
|
+
AssetType.new :configured, :processors => [:dummy], :mime_types => %w[test/configured]
|
18
|
+
|
19
|
+
describe AssetType do
|
20
|
+
|
21
|
+
context 'without thumbnails' do
|
22
|
+
subject{ AssetType.find(:simple) }
|
23
|
+
its(:plural) { should == "simples" }
|
24
|
+
its(:mime_types) { should == ["test/this", "test/that"] }
|
25
|
+
its(:condition) { should == ["asset_content_type IN (?,?)", "test/this", "test/that"] }
|
26
|
+
its(:non_condition) { should == ["NOT asset_content_type IN (?,?)", "test/this", "test/that"] }
|
27
|
+
its(:paperclip_processors) { should be_empty}
|
28
|
+
its(:paperclip_styles) { should be_empty}
|
29
|
+
its(:icon) { should == "/images/admin/assets/simple_icon.png"}
|
30
|
+
its(:icon_path) { should == "#{RAILS_ROOT}/public/images/admin/assets/simple_icon.png"}
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with initialized thumbnail sizes' do
|
34
|
+
before { Radiant.config["assets.create_complex_thumbnails?"] = true }
|
35
|
+
subject{ AssetType.find(:complex) }
|
36
|
+
its(:paperclip_processors) { should == [:dummy] }
|
37
|
+
its(:paperclip_styles) { should_not be_empty }
|
38
|
+
its(:paperclip_styles) { should == {:something => "99x99>"} }
|
39
|
+
its(:icon) { should == "/images/admin/assets/document_icon.png"}
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with configured thumbnail sizes' do
|
43
|
+
before {
|
44
|
+
Radiant.config["assets.create_configured_thumbnails?"] = true
|
45
|
+
Radiant.config["assets.thumbnails.configured"] = "special:size=800x800>,format=jpg|tiny:size=#10x10,format=png"
|
46
|
+
}
|
47
|
+
subject{ AssetType.find(:configured) }
|
48
|
+
its(:paperclip_processors) { should == [:dummy] }
|
49
|
+
its(:paperclip_styles) { should == {:special => ["800x800>", :jpg], :tiny => ["#10x10", :png]} }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'AssetType class methods' do
|
53
|
+
describe '.slice' do
|
54
|
+
AssetType.slice('simple', 'complex').should =~ [AssetType.find(:simple), AssetType.find(:complex)]
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.from' do
|
58
|
+
AssetType.from('test/this').should == AssetType.find(:simple)
|
59
|
+
AssetType.from('test/complex').should == AssetType.find(:complex)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|