initials 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2dce220e10036fd5284e737264c5ed0a4f0f4e47211d4fec4812207e28dd3cf
4
- data.tar.gz: 3eeebc342465b151e48ebd94d01e98d2f6a1bd0194851c5a2fc50d41103553af
3
+ metadata.gz: b1ddb7223bac6b77c96253275a3fcdc39d6de169c445650df95694f9897ad25b
4
+ data.tar.gz: 33af3be7bf7dbb56b6c2ad947fa2aa157b35f63bf98e515f4b8d852fa69ff514
5
5
  SHA512:
6
- metadata.gz: 660d98bbbb542bf6a706614ab725c63f5d2e991236ff23ddaf443ec35ef2e0709677b51f4e3d94ffc9bea81f647d8135cf206513e07617710820cba2b71b7253
7
- data.tar.gz: ddeb25f094cae8ffd4d8d7b01dc022b71898a45df031a231051d2f18bfce8a1b5392b9ed4e3ae41dba4398087ab7856a3f2f0f21c74dabed382cb5151c93998d
6
+ metadata.gz: a8f6b21b1f49b69cb49693b3f157f9597542597140e96b1124f8c2c13087326d5e1a4183b353393740fa82e91e3d6e9e789c8eb74eab9688b9069129708f1265
7
+ data.tar.gz: 3b62b60389a157f0713717bb086ec40a3c4b74edbe139609fef642535cd33df84672a61b50661ffd8ac3332e839409a376a9146dc977356e7b62b1434b8fa0e6
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
 
13
13
  # SimpleCov reports
14
14
  coverage
15
+
16
+ Gemfile.lock
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # ![demo](demo.png) 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)
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
- ```rb
50
- user_avatar(current_user.name, size: 96)
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
- This sets `width` and `height` to `96px` in the SVG. Of course, you can also use CSS to make the SVG have different sizes in different places of your HTML.
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: bold #{font_size}px sans-serif; user-select: none;'>",
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, 3].map { |s| s[0].capitalize }.join
35
+ name.split(' ')[0, limit].map { |s| s[0].capitalize }.join
35
36
  end
36
37
  end
37
38
  end
@@ -1,3 +1,3 @@
1
1
  module Initials
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.2
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-14 00:00:00.000000000 Z
11
+ date: 2021-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler