fix assets upload with S3 in production + enhance a couple of things

This commit is contained in:
dinedine 2010-06-12 23:47:14 +02:00
parent 339d791e7d
commit 28211edad6
11 changed files with 25 additions and 38 deletions

View File

@ -1 +1 @@
0.0.2.3 0.0.2.4

View File

@ -41,7 +41,7 @@ class ThemeAsset
def plain_text def plain_text
@plain_text ||= (if self.stylesheet? || self.javascript? @plain_text ||= (if self.stylesheet? || self.javascript?
File.read(self.source.path) self.source.read
else else
nil nil
end) end)
@ -63,19 +63,10 @@ class ThemeAsset
self.source = CarrierWave::SanitizedFile.new({ self.source = CarrierWave::SanitizedFile.new({
:tempfile => StringIO.new(self.plain_text), :tempfile => StringIO.new(self.plain_text),
:filename => self.filename :filename => "#{self.slug}.#{self.stylesheet? ? 'css' : 'js'}"
}) })
end end
def filename
if not self.image?
# TODO: fix that for handling not image / stylesheets / javascripts assets
"#{self.slug}.#{self.stylesheet? ? 'css' : 'js'}"
else
"#{self.slug}#{File.extname(self.source.file.original_filename)}"
end
end
def to_liquid def to_liquid
{ :url => self.source.url }.merge(self.attributes) { :url => self.source.url }.merge(self.attributes)
end end

View File

@ -8,6 +8,10 @@ class AssetUploader < CarrierWave::Uploader::Base
"sites/#{model.collection.site_id}/assets/#{model.id}" "sites/#{model.collection.site_id}/assets/#{model.id}"
end end
def cache_dir
"#{Rails.root}/tmp/uploads"
end
version :thumb do version :thumb do
process :resize_to_fill => [50, 50] process :resize_to_fill => [50, 50]
process :convert => 'png' process :convert => 'png'

View File

@ -29,14 +29,4 @@ class ThemeAssetUploader < AssetUploader
%w(jpg jpeg gif png css js) %w(jpg jpeg gif png css js)
end end
def filename
if model.slug.present?
model.filename
else
extension = File.extname(original_filename)
basename = File.basename(original_filename, extension).slugify(:underscore => true)
"#{basename}#{extension}"
end
end
end end

View File

@ -10,7 +10,7 @@
- elsif field.text? - elsif field.text?
= f.input field._alias.to_sym, :label => field.label, :as => :text = f.input field._alias.to_sym, :label => field.label, :as => :text
- if @asset.image? - if @asset.image? && @asset.valid?
= f.foldable_inputs :name => "#{t('formtastic.titles.preview')} #{image_dimensions_and_size(@asset)}", :class => 'preview' do = f.foldable_inputs :name => "#{t('formtastic.titles.preview')} #{image_dimensions_and_size(@asset)}", :class => 'preview' do
%li %li
.image .image

View File

@ -7,7 +7,7 @@
%ul %ul
- current_site.pages.latest_updated.each do |page| - current_site.pages.latest_updated.each do |page|
%li %li
= link_to truncate(page.title, :length => 40), edit_admin_page_url(page) = link_to truncate(page.title, :length => 30), edit_admin_page_url(page)
%span= time_ago_in_words(page.updated_at) %span= time_ago_in_words(page.updated_at)
- current_site.content_types.each do |content_type| - current_site.content_types.each do |content_type|
@ -20,7 +20,7 @@
%ul %ul
- content_type.contents.latest_updated.each do |content| - content_type.contents.latest_updated.each do |content|
%li %li
= link_to truncate(content.send(content_type.highlighted_field_name), :length => 40), edit_admin_content_path(content_type.slug, content) = link_to truncate(content.send(content_type.highlighted_field_name), :length => 30), edit_admin_content_path(content_type.slug, content)
%span= time_ago_in_words(content.updated_at) %span= time_ago_in_words(content.updated_at)
.action .action

View File

@ -32,4 +32,3 @@ CarrierWave.configure do |config|
config.storage = :file config.storage = :file
config.root = File.join(Rails.root, 'public') config.root = File.join(Rails.root, 'public')
end end

View File

@ -2,9 +2,7 @@ BOARD:
- deploy on Heroku - deploy on Heroku
- observers to add / remove domains - observers to add / remove domains
- truncate nom dans le menu de contents - "field name" for alias / hint for custom fields
x comment console.log
- missing translation for the edit categories popup
BACKLOG: BACKLOG:
@ -16,7 +14,6 @@ BACKLOG:
- theme assets: disable version if not image - theme assets: disable version if not image
- migrate content_instance to its collection
- new custom field types - new custom field types
- file - file
- boolean - boolean
@ -126,3 +123,9 @@ x api security option in content types
x password resets (url is not handled correctly) x password resets (url is not handled correctly)
x mongoid hack for nested attributes x mongoid hack for nested attributes
x convert 2 plugins into gems (mongo_session_store / actionmailer_with_request) x convert 2 plugins into gems (mongo_session_store / actionmailer_with_request)
x comment console.log
x upload files in S3
x [BUG] asset vignette: name + icon not vertically aligned
x truncate nom dans le menu de contents
x site subdomain regexp [a-z][A-Z][0-9]
! migrate content_instance to its own collection => http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24sliceoperator

View File

@ -1,7 +1,7 @@
module Locomotive module Locomotive
module Regexps module Regexps
SUBDOMAIN = /^[a-z][a-z0-9_]*[a-z0-9]{1}$/ SUBDOMAIN = /^[a-z][a-z0-9]*[a-z0-9]{1}$/
DOMAIN = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix DOMAIN = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix

View File

@ -121,7 +121,7 @@ ul.assets li.asset h4 { margin: 0px; height: 30px; }
ul.assets li.asset h4 a { ul.assets li.asset h4 a {
position: relative; position: relative;
top: 0px; top: 6px;
left: 12px; left: 12px;
font-weight: bold; font-weight: bold;
font-size: 0.6em; font-size: 0.6em;
@ -149,7 +149,7 @@ ul.assets li.asset div.image div.inside {
ul.assets li.asset div.actions { ul.assets li.asset div.actions {
position: absolute; position: absolute;
top: 4px; top: 7px;
right: 12px; right: 12px;
} }

View File

@ -20,13 +20,13 @@ describe Site do
site.errors[:subdomain].should == ["can't be blank"] site.errors[:subdomain].should == ["can't be blank"]
end end
%w{test foo_bar test42}.each do |subdomain| %w{test test42}.each do |subdomain|
it "should accept subdomain like '#{subdomain}'" do it "should accept subdomain like '#{subdomain}'" do
Factory.build(:site, :subdomain => subdomain).should be_valid Factory.build(:site, :subdomain => subdomain).should be_valid
end end
end end
['-', '_test', 'test_', 't est', '42', '42test'].each do |subdomain| ['-', '_test', 'test_', 't est', '42', '42test', 'foo_bar'].each do |subdomain|
it "should not accept subdomain like '#{subdomain}'" do it "should not accept subdomain like '#{subdomain}'" do
(site = Factory.build(:site, :subdomain => subdomain)).should_not be_valid (site = Factory.build(:site, :subdomain => subdomain)).should_not be_valid
site.errors[:subdomain].should == ['is invalid'] site.errors[:subdomain].should == ['is invalid']