Commit d53e4b1014efebcd5745e4466a5ca58eeb9b298d

Authored by Krzysiek Szczuka
1 parent 60a8bd95
Exists in master

v0.1.10:

- `LetterAvatar::AvatarHelper` module tweaks
  - `letter_avatar_url` method, returning avatar proper url
  - `letter_avatar_tag` doeas not require `ActionView::Helpers::AssetTagHelper`
CHANGELOG.md
  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 +
1 8 0.1.9
2 9 -----
3 10  
4 11 - `LetterAvatar::Configuration` module, `mattr_accessor` (depending on `ActiveSupport`) removed
  12 +
5 13 fixes [#7](https://github.com/ksz2k/letter_avatar/issues/7)
6 14  
7 15 0.1.5
8 16 -----
9 17  
10 18 - Use [posix-spawn](https://github.com/rtomayko/posix-spawn) to instead of Kernel#exec to get better performance.
  19 +
11 20 > fork(2) calls slow down as the parent process uses more memory due to the need to copy page tables.
... ...
README.md
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
... ...
lib/letter_avatar/avatar_helper.rb
... ... @@ -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
... ...
lib/letter_avatar/version.rb
1 1 module LetterAvatar
2   - VERSION = "0.1.9"
  2 + VERSION = "0.1.10"
3 3 end
... ...