letter_avatar 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 989abb8166d1c71d0da71f8182b8d9b0755ad042
4
- data.tar.gz: 5109232282967eac2d5c5b854eb12590690cc61b
3
+ metadata.gz: 86dcb811e2366a913e7664a020ea1b7e3ce6abcc
4
+ data.tar.gz: f26e75c683095b4b9b9ab465f8acd8560911e1da
5
5
  SHA512:
6
- metadata.gz: dc911d3955696fdb1b4a6f3d0037efa7641aa4ec7f76534e7488e6438d424f039af9f616abf5fa0e7bdbaef73fa3aa1493675e101950b9f9044ce1801111fce0
7
- data.tar.gz: 5b186666a21e8ab53ab6ead898cbb9acc0f661c48793964cb2bb9775f42a8ef0ae1f7d9e5f328192698308297e921e0e4695a09e82bf35292bc3b49ff796cee1
6
+ metadata.gz: 65bb042715c1090612f99e3f231bf36d9c56aca5e0a2d4901ea48609e875072bcd1b18a62dc2cbc2ec4f5ddb08e7393745bb0794b7704fd51dc9cdca7c26e225
7
+ data.tar.gz: d3c4ce80a3f3b66324fde6393822f6595cbfb04b8bc038151d1c3ba65db68e59ca9c2de68c6ef2b4e504f75440397e421079e4fbc3b4700f536f4ab3caae6b38
data/README.md CHANGED
@@ -8,6 +8,8 @@ Code extracted from discourse source (thanks guys!) - I needed this functionalit
8
8
 
9
9
  ## Examples
10
10
 
