letter_avatar 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3b849f44e2670439f8e2376988f5335c83b707a
4
- data.tar.gz: bc4738796c5f67cadce646504e6813d92a73153f
3
+ metadata.gz: a23085c33db8856b2c47db111f78212c2026b24a
4
+ data.tar.gz: 5dc1880d4338652bc95b9c660a7b21eef98e22f0
5
5
  SHA512:
6
- metadata.gz: 094ef5142742c6682c3c88f106b6ee7714e31a665c1836bd7a7df62d9a954a4f9ab368f4c9947ba6d4dfb45242f65baed1fadf381bdfc51484c80398c5644708
7
- data.tar.gz: de3823851c9412247abb68a7249a961ff0d2d8afa09b264acc6fa92c11e2bb79dc181f9c479d37bc7307cbd2f1b2cdf681fea58f7d9949c429134850d12231bb
6
+ metadata.gz: da069e4393094434e4d5a899e56547bb2384f297b643df2ad7c244406986806c8f263d549206f67460cd010b8939552775f6baa360de084c158701343366728b
7
+ data.tar.gz: c40982c022892c56b00bbc8c93c8f6e83eeb4529a6607c72c2e8e4b8b0d5fd7c89bdbf643ff10d2dd6c4da4ed4bc641e6d598e4758efd0925dbcb47b89a32c57
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
+ 0.1.10
2
+ -----
3
+
4
+ - `LetterAvatar::AvatarHelper` module tweaks
5
+ - `letter_avatar_url` method, returning avatar proper url
6
+ - `letter_avatar_tag` doeas not require `ActionView::Helpers::AssetTagHelper`
7
+
8
+ 0.1.9
9
+ -----
10
+
11
+ - `LetterAvatar::Configuration` module, `mattr_accessor` (depending on `ActiveSupport`) removed
12
+
13
+ fixes [#7](https://github.com/ksz2k/letter_avatar/issues/7)
14
+
1
15
  0.1.5
2
16
  -----
3
17
 
4
18
  - Use [posix-spawn](https://github.com/rtomayko/posix-spawn) to instead of Kernel#exec to get better performance.
19
+
5
20
  > fork(2) calls slow down as the parent process uses more memory due to the need to copy page tables.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # LetterAvatar
2
2
 
3
- Gem for creating letter avatar from user's name.
3
+ Gem for creating letter avatar from user's name (or any other strong / character).
4
4
 
5
- Code extracted from discourse source (thanks guys!) - I needed this functionality in three projects, so here's the gem! :-)
5
+ Code extracted from [discourse](https://www.discourse.org/) source (thanks guys!) - I needed this functionality in three projects, so here's the gem! :-)
6
6
 
7
7
  [![Code Climate](https://codeclimate.com/github/ksz2k/letter_avatar/badges/gpa.svg)](https://codeclimate.com/github/ksz2k/letter_avatar)
8
8
 
@@ -82,8 +82,13 @@ There's also helper for this. To use it, you need:
82
82
 
83
83
  ```ruby
84
84
  letter_avatar_for('ksz2k', 200)
85
+ => "public/system/letter_avatars/2/K/87_178_230/200.png"
86
+ # or
87
+ letter_avatar_url('ksz2k', 200)
88
+ => "/system/letter_avatars/2/K/87_178_230/200.png"
85
89
  # or even
86
90
  letter_avatar_tag('ksz2k', 200, class: 'av')
91
+ => "<img class=\"av\" alt=\"ksz2k\" src=\"/system/letter_avatars/2/K/87_178_230/200.png\" />"
87
92
  ```
88
93
 
89
94
  ### Way to support non [a-z0-9] charsets
@@ -64,31 +64,22 @@ module LetterAvatar
64
64
  end
65
65
 
66
66
  def generate_fullsize(identity)
67
- color = identity.color
68
- letter = identity.letter
69
-
70
-
71
67
  filename = fullsize_path(identity)
72
68
 
73
- command = %W(
74
- convert
75
- -size #{FULLSIZE}x#{FULLSIZE}
76
- xc:#{to_rgb(color)}
77
- -pointsize 140
78
- -font #{FONT_FILENAME}
79
- -weight #{LetterAvatar.weight}
80
- -fill '#{FILL_COLOR}'
81
- -gravity Center
82
- -annotate #{LetterAvatar.annotate_position} '#{letter}'
83
- '#{filename}'
84
- ).join(' ')
85
-
86
- pid, stdin, stdout, stderr = POSIX::Spawn.popen4(command)
87
- Process.waitpid(pid)
88
- err = stderr.read
89
- if err != nil && err.length > 0
90
- raise "letter_avatar error: #{err.strip}"
91
- end
69
+ LetterAvatar.execute(
70
+ %W(
71
+ convert
72
+ -size #{FULLSIZE}x#{FULLSIZE}
73
+ xc:#{to_rgb(identity.color)}
74
+ -pointsize 140
75
+ -font #{FONT_FILENAME}
76
+ -weight #{LetterAvatar.weight}
77
+ -fill '#{FILL_COLOR}'
78
+ -gravity Center
79
+ -annotate #{LetterAvatar.annotate_position} '#{identity.letter}'
80
+ '#{filename}'
81
+ ).join(' ')
82
+ )
92
83
 
93
84
  filename
94
85
  end
@@ -10,8 +10,17 @@ module LetterAvatar
10
10
  avatar_path.to_s.sub('public/','/')
11
11
  end
12
12
 
13
+ def letter_avatar_url(name, size = 64)
14
+ letter_avatar_url_for(letter_avatar_for(name, size))
15
+ end
16
+
13
17
  def letter_avatar_tag(name, size = 64, options = {})
14
- image_tag(letter_avatar_url_for(letter_avatar_for(name, size)), options)
18
+ if defined?(ActionView::Helpers::AssetTagHelper)
19
+ include ActionView::Helpers::AssetTagHelper
20
+ image_tag(letter_avatar_url(name, size), options.merge(alt: name))
21
+ else
22
+ "<img alt=\"#{name}\" class\"#{options.fetch(:class)}\" src=\"#{letter_avatar_url(name, size)}\" />"
23
+ end
15
24
  end
16
25
 
17
26
  end
@@ -4,7 +4,7 @@ module LetterAvatar
4
4
  PALETTES = [:google, :iwanthue]
5
5
 
6
6
  def self.for(username)
7
- public_send("with_#{LetterAvatar.colors_palette}", username) rescue with_google(username)
7
+ public_send("with_#{LetterAvatar.colors_palette}", username)
8
8
  end
9
9
 
10
10
  def self.with_iwanthue(username)
@@ -1,3 +1,3 @@
1
1
  module LetterAvatar
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
data/lib/letter_avatar.rb CHANGED
@@ -6,29 +6,31 @@ require "letter_avatar/avatar_helper"
6
6
  module LetterAvatar
7
7
  extend LetterAvatar::Configuration
8
8
 
9
+ class ExecutionError < StandardError; end
10
+
9
11
  def self.setup(&block)
10
12
  yield(self)
11
13
  end
12
14
 
13
15
  def self.resize(from, to, width, height)
14
- # NOTE: ORDER is important!
15
- instructions = %W{
16
- #{from}
17
- -background transparent
18
- -gravity center
19
- -thumbnail #{width}x#{height}^
20
- -extent #{width}x#{height}
21
- -interpolate bicubic
22
- -unsharp 2x0.5+0.7+0
23
- -quality 98
24
- #{to}
25
- }.join(" ")
26
-
27
- `convert #{instructions}`
28
-
29
- if $?.exitstatus == 0
16
+ begin
17
+ execute(
18
+ # NOTE: ORDER is important!
19
+ %W{
20
+ convert
21
+ #{from}
22
+ -background transparent
23
+ -gravity center
24
+ -thumbnail #{width}x#{height}^
25
+ -extent #{width}x#{height}
26
+ -interpolate bicubic
27
+ -unsharp 2x0.5+0.7+0
28
+ -quality 98
29
+ #{to}
30
+ }.join(" ")
31
+ )
30
32
  true
31
- else
33
+ rescue => e
32
34
  false
33
35
  end
34
36
  end
@@ -37,4 +39,16 @@ module LetterAvatar
37
39
  Avatar.generate(username, size)
38
40
  end
39
41
 
42
+ def self.execute(cmd)
43
+ cmd = cmd.join(' ') if cmd.is_a?(Array)
44
+ pid, stdin, stdout, stderr = POSIX::Spawn.popen4(cmd)
45
+ Process.waitpid(pid)
46
+ err = stderr.read
47
+ if err != nil && err.length > 0
48
+ raise ExecutionError.new("letter_avatar execution error (when calling '#{cmd}'): '#{err.strip}'")
49
+ else
50
+ true
51
+ end
52
+ end
53
+
40
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_avatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - discourse developers