Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jinhucheung/rpictogrify
Ruby version of the pictogrify to generate unique pictograms
https://github.com/jinhucheung/rpictogrify
avataaars avatar avatar-generator pictogram pictogrify rails ruby
Last synced: about 1 month ago
JSON representation
Ruby version of the pictogrify to generate unique pictograms
- Host: GitHub
- URL: https://github.com/jinhucheung/rpictogrify
- Owner: jinhucheung
- License: mit
- Created: 2020-12-29T14:39:53.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-24T16:04:42.000Z (over 2 years ago)
- Last Synced: 2024-11-29T17:45:11.789Z (about 2 months ago)
- Topics: avataaars, avatar, avatar-generator, pictogram, pictogrify, rails, ruby
- Language: Ruby
- Homepage: https://github.com/jinhucheung/rpictogrify
- Size: 89.8 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
[![Gem Version](https://badge.fury.io/rb/rpictogrify.svg)](https://badge.fury.io/rb/rpictogrify)
[![Build Status](https://travis-ci.org/jinhucheung/rpictogrify.svg?branch=master)](https://travis-ci.org/jinhucheung/rpictogrify)
Rpictogrify
Ruby version of the pictogrify to generate unique pictograms
## Installation
Add `rpictogrify` to application's Gemfile:
```
gem 'rpictogrify'
```And then execute:
```
$ bundle install
```Or install it yourself as:
```
$ gem install rpictogrify
```## Configuration
```ruby
Rpictogrify.configure do
# default theme, one of these themes: avataars_female, avataars_male, male_flat, monsters. default is :monsters
self.theme = :monsters
# pictogram directory. default is 'public/system'
self.base_path = 'public/system'
# register a custome theme with assets. assets see assets/themes
self.register_theme :custom, assets_path: 'vendor/assets/rpictogrify/themes/custom'
end
```## Usage
```ruby
Rpictogrify.generate 'jim.cheung' #=> 'public/system/rpictogrify/1/monsters/1313467160.svg'
Rpictogrify.generate 'jim.cheung', theme: :avataars_male #=> 'public/system/rpictogrify/1/avataars_male/1313467160.svg'
Rpictogrify.generate 'jim.cheung', theme: :custom #=> 'public/system/rpictogrify/1/custom/1313467160.svg', use custom theme
```### Controller / View
There is a helper for this, you need to include `Rpictogrify::Helper` in your controller or helper. e.g. `ApplicationHelper`
```ruby
include Rpictogrify::Helper
```Then you can use the following methods in views.
```ruby
rpictogrify_for('jim', theme: :monsters) #=> 'public/system/rpictogrify/1/monsters/1313467160.svg'
rpictogrify_url('jim') #=> '/system/rpictogrify/1/monsters/1313467160.svg'
rpictogrify_tag('jim', html: {class: :avatar}) #=> ''
rpictogrify_url_for('public/system/rpictogrify/1/monsters/1313467160.svg') #=> '/system/rpictogrify/1/monsters/1313467160.svg'
```### Model
You can include `Rpictogrify::Extension` in your model class. e.g. `User` model
```ruby
class User
include Rpictogrify::Extensionrpictogrify_on :username, theme: -> { gender == :male ? :avataars_male : :avataars_female }
# rpictogrify_on :username, theme: :avataars_male
end
```Then you have the following methods in user
```ruby
@user.rpictogrify_path #=> 'public/system/rpictogrify/1/monsters/1313467160.svg'
@user.rpictogrify_url #=> '/system/rpictogrify/1/monsters/1313467160.svg'
```## Contributing
Bug report or pull request are welcome.
1. Fork it
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)Please write unit test with your code if necessary.
## License
The gem is available as open source under the terms of the [MIT License](MIT-LICENSE).