11
+ #### Google's Inbox Palette
12
+
11
13
  ![a](https://cloud.githubusercontent.com/assets/5518/11028712/fb4ceb8a-86fb-11e5-8a94-c75eaf46b089.png) ![b](https://cloud.githubusercontent.com/assets/5518/11028713/fb55fc5c-86fb-11e5-9a67-a4e84ee618be.png) ![c](https://cloud.githubusercontent.com/assets/5518/11028715/fb5a8178-86fb-11e5-9312-9cc990b1a94f.png) ![d](https://cloud.githubusercontent.com/assets/5518/11028714/fb567f88-86fb-11e5-8e99-b14602321f69.png) ![e](https://cloud.githubusercontent.com/assets/5518/11028716/fb61d194-86fb-11e5-8bab-bc69cad905cc.png) ![f](https://cloud.githubusercontent.com/assets/5518/11028717/fb656d54-86fb-11e5-810a-f8a3847c0da8.png) ![g](https://cloud.githubusercontent.com/assets/5518/11028718/fb862e7c-86fb-11e5-8b46-42a64fb15f46.png) ![h](https://cloud.githubusercontent.com/assets/5518/11028719/fb8f1910-86fb-11e5-9794-433a9490b15a.png) ![j](https://cloud.githubusercontent.com/assets/5518/11028720/fb8f200e-86fb-11e5-8b20-476745abfe21.png) ![l](https://cloud.githubusercontent.com/assets/5518/11028721/fb923654-86fb-11e5-961c-92be1aaedef8.png) ![m](https://cloud.githubusercontent.com/assets/5518/11028722/fb9e68b6-86fb-11e5-8ba6-4e8ece3a9d89.png) ![n](https://cloud.githubusercontent.com/assets/5518/11028723/fba26826-86fb-11e5-9611-bde4bc7d84ed.png) ![p](https://cloud.githubusercontent.com/assets/5518/11028724/fbc4d9ec-86fb-11e5-85f3-0e0b46bbc9a1.png) ![s](https://cloud.githubusercontent.com/assets/5518/11028725/fbc5d464-86fb-11e5-937e-de11c747b70d.png)
12
14
 
13
15
  ## Installation
@@ -47,6 +49,7 @@ $ gem install letter_avatar
47
49
  ```ruby
48
50
  LetterAvatar.setup do |config|
49
51
  config.cache_base_path = 'public/system/lets' # default is 'public/system'
52
+ config.colors_palette = :iwanthue # default is :google
50
53
  end
51
54
  ```
52
55
 
@@ -71,6 +74,24 @@ There's also helper for this. To use it, you need:
71
74
  letter_avatar_for('ksz2k', 200)
72
75
  ```
73
76
 
77
+ ### Way to support non [a-z0-9] charsets
78
+
79
+ ```rb
80
+ class User
81
+ def username_for_avatar
82
+ # Translate chinese hanzi to pinyin
83
+ # https://github.com/flyerhzm/chinese_pinyin
84
+ Pinyin.t(self.username)
85
+ end
86
+ end
87
+ ```
88
+
89
+ Then you can get right avatar now:
90
+
91
+ ```rb
92
+ letter_avatar_for(user.username_for_avatar, 200)
93
+ ```
94
+
74
95
  ## Contributing
75
96
 
76
97
  1. Fork it
@@ -1,9 +1,29 @@
1
1
  module LetterAvatar
2
2
  module Colors
3
3
 
4
+ def self.for(username)
5
+ char = username[0].upcase
6
+
7
+ if /[A-Z]/.match(char)
8
+ # 65 is 'A' ord
9
+ idx = char.ord - 65
10
+ COLORS[idx]
11
+ elsif /[\d]/.match(char)
12
+ COLORS[char.to_i]
13
+ else
14
+ COLORS[Digest::MD5.hexdigest(username)[0...15].to_i(16) % COLORS.length]
15
+ end
16
+ end
17
+
18
+ def self.colors
19
+ public_send(LetterAvatar.colors_palette) rescue google
20
+ end
21
+
22
+
4
23
  # Colors form Google Inbox
5
24
  # https://inbox.google.com
6
- COLORS = [
25
+ def self.google
26
+ [
7
27
  [226, 95, 81], # A
8
28
  [242, 96, 145], # B
9
29
  [187, 101, 202], # C
@@ -32,24 +52,231 @@ module LetterAvatar
32
52
  [173, 214, 125] # Z
33
53
  ]
34
54
 
35
- def self.for(username)
36
- char = username[0]
37
- char.upcase!
38
- if /[A-Z]/.match(char)
39
- # 65 is 'A' ord
40
- idx = char.ord - 65
41
- return all[idx]
42
- end
43
-
44
- if /[\d]/.match(char)
45
- return all[char.to_i]
46
- end
47
-
48
- all[Digest::MD5.hexdigest(username)[0...15].to_i(16) % all.length]
49
- end
50
-
51
- def self.all
52
- COLORS
55
+ # palette of optimally disctinct colors
56
+ # cf. http://tools.medialab.sciences-po.fr/iwanthue/index.php
57
+ # parameters used:
58
+ # - H: 0 - 360
59
+ # - C: 0 - 2
60
+ # - L: 0.75 - 1.5
61
+ def self.iwanthue
62
+ [
63
+ [198,125,40],
64
+ [61,155,243],
65
+ [74,243,75],
66
+ [238,89,166],
67
+ [52,240,224],
68
+ [177,156,155],
69
+ [240,120,145],
70
+ [111,154,78],
71
+ [237,179,245],
72
+ [237,101,95],
73
+ [89,239,155],
74
+ [43,254,70],
75
+ [163,212,245],
76
+ [65,152,142],
77
+ [165,135,246],
78
+ [181,166,38],
79
+ [187,229,206],
80
+ [77,164,25],
81
+ [179,246,101],
82
+ [234,93,37],
83
+ [225,155,115],
84
+ [142,140,188],
85
+ [223,120,140],
86
+ [249,174,27],
87
+ [244,117,225],
88
+ [137,141,102],
89
+ [75,191,146],
90
+ [188,239,142],
91
+ [164,199,145],
92
+ [173,120,149],
93
+ [59,195,89],
94
+ [222,198,220],
95
+ [68,145,187],
96
+ [236,204,179],
97
+ [159,195,72],
98
+ [188,121,189],
99
+ [166,160,85],
100
+ [181,233,37],
101
+ [236,177,85],
102
+ [121,147,160],
103
+ [234,218,110],
104
+ [241,157,191],
105
+ [62,200,234],
106
+ [133,243,34],
107
+ [88,149,110],
108
+ [59,228,248],
109
+ [183,119,118],
110
+ [251,195,45],
111
+ [113,196,122],
112
+ [197,115,70],
113
+ [80,175,187],
114
+ [103,231,238],
115
+ [240,72,133],
116
+ [228,149,241],
117
+ [180,188,159],
118
+ [172,132,85],
119
+ [180,135,251],
120
+ [236,194,58],
121
+ [217,176,109],
122
+ [88,244,199],
123
+ [186,157,239],
124
+ [113,230,96],
125
+ [206,115,165],
126
+ [244,178,163],
127
+ [230,139,26],
128
+ [241,125,89],
129
+ [83,160,66],
130
+ [107,190,166],
131
+ [197,161,210],
132
+ [198,203,245],
133
+ [238,117,19],
134
+ [228,119,116],
135
+ [131,156,41],
136
+ [145,178,168],
137
+ [139,170,220],
138
+ [233,95,125],
139
+ [87,178,230],
140
+ [157,200,119],
141
+ [237,140,76],
142
+ [229,185,186],
143
+ [144,206,212],
144
+ [236,209,158],
145
+ [185,189,79],
146
+ [34,208,66],
147
+ [84,238,129],
148
+ [133,140,134],
149
+ [67,157,94],
150
+ [168,179,25],
151
+ [140,145,240],
152
+ [151,241,125],
153
+ [67,162,107],
154
+ [200,156,21],
155
+ [169,173,189],
156
+ [226,116,189],
157
+ [133,231,191],
158
+ [194,161,63],
159
+ [241,77,99],
160
+ [241,217,53],
161
+ [123,204,105],
162
+ [210,201,119],
163
+ [229,108,155],
164
+ [240,91,72],
165
+ [187,115,210],
166
+ [240,163,100],
167
+ [178,217,57],
168
+ [179,135,116],
169
+ [204,211,24],
170
+ [186,135,57],
171
+ [223,176,135],
172
+ [204,148,151],
173
+ [116,223,50],
174
+ [95,195,46],
175
+ [123,160,236],
176
+ [181,172,131],
177
+ [142,220,202],
178
+ [240,140,112],
179
+ [172,145,164],
180
+ [228,124,45],
181
+ [135,151,243],
182
+ [42,205,125],
183
+ [192,233,116],
184
+ [119,170,114],
185
+ [158,138,26],
186
+ [73,190,183],
187
+ [185,229,243],
188
+ [227,107,55],
189
+ [196,205,202],
190
+ [132,143,60],
191
+ [233,192,237],
192
+ [62,150,220],
193
+ [205,201,141],
194
+ [106,140,190],
195
+ [161,131,205],
196
+ [135,134,158],
197
+ [198,139,81],
198
+ [115,171,32],
199
+ [101,181,67],
200
+ [149,137,119],
201
+ [37,142,183],
202
+ [183,130,175],
203
+ [168,125,133],
204
+ [124,142,87],
205
+ [236,156,171],
206
+ [232,194,91],
207
+ [219,200,69],
208
+ [144,219,34],
209
+ [219,95,187],
210
+ [145,154,217],
211
+ [165,185,100],
212
+ [127,238,163],
213
+ [224,178,198],
214
+ [119,153,120],
215
+ [124,212,92],
216
+ [172,161,105],
217
+ [231,155,135],
218
+ [157,132,101],
219
+ [122,185,146],
220
+ [53,166,51],
221
+ [70,163,90],
222
+ [150,190,213],
223
+ [210,107,60],
224
+ [166,152,185],
225
+ [159,194,159],
226
+ [39,141,222],
227
+ [202,176,161],
228
+ [95,140,229],
229
+ [168,142,87],
230
+ [93,170,203],
231
+ [159,142,54],
232
+ [14,168,39],
233
+ [94,150,149],
234
+ [187,206,136],
235
+ [157,224,166],
236
+ [235,158,208],
237
+ [109,232,216],
238
+ [141,201,87],
239
+ [208,124,118],
240
+ [142,125,214],
241
+ [19,237,174],
242
+ [72,219,41],
243
+ [234,102,111],
244
+ [168,142,79],
245
+ [188,135,35],
246
+ [95,155,143],
247
+ [148,173,116],
248
+ [223,112,95],
249
+ [228,128,236],
250
+ [206,114,54],
251
+ [195,119,88],
252
+ [235,140,94],
253
+ [235,202,125],
254
+ [233,155,153],
255
+ [214,214,238],
256
+ [246,200,35],
257
+ [151,125,171],
258
+ [132,145,172],
259
+ [131,142,118],
260
+ [199,126,150],
261
+ [61,162,123],
262
+ [58,176,151],
263
+ [215,141,69],
264
+ [225,154,220],
265
+ [220,77,167],
266
+ [233,161,64],
267
+ [130,221,137],
268
+ [81,191,129],
269
+ [169,162,140],
270
+ [174,177,222],
271
+ [236,174,47],
272
+ [233,188,180],
273
+ [69,222,172],
274
+ [71,232,93],
275
+ [118,211,238],
276
+ [157,224,83],
277
+ [218,105,73],
278
+ [126,169,36]
279
+ ]
53
280
  end
54
281
 
55
282
  end
@@ -1,3 +1,3 @@
1
1
  module LetterAvatar
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/letter_avatar.rb CHANGED
@@ -7,6 +7,9 @@ module LetterAvatar
7
7
  mattr_accessor :cache_base_path
8
8
  @@cache_base_path = nil
9
9
 
10
+ mattr_accessor :colors_palette
11
+ @@colors_palette = :google
12
+
10
13
  def self.setup(&block)
11
14
  yield(self)
12
15
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - discourse developers
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-11-09 00:00:00.000000000 Z
14
+ date: 2015-11-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler