Method: MotionPrime::AbstractCollectionSection#cell_section_styles

Defined in:
motion-prime/sections/abstract_collection.rb

#cell_section_styles(section) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'motion-prime/sections/abstract_collection.rb', line 118

def cell_section_styles(section)
  # type = [`cell`, `header`, `field`]

  # UserFormSection example: field :email, type: :string
  # form_name = `user`
  # type = `field`
  # field_name = `email`
  # field_type = `string_field`

  # CategoriesTableSection example: table is a `CategoryTableSection`, cell is a `CategoryTitleSection`, element :icon, type: :image
  # table_name = `categories`
  # type = `cell` (always true)
  # table_cell_section_name = `title`
  type = section.respond_to?(:cell_type) ? section.cell_type : 'cell'
  suffixes = [type]
  if section.is_a?(BaseFieldSection)
    suffixes << section.default_name
  end

  styles = {}
  # table: base_table_<type>
  # form: base_form_<type>, base_form_<field_type>
  styles[:common] = build_styles_chain(collection_styles[:common], suffixes)
  if section.is_a?(BaseFieldSection)
    # form cell: _<type>_<field_name> = `_field_email`
    suffixes << :"#{type}_#{section.name}" if section.name
  elsif section.respond_to?(:cell_section_name) # cell section came from table
    # table cell: _<table_cell_section_name> = `_title`
    suffixes << section.cell_section_name
  end
  # table: <table_name>_table_<type>, <table_name>_table_<table_cell_section_name> = `categories_table_cell`, `categories_table_title`
  # form: <form_name>_form_<type>, <form_name>_form_<field_type>, user_form_<type>_email = `user_form_field`, `user_form_string_field`, `user_form_field_email`
  styles[:specific] = build_styles_chain(collection_styles[:specific], suffixes)

  container_options_styles = section.container_options[:styles]
  if container_options_styles.present?
    styles[:specific] += Array.wrap(container_options_styles)
  end

  styles
end