initials 0.4.0 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/initials/svg.rb +9 -4
- data/lib/initials/version.rb +1 -1
- metadata +3 -15
- data/.github/workflows/ruby.yml +0 -39
- data/.gitignore +0 -16
- data/.rspec +0 -3
- data/.travis.yml +0 -7
- data/Gemfile +0 -8
- data/LICENSE.txt +0 -21
- data/README.md +0 -75
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/demo.png +0 -0
- data/initials.gemspec +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f942a7cc275315fb9857c093f062b3b0540d440c5e8cbd788d04df0866cf6544
|
4
|
+
data.tar.gz: ac219a0e72952d98fd21fa21b7a4bb12626babd7fbfcbc509767edb1b35ac423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b4291e58c69db4f26b4d4ad007e0f14f0fe7b92722c5929554fc2c2a7e2026fdb9a2d927b1775e2124963e2d8f9731896b37b43222801933d751e41896ab412
|
7
|
+
data.tar.gz: da1900a26429932d5b9186438488920e12d040bbf433a835de7ae4d274216b69e975050c8ce6720ce1566ba90b43b77e2c291ba8449949cc9c287324374df114
|
data/lib/initials/svg.rb
CHANGED
@@ -5,20 +5,23 @@ module Initials
|
|
5
5
|
attr_reader :name, :colors, :limit, :shape, :size
|
6
6
|
|
7
7
|
def initialize(name, colors: 12, limit: 3, shape: :circle, size: 32)
|
8
|
-
@name = name
|
8
|
+
@name = name.to_s.strip
|
9
9
|
@colors = colors
|
10
10
|
@limit = limit
|
11
11
|
@shape = shape
|
12
12
|
@size = size
|
13
13
|
|
14
|
-
raise Initials::Error.new("Name is not a string or empty.") unless (name.respond_to?(:to_s) && name.to_s.length > 0)
|
15
14
|
raise Initials::Error.new("Colors must be a divider of 360 e.g. 24 but not 16.") unless valid_colors?
|
16
15
|
raise Initials::Error.new("Size is not a positive integer.") unless valid_size?
|
17
16
|
end
|
18
17
|
|
18
|
+
def name
|
19
|
+
@name.empty? ? "?" : @name
|
20
|
+
end
|
21
|
+
|
19
22
|
def to_s
|
20
23
|
svg = [
|
21
|
-
"<svg width='#{size}' height='#{size}'>",
|
24
|
+
"<svg xmlns='http://www.w3.org/2000/svg' width='#{size}' height='#{size}'>",
|
22
25
|
shape == :rect ?
|
23
26
|
"<rect width='#{size}' height='#{size}' rx='#{size / 32}' ry='#{size / 32}' fill='#{fill}' />"
|
24
27
|
:
|
@@ -33,6 +36,8 @@ module Initials
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def fill
|
39
|
+
return "hsl(0, 0%, 67%)" if @name.empty?
|
40
|
+
|
36
41
|
hue_step = HUE_WHEEL / colors
|
37
42
|
char_sum = name.split("").sum do |c|
|
38
43
|
# Multiplication makes sure neighboring characters (like A and B) are one hue step apart.
|
@@ -41,7 +46,7 @@ module Initials
|
|
41
46
|
|
42
47
|
# Spin the wheel!
|
43
48
|
hue = char_sum % HUE_WHEEL
|
44
|
-
|
49
|
+
|
45
50
|
"hsl(#{hue}, 40%, 40%)"
|
46
51
|
end
|
47
52
|
|
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.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,18 +59,6 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".github/workflows/ruby.yml"
|
63
|
-
- ".gitignore"
|
64
|
-
- ".rspec"
|
65
|
-
- ".travis.yml"
|
66
|
-
- Gemfile
|
67
|
-
- LICENSE.txt
|
68
|
-
- README.md
|
69
|
-
- Rakefile
|
70
|
-
- bin/console
|
71
|
-
- bin/setup
|
72
|
-
- demo.png
|
73
|
-
- initials.gemspec
|
74
62
|
- lib/initials.rb
|
75
63
|
- lib/initials/svg.rb
|
76
64
|
- lib/initials/version.rb
|
@@ -93,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
81
|
- !ruby/object:Gem::Version
|
94
82
|
version: '0'
|
95
83
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
84
|
+
rubygems_version: 3.3.7
|
97
85
|
signing_key:
|
98
86
|
specification_version: 4
|
99
87
|
summary: Simple SVG avatars
|
data/.github/workflows/ruby.yml
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# This workflow uses actions that are not certified by GitHub.
|
2
|
-
# They are provided by a third-party and are governed by
|
3
|
-
# separate terms of service, privacy policy, and support
|
4
|
-
# documentation.
|
5
|
-
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
-
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
-
|
8
|
-
name: Ruby
|
9
|
-
|
10
|
-
on:
|
11
|
-
push:
|
12
|
-
branches: [ main ]
|
13
|
-
pull_request:
|
14
|
-
branches: [ main ]
|
15
|
-
|
16
|
-
jobs:
|
17
|
-
test:
|
18
|
-
|
19
|
-
runs-on: ubuntu-latest
|
20
|
-
strategy:
|
21
|
-
matrix:
|
22
|
-
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
-
|
24
|
-
steps:
|
25
|
-
- uses: actions/checkout@v2
|
26
|
-
- name: Set up Ruby
|
27
|
-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
-
# uses: ruby/setup-ruby@v1
|
30
|
-
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
-
with:
|
32
|
-
ruby-version: ${{ matrix.ruby-version }}
|
33
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
-
- name: Run tests and publish code coverage
|
35
|
-
uses: paambaati/codeclimate-action@v2.7.5
|
36
|
-
env:
|
37
|
-
CC_TEST_REPORTER_ID: 9c690ab71ab481ac45785c4010ff30f93a45774e5ad6f03ec448b6e2b5bc39b4
|
38
|
-
with:
|
39
|
-
coverageCommand: bundle exec rake
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2021 Thomas Hutterer
|
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
DELETED
@@ -1,75 +0,0 @@
|
|
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
|
-
|
3
|
-
Don't want to implement user avatar uploads but still have basic avatars to distinguish users and brigthen up your app?
|
4
|
-
|
5
|
-
Use colorful SVGs as user avatars in any Ruby and Rails application.
|
6
|
-
|
7
|
-
![demo](demo.png)
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Add this line to your application's Gemfile:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem 'initials'
|
15
|
-
```
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install initials
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
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.
|
29
|
-
|
30
|
-
### Rails
|
31
|
-
|
32
|
-
No special configuration is required to work with Ruby on Rails, but for your convinience, you can add this to your `app/helpers/application_helper.rb`:
|
33
|
-
|
34
|
-
```ruby
|
35
|
-
def user_avatar(name, **options)
|
36
|
-
Initials.svg(name, **options)
|
37
|
-
end
|
38
|
-
```
|
39
|
-
|
40
|
-
Now you can create SVGs in all views:
|
41
|
-
|
42
|
-
```erb
|
43
|
-
<%= user_avatar(current_user.name) %>
|
44
|
-
```
|
45
|
-
|
46
|
-
Initials automatically marks its created SVG strings as `html_safe`.
|
47
|
-
|
48
|
-
### Options
|
49
|
-
|
50
|
-
You can pass the following options into `Initials.svg` or your `user_avatar` helper:
|
51
|
-
|
52
|
-
```ruby
|
53
|
-
user_avatar(current_user.name,
|
54
|
-
colors: 8, # number of different colors, default: 12
|
55
|
-
limit: 1, # maximal initials length, default: 3
|
56
|
-
shape: :rect, # background shape, default: :cirlce
|
57
|
-
size: 96 # SVG height and width in pixel, default: 32
|
58
|
-
)
|
59
|
-
```
|
60
|
-
|
61
|
-
Of course, you can also use CSS to make the SVG have different sizes in different places of your HTML.
|
62
|
-
|
63
|
-
## Development
|
64
|
-
|
65
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
-
|
67
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
-
|
69
|
-
## Contributing
|
70
|
-
|
71
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/thutterer/initials.
|
72
|
-
|
73
|
-
## License
|
74
|
-
|
75
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "initials"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/demo.png
DELETED
Binary file
|
data/initials.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "initials/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "initials"
|
8
|
-
spec.version = Initials::VERSION
|
9
|
-
spec.authors = ["Thomas Hutterer"]
|
10
|
-
spec.email = ["tohu@tuta.io"]
|
11
|
-
|
12
|
-
spec.summary = "Simple SVG avatars"
|
13
|
-
spec.description = "Use colorful SVGs as user avatars in any Ruby and Rails application."
|
14
|
-
spec.homepage = "https://github.com/thutterer/initials"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Specify which files should be added to the gem when it is released.
|
18
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
-
end
|
22
|
-
spec.bindir = "exe"
|
23
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = ["lib"]
|
25
|
-
|
26
|
-
spec.add_development_dependency "bundler"
|
27
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
-
end
|