avatars_for_rails 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/app/controllers/avatars_controller.rb +1 -0
- data/app/models/avatar.rb +17 -1
- data/avatars_for_rails.gemspec +1 -1
- metadata +4 -4
data/.gitignore
CHANGED
data/app/models/avatar.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'RMagick'
|
2
2
|
|
3
3
|
class Avatar < ActiveRecord::Base
|
4
|
+
|
5
|
+
#Paperclip configuration.
|
4
6
|
has_attached_file :logo,
|
5
7
|
:styles => AvatarsForRails.avatarable_styles,
|
6
8
|
:default_url => "logos/:style/:subtype_class.png"
|
@@ -17,11 +19,14 @@ class Avatar < ActiveRecord::Base
|
|
17
19
|
|
18
20
|
before_create :make_active
|
19
21
|
after_create :disable_old
|
22
|
+
|
23
|
+
#This method helps when changing the active logo for a user.
|
20
24
|
def make_active
|
21
25
|
self.updating_logo = true
|
22
26
|
self.active = true
|
23
27
|
end
|
24
28
|
|
29
|
+
#Disable all the user's logos except the actual.
|
25
30
|
def disable_old
|
26
31
|
self.avatarable.avatars.where("id != ?", self.id).each do |old_logo|
|
27
32
|
old_logo.update_attribute :active, false
|
@@ -36,6 +41,7 @@ class Avatar < ActiveRecord::Base
|
|
36
41
|
return @name.blank?
|
37
42
|
end
|
38
43
|
|
44
|
+
#Process the seccond step. It makes the precrop of the image and create a new avatar with the croped image.
|
39
45
|
def precrop_done
|
40
46
|
return if @name.blank? || !@updating_logo.blank?
|
41
47
|
|
@@ -49,15 +55,21 @@ class Avatar < ActiveRecord::Base
|
|
49
55
|
FileUtils.remove_file(precrop_path)
|
50
56
|
end
|
51
57
|
|
58
|
+
#Returns the avatars_for_rails temp directory.
|
52
59
|
def self.images_tmp_path
|
53
60
|
images_path = File.join(Rails.root, "public", "images")
|
54
|
-
tmp_path = FileUtils.mkdir_p(File.join(images_path, "tmp"))
|
61
|
+
#tmp_path = FileUtils.mkdir_p(File.join(images_path, "tmp"))
|
62
|
+
tmp_path = File.join(images_path, "tmp")
|
63
|
+
FileUtils.mkdir_p(tmp_path)
|
64
|
+
return tmp_path
|
55
65
|
end
|
56
66
|
|
67
|
+
#This method copies a file to the avatars_for_rails temp directory.
|
57
68
|
def self.copy_to_temp_file(path)
|
58
69
|
FileUtils.cp(path,Avatar.images_tmp_path)
|
59
70
|
end
|
60
71
|
|
72
|
+
#Returns the height and widht of an image.
|
61
73
|
def self.get_image_dimensions(name)
|
62
74
|
img_orig = Magick::Image.read(name).first
|
63
75
|
dimensions = {}
|
@@ -66,6 +78,7 @@ class Avatar < ActiveRecord::Base
|
|
66
78
|
dimensions
|
67
79
|
end
|
68
80
|
|
81
|
+
#Checks if a file is valid for being an avatar.
|
69
82
|
def self.check_image_tmp_valid(path)
|
70
83
|
|
71
84
|
begin
|
@@ -77,6 +90,7 @@ class Avatar < ActiveRecord::Base
|
|
77
90
|
end
|
78
91
|
end
|
79
92
|
|
93
|
+
#Process the image in the first step of the process. It resizes the image and copy it to the avatars_for_rails temp directory.
|
80
94
|
def process_precrop
|
81
95
|
|
82
96
|
if @name.blank? && ( logo.content_type.present? && !logo.content_type.start_with?("image/"))
|
@@ -94,6 +108,7 @@ class Avatar < ActiveRecord::Base
|
|
94
108
|
end
|
95
109
|
end
|
96
110
|
|
111
|
+
#Resizes an image with the options passed as arguments.
|
97
112
|
def resize_image(path,width,height)
|
98
113
|
begin
|
99
114
|
img_orig = Magick::Image.read(path).first
|
@@ -106,6 +121,7 @@ class Avatar < ActiveRecord::Base
|
|
106
121
|
end
|
107
122
|
end
|
108
123
|
|
124
|
+
#Precrop an image with the options passed as arguments.
|
109
125
|
def make_precrop(path,x,y,width,height)
|
110
126
|
begin
|
111
127
|
img_orig = Magick::Image.read(path).first
|
data/avatars_for_rails.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# project in your rails apps through git.
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "avatars_for_rails"
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
s.authors = ["Jaime Castro Montero"]
|
7
7
|
s.summary = "Avatar manager for rails apps."
|
8
8
|
s.description = "A Rails engine that allows any model to act as avatarable, permitting it to have a complete avatar manager with a few options. Adapted to rails 3.1.0"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avatars_for_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jaime Castro Montero
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: foreigner
|