fix validation for photo title if russian locale

master
Alexander Negoda 2012-07-21 00:50:30 +04:00
parent aedc18f834
commit d996de1514
7 changed files with 152 additions and 118 deletions

View File

@ -8,6 +8,7 @@ gem 'mime-types', :require => 'mime/types'
gem 'carrierwave', '0.6.2'
gem 'dynamic_form'
gem 'princely'
gem 'russian', :git => 'git://github.com/yaroslav/russian.git'
# -- Heroku
#gem 'heroku'

View File

@ -1,3 +1,10 @@
GIT
remote: git://github.com/yaroslav/russian.git
revision: e2dde13672bcee176f8b0be364a55ac256913231
specs:
russian (0.6.0)
i18n (>= 0.5.0)
GEM
remote: http://rubygems.org/
specs:
@ -123,4 +130,5 @@ DEPENDENCIES
mini_magick
princely
rails (= 3.2.6)
russian!
sqlite3-ruby

View File

@ -5,11 +5,11 @@ class FileUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support
# include CarrierWave::RMagick
# include CarrierWave::ImageScience
include CarrierWave::MiniMagick
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader
if ENV['S3_KEY']
storage :fog
def cache_dir
"#{Rails.root.to_s}/tmp/uploads" if ENV['HEROKU'] == 'true'
end
@ -37,36 +37,40 @@ class FileUploader < CarrierWave::Uploader::Base
# end
# Create different versions of your uploaded files
version :collection do
process :resize_to_fill => [200, 200]
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
end
end
version :album do
process :resize_to_fill => [100, 100]
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
end
end
version :preview do
process :resize_to_fit => [210, 210]
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
end
end
version :single do
process :resize_to_limit => [950, 950]
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
end
end
version :collection do
process :resize_to_fill => [200, 200]
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
end
end
version :album do
process :resize_to_fill => [100, 100]
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
end
end
version :preview do
process :resize_to_fit => [210, 210]
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
end
end
version :single do
process :resize_to_limit => [950, 950]
def store_dir
ENV['STORAGE_PATH'] + "/thumbs/#{model.album.path}"
end
end
# Add a white list of extensions which are allowed to be uploaded,
# for images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png bmp tiff)
end
def extension_white_list
%w(jpg jpeg gif png bmp tiff)
end
# Override the filename of the uploaded files
# def filename

View File

@ -1,86 +1,83 @@
<%= content_for :javascript do %>
<style type="text/css">@import url(/javascripts/plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css);</style>
<%= javascript_include_tag "plupload/js/plupload.full.js" -%>
<%= javascript_include_tag "plupload/js/jquery.plupload.queue/jquery.plupload.queue.js" -%>
<style type="text/css">@import url(/javascripts/plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css);</style>
<%= javascript_include_tag "plupload/js/plupload.full.js" -%>
<%= javascript_include_tag "plupload/js/jquery.plupload.queue/jquery.plupload.queue.js" -%>
<script type="text/javascript">
$(document).ready(function() {
$("#uploader").pluploadQueue({
// General settings
runtimes : 'flash,html5,browserplus,silverlight,gears',
url : '<%= photos_path %>',
max_file_size : '10mb',
multipart: true,
multipart_params: {
'<%= get_session_key %>' : encodeURIComponent('<%= cookies[get_session_key] %>'),
'authenticity_token' : '<%= form_authenticity_token %>',
'photo[album_id]' : "<%= @album.id %>"
},
<script type="text/javascript">
$(document).ready(function () {
// Resize images on clientside if we can
//resize : {width : 320, height : 240, quality : 90},
$("#uploader").pluploadQueue({
// General settings
runtimes:'flash,html5,browserplus,silverlight,gears',
url:'<%= photos_path %>',
max_file_size:'10mb',
multipart:true,
multipart_params:{
'<%= get_session_key %>':encodeURIComponent('<%= cookies[get_session_key] %>'),
'authenticity_token':'<%= form_authenticity_token %>',
'photo[album_id]':"<%= @album.id %>"
},
// Specify what files to browse for
filters : [
{title : "Image files", extensions : "jpg,gif,png,bmp,jpeg,tif,tiff"}
],
// Resize images on clientside if we can
//resize : {width : 320, height : 240, quality : 90},
// Flash settings
flash_swf_url : '/javascripts/plupload/js/plupload.flash.swf',
// Specify what files to browse for
filters:[
{title:"Image files", extensions:"jpg,gif,png,bmp,jpeg,tif,tiff,JPG,GIF,PNG,BMP,JPEG,TIF,TIFF"}
],
// Silverlight settings
silverlight_xap_url : '/javascripts/plupload/js/plupload.silverlight.xap',
// Post init events, bound after the internal events
init : {
// Flash settings
flash_swf_url:'/javascripts/plupload/js/plupload.flash.swf',
FileUploaded: function(up, file, info) {
// Called when a file has finished uploading
res = info.response;
if (res.substring(0, 7) === "FILEID:") {
var image = $('<img>').appendTo('#thumbs')
image.css('display','none')
image.attr('src', res.substring(7) )
image.fadeIn('slow')
}
}
}
});
// Silverlight settings
silverlight_xap_url:'/javascripts/plupload/js/plupload.silverlight.xap',
// Client side form validation
$('form').submit(function(e) {
var uploader = $('#uploader').pluploadQueue();
// Post init events, bound after the internal events
init:{
// Validate number of uploaded files
if (uploader.total.uploaded == 0) {
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('UploadProgress', function() {
if (uploader.total.uploaded == uploader.files.length)
$('form').submit();
});
FileUploaded:function (up, file, info) {
// Called when a file has finished uploading
res = info.response;
if (res.substring(0, 7) === "FILEID:") {
var image = $('<img>').appendTo('#thumbs')
image.css('display', 'none')
image.attr('src', res.substring(7))
image.fadeIn('slow')
}
}
}
});
uploader.start();
} else
alert('You must at least upload one file.');
// Client side form validation
$('form').submit(function (e) {
var uploader = $('#uploader').pluploadQueue();
e.preventDefault();
}
});
})
</script>
// Validate number of uploaded files
if (uploader.total.uploaded == 0) {
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('UploadProgress', function () {
if (uploader.total.uploaded == uploader.files.length)
$('form').submit();
});
uploader.start();
} else
alert('You must at least upload one file.');
e.preventDefault();
}
});
})
</script>
<% end %>
<form>
<div id="uploader">
<p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
</div>
<br>
<div id="thumbs"></div>
<div id="uploader">
<p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
</div>
<br>
<div id="thumbs"></div>
</form>
<br><%= link_to "Edit uploaded photos", untouched_album_photos_path( @album ) %>
<br><%= link_to "Edit uploaded photos", untouched_album_photos_path(@album) %>
<br><%= link_to "Back to #{@album.title}", @album %>

View File

@ -14,6 +14,8 @@ module Balder
config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/middleware/)
config.encoding = "utf-8"
config.i18n.default_locale = :ru
config.time_zone = 'Moscow'
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password, :password_confirmation]

View File

@ -0,0 +1,22 @@
String.class_eval do
def to_url
self.parameterize
end
def linkify
result = self.downcase
result.gsub!(/&(\d)+;/, '') # Ditch Entities
result.gsub!('&', 'and') # Replace & with 'and'
result.gsub!(/['"]/, '') # replace quotes by nothing
result.gsub!(/\W/, ' ') # strip all non word chars
result.gsub!(/\ +/, '-') # replace all white space sections with a dash
result.gsub!(/(-)$/, '') # trim dashes
result.gsub!(/^(-)/, '') # trim dashes
result.gsub!(/[^a-zA-Z0-9\-]/, '-') # Get rid of anything we don't like
result
end
def linkify!
self.replace(self.linkify)
end
end

View File

@ -16,8 +16,8 @@ ActiveRecord::Schema.define(:version => 20100412220801) do
create_table "albums", :force => true do |t|
t.string "title", :null => false
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "path"
t.string "address"
t.float "longitude"
@ -30,8 +30,8 @@ ActiveRecord::Schema.define(:version => 20100412220801) do
create_table "collection_albums", :force => true do |t|
t.integer "collection_id"
t.integer "album_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "collection_albums", ["album_id"], :name => "index_collection_albums_on_album_id"
@ -40,8 +40,8 @@ ActiveRecord::Schema.define(:version => 20100412220801) do
create_table "collections", :force => true do |t|
t.string "title", :null => false
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "collections", ["id"], :name => "index_collections_on_id", :unique => true
@ -51,15 +51,15 @@ ActiveRecord::Schema.define(:version => 20100412220801) do
t.string "permissible_type"
t.string "action"
t.boolean "granted"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "photo_tags", :force => true do |t|
t.integer "tag_id"
t.integer "photo_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "photo_tags", ["photo_id"], :name => "index_photo_tags_on_photo_id"
@ -69,8 +69,8 @@ ActiveRecord::Schema.define(:version => 20100412220801) do
t.string "title", :null => false
t.text "description"
t.integer "album_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "path"
t.float "longitude"
t.float "latitude"
@ -84,20 +84,20 @@ ActiveRecord::Schema.define(:version => 20100412220801) do
t.integer "roleable_id"
t.string "roleable_type"
t.integer "role_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "roles", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "tags", :force => true do |t|
t.string "title", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "tags", ["id"], :name => "index_tags_on_id", :unique => true
@ -116,8 +116,8 @@ ActiveRecord::Schema.define(:version => 20100412220801) do
t.datetime "last_login_at"
t.string "current_login_ip"
t.string "last_login_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "name"
end