initial.js is a simple jQuery plugin to make Gmail-like text avatars for profile pictures using SVG.
initialjs-rails is a wrapper to easily include it in your Rails projects using the assets pipeline.
Add this gem to your Gemfile:
gem 'initialjs-rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install initialjs-rails
After that add the following directive to your Javascript manifest file (application.js), after the //= require jquery
:
//= require initial
Add this to your application.js after page is ready:
$('.initialjs-avatar').initial();
And finally, in your views, tag your class with initialjs-avatar
class. You can use data-attributes as described in initial.js. Or you can use the helper below.
Enjoy.
For extra simplicity, you can use this helper in your view to generate your avatar image from your model. In the following examples we'll use User, any model responding to :name
or passing String will do. You can learn the options available and their defaults directly from the examples:
avatar_image(@user) or avatar_image(@user.full_name) # => 100x100 image with round corners
avatar_image(@user, size: 32) # => 32x32 image with round corners
avatar_image(@user, count: 2) # => Number of characherts to be shown in the picture
avatar_image(@user, color: black or #000) # => Color of the text
avatar_image(@user, class: 'extra_class') # => add an extra CSS class to <img/> tag
avatar_image(@user, round_corners: false) # => disable round corners
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
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
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
initialjs-rails 0.2.0 == initial.js 0.2.0
Regarding intermediate versions between initialjs releases, an extra number will be used. For example, 0.2.0.1
version reflects some change within initialjs-rails, still using initialjs' 0.2.0
version.
- Fork it ( https://github.com/[my-github-username]/initialjs-rails/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Follow the code of conduct (CODE_OF_CONDUCT.md)
- Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request