forked from OpenNeo/impress
carrierwave for asset swfs
This commit is contained in:
parent
5a5b5fffc7
commit
7c015e2d88
4 changed files with 40 additions and 6 deletions
|
@ -15,8 +15,14 @@ class SwfAsset < ActiveRecord::Base
|
|||
|
||||
set_inheritance_column 'inheritance_type'
|
||||
|
||||
IMAGE_SIZES = {
|
||||
:small => [150, 150],
|
||||
:medium => [300, 300],
|
||||
:large => [600, 600]
|
||||
}
|
||||
|
||||
include SwfConverter
|
||||
converts_swfs :size => [600, 600], :output_sizes => [[150, 150], [300, 300], [600, 600]]
|
||||
converts_swfs :size => IMAGE_SIZES[:large], :output_sizes => IMAGE_SIZES.values
|
||||
|
||||
def local_swf_path
|
||||
LOCAL_ASSET_DIR.join(local_path_within_outfit_swfs)
|
||||
|
@ -75,6 +81,21 @@ class SwfAsset < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def image_version
|
||||
converted_at.to_i
|
||||
end
|
||||
|
||||
def image_url(size=IMAGE_SIZES[:large])
|
||||
host = ASSET_HOSTS[:swf_asset_images]
|
||||
size_key = size.join('x')
|
||||
|
||||
"http://#{host}/#{s3_path}/#{size_key}.png?#{image_version}"
|
||||
end
|
||||
|
||||
def images
|
||||
IMAGE_SIZES.values.map { |size| {:size => size, :url => image_url(size)} }
|
||||
end
|
||||
|
||||
def convert_swf_if_not_converted!
|
||||
if needs_conversion?
|
||||
convert_swf!
|
||||
|
@ -161,7 +182,7 @@ class SwfAsset < ActiveRecord::Base
|
|||
:zones_restrict => zones_restrict,
|
||||
:is_body_specific => body_specific?,
|
||||
:has_image => has_image?,
|
||||
:s3_path => s3_path
|
||||
:images => images
|
||||
}
|
||||
if options[:for] == 'wardrobe'
|
||||
json[:local_path] = local_url
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
%ul#report-assets
|
||||
- @swf_assets.each do |swf_asset|
|
||||
%li
|
||||
= link_to image_tag(swf_asset.s3_url([150, 150])), swf_asset.url
|
||||
= link_to image_tag(swf_asset.image_url([150, 150])), swf_asset.url
|
||||
- unless swf_asset.image_pending_repair?
|
||||
= form_tag(:action => :create) do
|
||||
= hidden_field_tag 'swf_asset_remote_id', swf_asset.remote_id
|
||||
|
|
3
config/initializers/asset_hosts.rb
Normal file
3
config/initializers/asset_hosts.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
ASSET_HOSTS = {
|
||||
:swf_asset_images => 'd1i4vx4g4uxw7j.cloudfront.net'
|
||||
}
|
|
@ -79,8 +79,19 @@ function Wardrobe() {
|
|||
function Asset(newData) {
|
||||
var asset = this;
|
||||
|
||||
function size_key(size) {
|
||||
return size[0] + 'x' + size[1];
|
||||
}
|
||||
|
||||
this.image_urls_by_size_key = {};
|
||||
var image;
|
||||
for(var i = 0; i < newData.images.length; i++) {
|
||||
image = newData.images[i];
|
||||
this.image_urls_by_size_key[size_key(image.size)] = image.url;
|
||||
}
|
||||
|
||||
this.imageURL = function (size) {
|
||||
return Wardrobe.IMAGE_CONFIG.base_url + this.s3_path + "/" + size[0] + "x" + size[1] + ".png";
|
||||
return this.image_urls_by_size_key[size_key(size)];
|
||||
}
|
||||
|
||||
this.update = function (data) {
|
||||
|
@ -1376,10 +1387,9 @@ Wardrobe.getStandardView = function (options) {
|
|||
for(var i in sizes) {
|
||||
if(!sizes.hasOwnProperty(i)) continue;
|
||||
size = sizes[i];
|
||||
size[2] = size[0] * size[1];
|
||||
inserted = false;
|
||||
for(var i in SIZES_SMALL_TO_LARGE) {
|
||||
if(SIZES_SMALL_TO_LARGE[i][2] > size[2]) {
|
||||
if(SIZES_SMALL_TO_LARGE[i][0] * SIZES_SMALL_TO_LARGE[i][1] > size[0] * size[1]) {
|
||||
SIZES_SMALL_TO_LARGE.splice(i, 0, size);
|
||||
inserted = true;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue