代码拉取完成,页面将自动刷新
Ruby version of the pictogrify to generate unique pictograms
Add rpictogrify
to application's Gemfile:
gem 'rpictogrify'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install rpictogrify
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
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
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'
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'
Bug report or pull request are welcome.
Please write unit test with your code if necessary.
The gem is available as open source under the terms of the MIT License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。