Class: Hyrax::Forms::Admin::Appearance

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Defined in:
app/forms/hyrax/forms/admin/appearance.rb

Overview

An object to model and persist the form data for the appearance customization menu

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Appearance

Returns a new instance of Appearance.

Parameters:

  • attributes (Hash) (defaults to: {})

    the list of parameters from the form


10
11
12
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 10

def initialize(attributes = {})
  @attributes = attributes
end

Class Method Details

.color_paramsObject

A list of parameters that are related to custom colors


105
106
107
108
109
110
111
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 105

def self.color_params
  [:header_background_color,
   :header_text_color,
   :link_color,
   :footer_link_color,
   :primary_button_background_color]
end

.model_nameObject

This allows this object to route to the correct path


18
19
20
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 18

def self.model_name
  ActiveModel::Name.new(self, Hyrax, "Hyrax::Admin::Appearance")
end

.permitted_paramsObject

Override this method if your form takes more than just the color_params


23
24
25
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 23

def self.permitted_params
  color_params
end

Instance Method Details

The color for links in the footer


53
54
55
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 53

def footer_link_color
  block_for('footer_link_color', '#ffebcd')
end

#header_background_colorObject

The color for the background of the header and footer bars


38
39
40
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 38

def header_background_color
  block_for('header_background_color', '#3c3c3c')
end

#header_text_colorObject

The color for the text in the header bar


43
44
45
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 43

def header_text_color
  block_for('header_text_color', '#dcdcdc')
end

The color links


48
49
50
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 48

def link_color
  block_for('link_color', '#2e74b2')
end

#persisted?Boolean

Required to back a form (for route determination)

Returns:

  • (Boolean)

33
34
35
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 33

def persisted?
  true
end

#primary_button_active_background_colorObject

The color for the background of active “primary” buttons


78
79
80
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 78

def primary_button_active_background_color
  darken_color(primary_button_background_color, 0.1)
end

#primary_button_active_border_colorObject

The color for the border of active “primary” buttons


83
84
85
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 83

def primary_button_active_border_color
  darken_color(primary_button_border_color, 0.12)
end

#primary_button_background_colorObject

The background color for “primary” buttons


58
59
60
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 58

def primary_button_background_color
  block_for('primary_button_background_color', '#286090')
end

#primary_button_border_colorObject

The border color for “primary” buttons


63
64
65
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 63

def primary_button_border_color
  @primary_button_border ||= darken_color(primary_button_background_color, 0.05)
end

#primary_button_focus_background_colorObject

The color for the background of focused “primary” buttons


88
89
90
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 88

def primary_button_focus_background_color
  darken_color(primary_button_background_color, 0.1)
end

#primary_button_focus_border_colorObject

The color for the border of focused “primary” buttons


93
94
95
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 93

def primary_button_focus_border_color
  darken_color(primary_button_border_color, 0.25)
end

#primary_button_hover_background_colorObject

The mouse over color for “primary” buttons


68
69
70
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 68

def primary_button_hover_background_color
  darken_color(primary_button_background_color, 0.1)
end

#primary_button_hover_border_colorObject

The mouse over color for the border of “primary” buttons


73
74
75
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 73

def primary_button_hover_border_color
  darken_color(primary_button_border_color, 0.12)
end

#to_keyObject

Required to back a form


28
29
30
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 28

def to_key
  []
end

#update!Object

Persist the form values


98
99
100
101
102
# File 'app/forms/hyrax/forms/admin/appearance.rb', line 98

def update!
  self.class.color_params.each do |field|
    update_block(field, attributes[field]) if attributes[field]
  end
end