Class: Avo::Fields::GravatarField
- Defined in:
- lib/avo/fields/gravatar_field.rb
Defined Under Namespace
Classes: IndexComponent, ShowComponent
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#link_to_resource ⇒ Object
readonly
Returns the value of attribute link_to_resource.
-
#rounded ⇒ Object
readonly
Returns the value of attribute rounded.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #format_using, #help, #id, #index_text_align, #model, #null_values, #nullable, #panel_name, #readonly, #required, #resource, #sortable, #stacked, #updatable, #user, #view, #visible
Attributes included from Concerns::HasHTMLAttributes
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
-
#initialize(id, **args, &block) ⇒ GravatarField
constructor
A new instance of GravatarField.
- #md5 ⇒ Object
- #to_image ⇒ Object
Methods inherited from BaseField
#component_for_view, #custom?, #custom_name?, #database_id, #default_name, #fill_field, #has_own_panel?, #hidden_in_reflection?, #hydrate, #model_errors, #name, #placeholder, #plural_name, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?, #visible_in_reflection?
Methods included from FieldExtensions::HasFieldName
Methods included from Concerns::HasDefault
Methods included from Concerns::IsReadonly
Methods included from Concerns::IsRequired
Methods included from Concerns::HasHTMLAttributes
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on, #show_on_create, #show_on_update, #visible_on?
Methods included from Concerns::IsResourceItem
#is_field?, #is_main_panel?, #is_panel?, #is_sidebar?, #is_tab?, #is_tab_group?, #is_tool?
Constructor Details
#initialize(id, **args, &block) ⇒ GravatarField
Returns a new instance of GravatarField.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/avo/fields/gravatar_field.rb', line 12 def initialize(id, **args, &block) args[:name] ||= "Avatar" super(id, **args, &block) hide_on [:edit, :new] @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false @rounded = args[:rounded].nil? ? true : args[:rounded] @size = args[:size].present? ? args[:size].to_i : 32 @default = args[:default].present? ? ERB::Util.url_encode(args[:default]).to_s : "" end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
10 11 12 |
# File 'lib/avo/fields/gravatar_field.rb', line 10 def default @default end |
#link_to_resource ⇒ Object (readonly)
Returns the value of attribute link_to_resource.
7 8 9 |
# File 'lib/avo/fields/gravatar_field.rb', line 7 def link_to_resource @link_to_resource end |
#rounded ⇒ Object (readonly)
Returns the value of attribute rounded.
8 9 10 |
# File 'lib/avo/fields/gravatar_field.rb', line 8 def rounded @rounded end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
9 10 11 |
# File 'lib/avo/fields/gravatar_field.rb', line 9 def size @size end |
Instance Method Details
#md5 ⇒ Object
25 26 27 28 29 |
# File 'lib/avo/fields/gravatar_field.rb', line 25 def md5 return if value.blank? Digest::MD5.hexdigest(value.strip.downcase) end |
#to_image ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/avo/fields/gravatar_field.rb', line 31 def to_image = { default: "", size: 340 } query = .map { |key, value| "#{key}=#{value}" }.join("&") URI::HTTPS.build(host: "www.gravatar.com", path: "/avatar/#{md5}", query: query).to_s end |