克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Gem Version Build Status

Rpictogrify

Ruby version of the pictogrify to generate unique pictograms

Avatar

Installation

Add rpictogrify to application's Gemfile:

gem 'rpictogrify'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rpictogrify

Configuration

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

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

include Rpictogrify::Helper

Then you can use the following methods in views.

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})    #=> '<img class="avatar" src="/system/rpictogrify/1/monsters/1313467160.svg" alt="jim" />'
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

class User
  include Rpictogrify::Extension

  rpictogrify_on :username, theme: -> { gender == :male ? :avataars_male : :avataars_female }
  # rpictogrify_on :username, theme: :avataars_male
end

Then you have the following methods in user

@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.

Copyright 2021 jimcheung Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Ruby version of the pictogrify to generate unique pictograms 展开 收起
Ruby
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化