The `use_helpers` method was added in ViewComponent 3.8.0, and it's included by default in all components since version 3.11.0. Note we sometimes delegated the `can?` method to the controller instead of the helpers, for no particularly reason. We're unifying that code as well.
31 lines
771 B
Ruby
31 lines
771 B
Ruby
class Shared::AvatarComponent < ApplicationComponent
|
|
attr_reader :record, :given_options
|
|
use_helpers :avatar_image
|
|
|
|
def initialize(record, **given_options)
|
|
@record = record
|
|
@given_options = given_options
|
|
end
|
|
|
|
private
|
|
|
|
def default_options
|
|
{ background_color: colors[seed % colors.size] }
|
|
end
|
|
|
|
def options
|
|
default_options.merge(given_options)
|
|
end
|
|
|
|
def colors
|
|
["#16836d", "#12826c", "#896f06", "#a06608", "#1e8549", "#1e8549", "#b35e14",
|
|
"#c75000", "#207ab6", "#2779b0", "#de2f1b", "#c0392b", "#9b59b6", "#8e44ad",
|
|
"#6c767f", "#34495e", "#2c3e50", "#66797a", "#697677", "#d82286", "#c93b8e",
|
|
"#db310f", "#727755", "#8a6f3d", "#8a6f3d", "#a94136"]
|
|
end
|
|
|
|
def seed
|
|
record.id
|
|
end
|
|
end
|