avatari 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 58d6762f5d16be413ff91cf6cef2aed554b7e61d1123c3c0e916ec2b8c658b37
4
+ data.tar.gz: e51d50a4bd162966c840d6adf724b87957a8516751da32766936bb8d43e52646
5
+ SHA512:
6
+ metadata.gz: 74b7f808676b6115e4f25c94a247b4e98551f8a2191e02a3c5733a9bd26dd57f1f8a14d5673992325aa0612b2b5b96c72fb53230c37352d31c0396534fa9b583
7
+ data.tar.gz: d3050c08d7f3faf5ccba1adc8a823d9d7e7c7ddbe798985db0dab8acfe1830c9df3a6f8e6133001b8971187bc1878ab3a12be06a4bfe997b74c2f325aba9a2ec
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ### master
4
+
5
+ * nothing yet
6
+
7
+ ### 1.0.0 - 2018/01/06
8
+
9
+ * initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jonas Hübotter
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,184 @@
1
+ # Avatari
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/avatari.svg)](https://badge.fury.io/rb/avatari) <img src="https://travis-ci.org/jonhue/avatari.svg?branch=master" />
4
+
5
+ Avatari extends [CarrierWave](https://github.com/carrierwaveuploader/carrierwave) to make adding avatars to ActiveRecord models super simple.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ * [Assets](#assets)
14
+ * [CarrierWave](#carrierwave)
15
+ * [Models](#models)
16
+ * [Views](#views)
17
+ * [To Do](#to-do)
18
+ * [Contributing](#contributing)
19
+ * [Contributors](#contributors)
20
+ * [Semantic versioning](#semantic-versioning)
21
+ * [License](#license)
22
+
23
+ ---
24
+
25
+ ## Installation
26
+
27
+ Avatari works with Rails 5 onwards. You can add it to your `Gemfile` with:
28
+
29
+ ```ruby
30
+ gem 'avatari'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle
36
+
37
+ Or install it yourself as:
38
+
39
+ $ gem install avatari
40
+
41
+ If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
42
+
43
+ ```ruby
44
+ gem 'avatari', github: 'jonhue/avatari'
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ### Assets
50
+
51
+ To render Avatari avatars, you have to require the necessary assets to be added to your asset pipeline:
52
+
53
+ ```js
54
+ //= require avitari
55
+ ```
56
+
57
+ ```css
58
+ /*
59
+ *= require avitari.min
60
+ */
61
+ ```
62
+
63
+ **Note:** You can override the [styles](vendor/assets/stylesheets/avitari.sass) when you are looking for a custom integration.
64
+
65
+ ### CarrierWave
66
+
67
+ To backup CarrierWave add an `avatar` column (`string`) to every ActiveRecord model's database table you are using Avatari on.
68
+
69
+ The `avatar` attribute can be used like any other CarrierWave instance.
70
+
71
+ Avatari makes some assumptions about your CarrierWave integration. For Avatari to work properly, [Fog](https://github.com/carrierwaveuploader/carrierwave#fog) and [MiniMagick](https://github.com/minimagick/minimagick) have to be set up.
72
+
73
+ Avatari preprocesses uploaded avatars:
74
+
75
+ * `raw` (800x800)
76
+ * `big` (350x350)
77
+ * `medium` (100x100)
78
+ * `small` (75x75)
79
+ * `tiny` (50x50)
80
+ * `mini` (40x40)
81
+
82
+ It accepts images in `jpg`, `jpeg` and `png` format.
83
+
84
+ ### Models
85
+
86
+ You can add Avatari to an ActiveRecord model:
87
+
88
+ ```ruby
89
+ class User < ApplicationRecord
90
+ avatari
91
+ end
92
+ ```
93
+
94
+ You can also pass an `initials` option, which specifies an attribute or instance method that returns initials used for placeholder avatars if no custom avatar has been uploaded yet:
95
+
96
+ ```ruby
97
+ class User < ApplicationRecord
98
+ avatari :initials
99
+
100
+ def initials
101
+ self.first_name[0] + self.last_name[0]
102
+ end
103
+ end
104
+ ```
105
+
106
+ **Note:** When [rendering](#views) an avatar and you did not provide the `initials` option + no avatar has been uploaded yet, the helper method will return `false`.
107
+
108
+ To add custom background colors to your placeholder avatars, pass the `colors` option:
109
+
110
+ ```ruby
111
+ class User < ApplicationRecord
112
+ avatari colors: ['#000000', '#333333']
113
+ end
114
+ ```
115
+
116
+ For every instance of the class, Avatari will pick a sample of the array of provided background colors. The default for every instance is `#000000`.
117
+
118
+ To attach a picked color to a given record permanently, you will also have to add an `avatar_color` string column to your database tables.
119
+
120
+ ### Views
121
+
122
+ To render an avatar in your view, utilize the `avatari` helper method:
123
+
124
+ ```haml
125
+ = avatari current_user
126
+ ```
127
+
128
+ You can also specify a size:
129
+
130
+ ```haml
131
+ = avatari current_user, :tiny
132
+ ```
133
+
134
+ The `size` of the rendered avatar defaults to `:medium`.
135
+
136
+ ---
137
+
138
+ ## To Do
139
+
140
+ [Here](https://github.com/jonhue/avatari/projects/1) is the full list of current projects.
141
+
142
+ To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/avatari/issues/new).
143
+
144
+ ---
145
+
146
+ ## Contributing
147
+
148
+ We hope that you will consider contributing to Avatari. Please read this short overview for some information about how to get started:
149
+
150
+ [Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
151
+
152
+ ### Contributors
153
+
154
+ Give the people some :heart: who are working on this project. See them all at:
155
+
156
+ https://github.com/jonhue/avatari/graphs/contributors
157
+
158
+ ### Semantic Versioning
159
+
160
+ Avatari follows Semantic Versioning 2.0 as defined at http://semver.org.
161
+
162
+ ## License
163
+
164
+ MIT License
165
+
166
+ Copyright (c) 2017 Jonas Hübotter
167
+
168
+ Permission is hereby granted, free of charge, to any person obtaining a copy
169
+ of this software and associated documentation files (the "Software"), to deal
170
+ in the Software without restriction, including without limitation the rights
171
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
172
+ copies of the Software, and to permit persons to whom the Software is
173
+ furnished to do so, subject to the following conditions:
174
+
175
+ The above copyright notice and this permission notice shall be included in all
176
+ copies or substantial portions of the Software.
177
+
178
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
179
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
180
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
181
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
182
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
183
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
184
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ module Avatari
2
+ module AvatarHelper
3
+
4
+ def avatari object, version = :medium
5
+ if object.avatar?
6
+ image_tag object.avatar.url, class: 'avatari avatari--' + version.to_s
7
+ elsif !object.class.avatari_initials.nil?
8
+ render partial: 'avatari/avatar', locals: { object: object, version: version.to_s }
9
+ else
10
+ false
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ module Avatari
2
+ module Model
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ def avatari_color
7
+ if defined?(self.avatar_color)
8
+ self.update_attributes(avatar_color: self.class.avatari_colors.sample) if self.avatar_color.nil?
9
+ self.avatar_color
10
+ else
11
+ self.class.avatari_colors.sample
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+
17
+ attr_accessor :avatari_colors
18
+ attr_accessor :avatari_initials
19
+
20
+ def avatari initials = nil, options = {}
21
+ defaults = {
22
+ colors: nil
23
+ }
24
+ defaults.merge! options
25
+
26
+ self.avatari_colors = options[:colors] || ['#000000']
27
+ self.avatari_initials = initials
28
+
29
+ serialize :avatar_color, Array
30
+ mount_uploader :avatar, ::Avatari::AvatarUploader
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,48 @@
1
+ class Avatari::AvatarUploader < CarrierWave::Uploader::Base
2
+
3
+ # Include MiniMagick support:
4
+ include CarrierWave::MiniMagick
5
+
6
+ # Choose AWS as file storage:
7
+ storage :fog
8
+
9
+ # Override the directory where uploaded files will be stored.
10
+ # This is a sensible default for uploaders that are meant to be mounted:
11
+ def store_dir
12
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
13
+ end
14
+
15
+ # Process files as they are uploaded:
16
+ process scale: [800, 800]
17
+
18
+ # Create different versions of your uploaded files:
19
+ version :raw do
20
+ process resize_to_fill: [800, 800]
21
+ end
22
+
23
+ version :big, from_version: :raw do
24
+ process resize_to_fill: [350, 350]
25
+ end
26
+
27
+ version :medium, from_version: :big do
28
+ process resize_to_fill: [100, 100]
29
+ end
30
+
31
+ version :small, from_version: :medium do
32
+ process resize_to_fill: [75, 75]
33
+ end
34
+
35
+ version :tiny, from_version: :small do
36
+ process resize_to_fill: [50, 50]
37
+ end
38
+
39
+ version :mini, from_version: :tiny do
40
+ process resize_to_fill: [40, 40]
41
+ end
42
+
43
+ # White list of extensions which are allowed to be uploaded:
44
+ def extension_whitelist
45
+ %w(jpg jpeg png)
46
+ end
47
+
48
+ end
@@ -0,0 +1,3 @@
1
+ <div class="<%= 'avatari avatari--' + version %>" style="background: <%= object.avatari_color %>;">
2
+ <span class="initials"><%= object.send(object.class.avatari_initials) %></span>
3
+ </div>
@@ -0,0 +1,8 @@
1
+ require 'avatari/version'
2
+
3
+ module Avatari
4
+
5
+ require 'avatari/engine'
6
+ require 'avatari/railtie'
7
+
8
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails/railtie'
2
+
3
+ module Avatari
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/railtie'
2
+
3
+ module Avatari
4
+ class Railtie < Rails::Railtie
5
+
6
+ initializer 'avatari.active_record' do
7
+ ActiveSupport.on_load :active_record do
8
+ include Avatari::Model
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Avatari
2
+
3
+ VERSION = '1.0.0'
4
+
5
+ end
@@ -0,0 +1 @@
1
+ .avatari--mini{width:px(40);height:px(40);display:flex;justify-content:center;align-items:center;border-radius:50%;-webkit-border-radius:50%;-moz-border-radius:50%}.avatari--mini>.initials{font-size:px(16);line-height:1;color:white;font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";font-weight:600}.avatari--tiny{width:px(50);height:px(50);display:flex;justify-content:center;align-items:center;border-radius:50%;-webkit-border-radius:50%;-moz-border-radius:50%}.avatari--tiny>.initials{font-size:px(16);line-height:1;color:white;font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";font-weight:600}.avatari--small{width:px(75);height:px(75);display:flex;justify-content:center;align-items:center;border-radius:50%;-webkit-border-radius:50%;-moz-border-radius:50%}.avatari--small>.initials{font-size:px(24);line-height:1;color:white;font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";font-weight:600}.avatari{width:px(100);height:px(100);display:flex;justify-content:center;align-items:center;border-radius:50%;-webkit-border-radius:50%;-moz-border-radius:50%}.avatari>.initials{font-size:px(32);line-height:1;color:white;font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";font-weight:600}.avatari--big{width:px(350);height:px(350);display:flex;justify-content:center;align-items:center;border-radius:50%;-webkit-border-radius:50%;-moz-border-radius:50%}.avatari--big>.initials{font-size:px(74);line-height:1;color:white;font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";font-weight:600}.avatari--raw{width:px(800);height:px(800);display:flex;justify-content:center;align-items:center;border-radius:50%;-webkit-border-radius:50%;-moz-border-radius:50%}.avatari--raw>.initials{font-size:px(160);line-height:1;color:white;font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";font-weight:600}
@@ -0,0 +1,28 @@
1
+ @mixin avatar($size, $font)
2
+ width: $size
3
+ height: $size
4
+ display: flex
5
+ justify-content: center
6
+ align-items: center
7
+ border-radius: 50%
8
+ -webkit-border-radius: 50%
9
+ -moz-border-radius: 50%
10
+ & > .initials
11
+ font-size: $font
12
+ line-height: 1
13
+ color: white
14
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"
15
+ font-weight: 600
16
+
17
+ .avatari--mini
18
+ @include avatar(px(40), px(16))
19
+ .avatari--tiny
20
+ @include avatar(px(50), px(16))
21
+ .avatari--small
22
+ @include avatar(px(75), px(24))
23
+ .avatari--medium
24
+ @include avatar(px(100), px(32))
25
+ .avatari--big
26
+ @include avatar(px(350), px(74))
27
+ .avatari--raw
28
+ @include avatar(px(800), px(160))
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avatari
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonas Hübotter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.52'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.52'
83
+ description: Add avatars to ActiveRecord models.
84
+ email: me@jonhue.me
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - CHANGELOG.md
90
+ - LICENSE
91
+ - README.md
92
+ - app/helpers/avatari/avatar_helper.rb
93
+ - app/models/concerns/avatari/model.rb
94
+ - app/uploaders/avatari/avatar_uploader.rb
95
+ - app/views/avatari/_avatar.html.erb
96
+ - lib/avatari.rb
97
+ - lib/avatari/engine.rb
98
+ - lib/avatari/railtie.rb
99
+ - lib/avatari/version.rb
100
+ - vendor/assets/stylesheets/avatari.min.css
101
+ - vendor/assets/stylesheets/avatari.sass
102
+ homepage: https://github.com/jonhue/avatari
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '2.3'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.4
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Add avatars to ActiveRecord models
126
+ test_files: []