Module: ActsAsAvatar::Helper
- Includes:
- Scrubber
- Defined in:
- lib/acts_as_avatar/helper.rb
Instance Method Summary collapse
- #acts_as_avatar_tag(object, name: nil, size: nil, **options) ⇒ Object
- #github_avatar_tag(size:, **options) ⇒ Object
- #icodi_avatar_tag(text, size:, **options) ⇒ Object
- #initial_avatar_tag(text, size:, **options) ⇒ Object
- #initials_tag(text, size:, **options) ⇒ Object
- #inline_avatar_tag(object, size:, name: nil, **options) ⇒ Object
Methods included from Scrubber
Instance Method Details
#acts_as_avatar_tag(object, name: nil, size: nil, **options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/acts_as_avatar/helper.rb', line 13 def acts_as_avatar_tag(object, name: nil, size: nil, **) size = size.presence || ActsAsAvatar.configuration.avatar_size current_avatar = object.current_avatar blob = current_avatar.blob if current_avatar.attached? if blob.content_type == "image/svg+xml" render_svg blob, size, else image_tag current_avatar.variant(resize_to_fill: [size, size]), ** end else inline_avatar_tag(object, name: name, size: size, **) end rescue StandardError => e puts e.inspect puts e.backtrace.inspect "".html_safe end |
#github_avatar_tag(size:, **options) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/acts_as_avatar/helper.rb', line 69 def github_avatar_tag(size:, **) opts = .extract!(:github_complexity, :github_render_method, :github_rounded_circle).compact opts = ActsAsAvatar.configuration..merge(opts) ActsAsAvatar::GithubAvatar.instance.random_svg_avatar( size: size, github_complexity: opts[:github_complexity], github_render_method: opts[:github_render_method], github_rounded_circle: opts[:github_rounded_circle] ).html_safe end |
#icodi_avatar_tag(text, size:, **options) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/acts_as_avatar/helper.rb', line 82 def icodi_avatar_tag(text, size:, **) # # https://github.com/DannyBen/icodi # # Default value: # # custom attribute: # # rounded_circle: nil # # pixels: 5 # mirror: :x # color: # density: 0.5 # stroke: 0.1 # jitter: 0 # background: #fff # id: icodi # # SVG template to use. # Can be :default, :html or a path to a file. Read more on Victor SVG Templates. # # template: default opts = .extract!(:pixels, :density, :mirror, :color, :stroke, :jitter, :id, :template, :rounded_circle, :background) pixels = opts[:pixels] || 8 density = opts[:density] || 0.33 svg = Icodi.new text, size: size, pixels: pixels, density: density, **opts svg.render.html_safe end |
#initial_avatar_tag(text, size:, **options) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/acts_as_avatar/helper.rb', line 50 def initial_avatar_tag(text, size:, **) opts = .extract!(:colors, :text_color, :font_weight, :font_family).compact limit = [:limit] || 1 image_tag InitialAvatar.avatar_data_uri(text.first(limit), size: size, **opts), ** end |
#initials_tag(text, size:, **options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/acts_as_avatar/helper.rb', line 58 def initials_tag(text, size:, **) # # number of different colors, default: 12 # maximal initials length, default: 3 # background shape, default: :cirlce # opts = .extract!(:colors, :limit, :shape).compact Initials.svg text, size: size, **opts end |
#inline_avatar_tag(object, size:, name: nil, **options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/acts_as_avatar/helper.rb', line 34 def inline_avatar_tag(object, size:, name: nil, **) name = name.presence || ActsAsAvatar.configuration.avatar_name text = object.send(name.to_sym) inline_svg_engine = object.class.inline_svg_engine.to_sym case inline_svg_engine.to_sym when :initial_avatar initial_avatar_tag(text, size: size, **) when :icodi_avatar icodi_avatar_tag(text, size: size, **) when :initials initials_tag(text, size: size, **) end end |