From 28211edad67b99b064a51d5fb3ae6acc2ad66387 Mon Sep 17 00:00:00 2001 From: dinedine Date: Sat, 12 Jun 2010 23:47:14 +0200 Subject: [PATCH] fix assets upload with S3 in production + enhance a couple of things --- VERSION | 2 +- app/models/theme_asset.rb | 13 ++----------- app/uploaders/asset_uploader.rb | 4 ++++ app/uploaders/theme_asset_uploader.rb | 10 ---------- app/views/admin/assets/_form.html.haml | 2 +- app/views/admin/shared/menu/_contents.html.haml | 4 ++-- config/environments/development.rb | 3 +-- doc/TODO | 15 +++++++++------ lib/locomotive/regexps.rb | 2 +- public/stylesheets/admin/application.css | 4 ++-- spec/models/site_spec.rb | 4 ++-- 11 files changed, 25 insertions(+), 38 deletions(-) diff --git a/VERSION b/VERSION index 62cd6db1..dd930e59 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.2.3 \ No newline at end of file +0.0.2.4 \ No newline at end of file diff --git a/app/models/theme_asset.rb b/app/models/theme_asset.rb index c29aa08f..256a1362 100644 --- a/app/models/theme_asset.rb +++ b/app/models/theme_asset.rb @@ -41,7 +41,7 @@ class ThemeAsset def plain_text @plain_text ||= (if self.stylesheet? || self.javascript? - File.read(self.source.path) + self.source.read else nil end) @@ -63,19 +63,10 @@ class ThemeAsset self.source = CarrierWave::SanitizedFile.new({ :tempfile => StringIO.new(self.plain_text), - :filename => self.filename + :filename => "#{self.slug}.#{self.stylesheet? ? 'css' : 'js'}" }) 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 { :url => self.source.url }.merge(self.attributes) end diff --git a/app/uploaders/asset_uploader.rb b/app/uploaders/asset_uploader.rb index 21250395..130709c6 100644 --- a/app/uploaders/asset_uploader.rb +++ b/app/uploaders/asset_uploader.rb @@ -8,6 +8,10 @@ class AssetUploader < CarrierWave::Uploader::Base "sites/#{model.collection.site_id}/assets/#{model.id}" end + def cache_dir + "#{Rails.root}/tmp/uploads" + end + version :thumb do process :resize_to_fill => [50, 50] process :convert => 'png' diff --git a/app/uploaders/theme_asset_uploader.rb b/app/uploaders/theme_asset_uploader.rb index 0dea8eb8..0ef39062 100644 --- a/app/uploaders/theme_asset_uploader.rb +++ b/app/uploaders/theme_asset_uploader.rb @@ -29,14 +29,4 @@ class ThemeAssetUploader < AssetUploader %w(jpg jpeg gif png css js) 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 \ No newline at end of file diff --git a/app/views/admin/assets/_form.html.haml b/app/views/admin/assets/_form.html.haml index 122adfff..d50673f2 100644 --- a/app/views/admin/assets/_form.html.haml +++ b/app/views/admin/assets/_form.html.haml @@ -10,7 +10,7 @@ - elsif field.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 %li .image diff --git a/app/views/admin/shared/menu/_contents.html.haml b/app/views/admin/shared/menu/_contents.html.haml index 5838660c..3fe2ee7f 100644 --- a/app/views/admin/shared/menu/_contents.html.haml +++ b/app/views/admin/shared/menu/_contents.html.haml @@ -7,7 +7,7 @@ %ul - current_site.pages.latest_updated.each do |page| %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) - current_site.content_types.each do |content_type| @@ -20,7 +20,7 @@ %ul - content_type.contents.latest_updated.each do |content| %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) .action diff --git a/config/environments/development.rb b/config/environments/development.rb index 3da6a274..e37aa7c5 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -31,5 +31,4 @@ end CarrierWave.configure do |config| config.storage = :file config.root = File.join(Rails.root, 'public') -end - +end \ No newline at end of file diff --git a/doc/TODO b/doc/TODO index 059a8acd..7e14caae 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,10 +1,8 @@ BOARD: - deploy on Heroku - - observers to add / remove domains -- truncate nom dans le menu de contents -x comment console.log -- missing translation for the edit categories popup + - observers to add / remove domains +- "field name" for alias / hint for custom fields BACKLOG: @@ -16,7 +14,6 @@ BACKLOG: - theme assets: disable version if not image -- migrate content_instance to its collection - new custom field types - file - boolean @@ -125,4 +122,10 @@ x missing translation in english x api security option in content types x password resets (url is not handled correctly) x mongoid hack for nested attributes -x convert 2 plugins into gems (mongo_session_store / actionmailer_with_request) \ No newline at end of file +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 \ No newline at end of file diff --git a/lib/locomotive/regexps.rb b/lib/locomotive/regexps.rb index 96dc5564..0dd3ebfe 100644 --- a/lib/locomotive/regexps.rb +++ b/lib/locomotive/regexps.rb @@ -1,7 +1,7 @@ module Locomotive 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 diff --git a/public/stylesheets/admin/application.css b/public/stylesheets/admin/application.css index ab074eec..c209ba7f 100644 --- a/public/stylesheets/admin/application.css +++ b/public/stylesheets/admin/application.css @@ -121,7 +121,7 @@ ul.assets li.asset h4 { margin: 0px; height: 30px; } ul.assets li.asset h4 a { position: relative; - top: 0px; + top: 6px; left: 12px; font-weight: bold; font-size: 0.6em; @@ -149,7 +149,7 @@ ul.assets li.asset div.image div.inside { ul.assets li.asset div.actions { position: absolute; - top: 4px; + top: 7px; right: 12px; } diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index a6893d64..ba06fa7f 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -20,13 +20,13 @@ describe Site do site.errors[:subdomain].should == ["can't be blank"] end - %w{test foo_bar test42}.each do |subdomain| + %w{test test42}.each do |subdomain| it "should accept subdomain like '#{subdomain}'" do Factory.build(:site, :subdomain => subdomain).should be_valid 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 (site = Factory.build(:site, :subdomain => subdomain)).should_not be_valid site.errors[:subdomain].should == ['is invalid']