lavatar 0.1.0
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/lavatar.gemspec +19 -0
- data/lib/lavatar/configuration.rb +17 -0
- data/lib/lavatar/helpers.rb +73 -0
- data/lib/lavatar/version.rb +3 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 489ab38d90bfb513ad3c28c82f2f3867e5b9d12ed9fa0c7303de04ed45655077
|
4
|
+
data.tar.gz: 2449685906a6078e44d86757d73075069cc4674fe7c3f63f1835d727f2ae9242
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb0f9fb0c500aa260b0fa5f0cdc172f7816819f405fa13df1352218da7cde46464bbe37cb3edcdce5100c236a1ca11933dd2f0a13c862088dd4da9ea252ecbb4
|
7
|
+
data.tar.gz: 28319310042107c3967eeb6e3e0fca898f02d099427b0844ec6f07878f4cbc8e33ef73ecb1c2e3ecd5bdb2c28421a97dd1713a0e4fb0b11f24c09bcbbc1141ce
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Juraj Kostolansky
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Lavatar
|
2
|
+
|
3
|
+
Create letter avatars from user initials.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'lavatar'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install lavatar
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
You can override default configuration, for example in `config/initializers/lavatar.rb`:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Lavatar.configure do |config|
|
31
|
+
config.saturation = 0.4 # from 0 to 1
|
32
|
+
config.lightness = 0.5 # from 0 to 1
|
33
|
+
config.font_size = 48
|
34
|
+
config.font_weight = 700
|
35
|
+
config.font_color = "#ffffff"
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
lavatar_tag("JK", 24, { # (required) letters and size (width and height)
|
43
|
+
key: 123, # user identifier to pick a color (ID, email, ...)
|
44
|
+
color: "#9e5555", # forced background color
|
45
|
+
font_color: "#ffffff", # font color
|
46
|
+
class: "my-class" # SVG element classes
|
47
|
+
)
|
48
|
+
```
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jkostolansky/lavatar. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
57
|
+
|
58
|
+
## Code of Conduct
|
59
|
+
|
60
|
+
Everyone interacting in the Lavatar project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jkostolansky/lavatar/blob/master/CODE_OF_CONDUCT.md).
|
data/lavatar.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "lavatar/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "lavatar"
|
7
|
+
spec.version = Lavatar::VERSION
|
8
|
+
spec.authors = ["Juraj Kostolansky"]
|
9
|
+
spec.email = ["juraj@kostolansky.sk"]
|
10
|
+
|
11
|
+
spec.summary = "Generate letter avatars in Ruby on Rails"
|
12
|
+
spec.homepage = "https://github.com/jkostolansky/lavatar"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = Dir["README.md", "LICENSE.txt", "lavatar.gemspec", "lib/lavatar/*.rb"]
|
16
|
+
spec.require_path = "lib"
|
17
|
+
|
18
|
+
spec.add_dependency "actionpack"
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Lavatar
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :saturation
|
4
|
+
attr_accessor :lightness
|
5
|
+
attr_accessor :font_size
|
6
|
+
attr_accessor :font_weight
|
7
|
+
attr_accessor :font_color
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@saturation = 0.4
|
11
|
+
@lightness = 0.5
|
12
|
+
@font_size = 48
|
13
|
+
@font_weight = 700
|
14
|
+
@font_color = "#ffffff"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Lavatar
|
2
|
+
module Helpers
|
3
|
+
def lavatar_tag(letters, size, options = {})
|
4
|
+
key = options[:key] || letters
|
5
|
+
saturation = options[:saturation] || Lavatar.configuration.saturation
|
6
|
+
lightness = options[:lightness] || Lavatar.configuration.lightness
|
7
|
+
color = options[:color] || key_to_color(key, saturation, lightness)
|
8
|
+
font_color = options[:font_color] || Lavatar.configuration.font_color
|
9
|
+
font_size = options[:font_size] || Lavatar.configuration.font_size
|
10
|
+
font_weight = options[:font_weight] || Lavatar.configuration.font_weight
|
11
|
+
klass = options[:class]
|
12
|
+
|
13
|
+
svg_attrs = {
|
14
|
+
width: size,
|
15
|
+
height: size,
|
16
|
+
class: klass,
|
17
|
+
viewBox: "0 0 100 100",
|
18
|
+
}
|
19
|
+
|
20
|
+
rect_attrs = {
|
21
|
+
x: "0",
|
22
|
+
y: "0",
|
23
|
+
width: "100",
|
24
|
+
height: "100",
|
25
|
+
fill: color,
|
26
|
+
}
|
27
|
+
|
28
|
+
text_attrs = {
|
29
|
+
x: "50%",
|
30
|
+
y: "50%",
|
31
|
+
fill: font_color,
|
32
|
+
"font-size": font_size,
|
33
|
+
"font-weight": font_weight,
|
34
|
+
"alignment-baseline": "central",
|
35
|
+
"text-anchor": "middle",
|
36
|
+
}
|
37
|
+
|
38
|
+
content_tag :svg, svg_attrs do
|
39
|
+
tag(:rect, rect_attrs) + content_tag(:text, letters, text_attrs)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def key_to_color(key, saturation, lightness)
|
46
|
+
hue = Digest::MD5.hexdigest(key)[0..5].to_i(16).to_f/0xFFFFFF
|
47
|
+
hsl_to_rgb(hue, saturation, lightness)
|
48
|
+
end
|
49
|
+
|
50
|
+
def hsl_to_rgb(h, s, l)
|
51
|
+
if s == 0 # achromatic
|
52
|
+
r, g, b = l, l, l
|
53
|
+
else
|
54
|
+
hue2rgb = lambda do |m1, m2, h|
|
55
|
+
h += 1 if h < 0
|
56
|
+
h -= 1 if h > 1
|
57
|
+
return m1 + (m2 - m1) * h * 6 if h * 6 < 1
|
58
|
+
return m2 if h * 2 < 1
|
59
|
+
return m1 + (m2 - m1) * (2.0/3 - h) * 6 if h * 3 < 2
|
60
|
+
return m1
|
61
|
+
end
|
62
|
+
|
63
|
+
m2 = l < 0.5 ? l * (s + 1) : l + s - l * s
|
64
|
+
m1 = l * 2 - m2
|
65
|
+
r = hue2rgb.call(m1, m2, h + 1.0/3)
|
66
|
+
g = hue2rgb.call(m1, m2, h)
|
67
|
+
b = hue2rgb.call(m1, m2, h - 1.0/3)
|
68
|
+
end
|
69
|
+
|
70
|
+
"#%02x%02x%02x" % [(r*255).to_i, (g*255).to_i, (b*255).to_i]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lavatar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juraj Kostolansky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- juraj@kostolansky.sk
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.md
|
36
|
+
- lavatar.gemspec
|
37
|
+
- lib/lavatar/configuration.rb
|
38
|
+
- lib/lavatar/helpers.rb
|
39
|
+
- lib/lavatar/version.rb
|
40
|
+
homepage: https://github.com/jkostolansky/lavatar
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.0.1
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Generate letter avatars in Ruby on Rails
|
63
|
+
test_files: []
|