Module: ElaineCrud::LayoutCalculation
- Extended by:
- ActiveSupport::Concern
- Included in:
- BaseController
- Defined in:
- lib/elaine_crud/layout_calculation.rb
Overview
Methods for calculating and customizing layout and grid structure Handles column widths, row layouts, and field positioning
Instance Method Summary collapse
-
#calculate_layout(content, fields) ⇒ Array<Array<Hash>>
Calculate layout structure for a specific record.
-
#calculate_layout_header(fields) ⇒ Array<Hash>
Calculate layout header structure defining column sizes and titles.
Instance Method Details
#calculate_layout(content, fields) ⇒ Array<Array<Hash>>
Calculate layout structure for a specific record
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/elaine_crud/layout_calculation.rb', line 14 def calculate_layout(content, fields) # Default implementation: single row with all fields, each taking 1 column and 1 row row = fields.map do |field_name| { field_name: field_name, colspan: 1, rowspan: 1 } end [row] # Return single row end |
#calculate_layout_header(fields) ⇒ Array<Hash>
Calculate layout header structure defining column sizes and titles
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/elaine_crud/layout_calculation.rb', line 34 def calculate_layout_header(fields) # Default implementation: flexible columns that can expand to fit content # Using minmax() allows columns to grow beyond their base size when content requires it # Note: Create a new array to avoid mutating the input all_fields = fields + ["ROW-ACTIONS"] all_fields.map do |field_name| width = case field_name.to_s when 'id' then "max-content" when 'email' then "minmax(180px, 2fr)" when 'ROW-ACTIONS' then "max-content" else "minmax(100px, 1fr)" end { width: width, field_name: field_name } end end |