initials 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +10 -4
- data/demo.png +0 -0
- data/lib/initials/svg.rb +5 -4
- data/lib/initials/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ddb7223bac6b77c96253275a3fcdc39d6de169c445650df95694f9897ad25b
|
4
|
+
data.tar.gz: 33af3be7bf7dbb56b6c2ad947fa2aa157b35f63bf98e515f4b8d852fa69ff514
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8f6b21b1f49b69cb49693b3f157f9597542597140e96b1124f8c2c13087326d5e1a4183b353393740fa82e91e3d6e9e789c8eb74eab9688b9069129708f1265
|
7
|
+
data.tar.gz: 3b62b60389a157f0713717bb086ec40a3c4b74edbe139609fef642535cd33df84672a61b50661ffd8ac3332e839409a376a9146dc977356e7b62b1434b8fa0e6
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# Initials [![Maintainability](https://api.codeclimate.com/v1/badges/fb865ec4adcd0671dc48/maintainability)](https://codeclimate.com/github/thutterer/initials/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/fb865ec4adcd0671dc48/test_coverage)](https://codeclimate.com/github/thutterer/initials/test_coverage)
|
2
2
|
|
3
3
|
Don't want to implement user avatar uploads but still have basic avatars to distinguish users and brigthen up your app?
|
4
4
|
|
5
5
|
Use colorful SVGs as user avatars in any Ruby and Rails application.
|
6
6
|
|
7
|
+
![demo](demo.png)
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
@@ -23,6 +25,7 @@ Or install it yourself as:
|
|
23
25
|
## Usage
|
24
26
|
|
25
27
|
Call `Initials.svg("Morty Smith")` anywhere to get a colorful initials avatar SVG as string.
|
28
|
+
The avatar's background color is based on the provided name and the font-size is adjusted to fit between one and three character initials.
|
26
29
|
|
27
30
|
### Rails
|
28
31
|
|
@@ -46,11 +49,14 @@ Initials automatically marks its created SVG strings as `html_safe`.
|
|
46
49
|
|
47
50
|
You can pass the following options into `Initials.svg` or your `user_avatar` helper:
|
48
51
|
|
49
|
-
```
|
50
|
-
user_avatar(current_user.name,
|
52
|
+
```ruby
|
53
|
+
user_avatar(current_user.name,
|
54
|
+
limit: 1, # sets max length for initials
|
55
|
+
size: 96 # sets SVG height and width in pixel
|
56
|
+
)
|
51
57
|
```
|
52
58
|
|
53
|
-
|
59
|
+
Of course, you can also use CSS to make the SVG have different sizes in different places of your HTML.
|
54
60
|
|
55
61
|
## Development
|
56
62
|
|
data/demo.png
CHANGED
Binary file
|
data/lib/initials/svg.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Initials
|
2
2
|
class SVG
|
3
|
-
attr_reader :name, :size
|
3
|
+
attr_reader :name, :limit, :size
|
4
4
|
|
5
|
-
def initialize(name, size: 32)
|
5
|
+
def initialize(name, limit: 3, size: 32)
|
6
6
|
raise Initials::Error.new("Name is not a string or empty") unless (name.respond_to?(:to_s) && name.to_s.length > 0)
|
7
7
|
@name = name
|
8
|
+
@limit = limit
|
8
9
|
@size = size
|
9
10
|
end
|
10
11
|
|
@@ -12,7 +13,7 @@ module Initials
|
|
12
13
|
svg = [
|
13
14
|
"<svg width='#{size}' height='#{size}'>",
|
14
15
|
"<circle cx='#{size / 2}' cy='#{size / 2}' r='#{size / 2}' fill='#{fill}' />",
|
15
|
-
"<text x='50%' y='50%' fill='white' fill-opacity='0.75' dominant-baseline='central' text-anchor='middle' style='font:
|
16
|
+
"<text x='50%' y='50%' fill='white' fill-opacity='0.75' dominant-baseline='central' text-anchor='middle' style='font-size: #{font_size}px; font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen-Sans, Ubuntu, Cantarell, \"Helvetica Neue\", sans-serif; user-select: none;'>",
|
16
17
|
"#{initials}",
|
17
18
|
"</text>",
|
18
19
|
"</svg>"
|
@@ -31,7 +32,7 @@ module Initials
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def initials
|
34
|
-
name.split(' ')[0,
|
35
|
+
name.split(' ')[0, limit].map { |s| s[0].capitalize }.join
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
data/lib/initials/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: initials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|