Class: CrudComponents::Config
- Inherits:
-
Object
- Object
- CrudComponents::Config
- Defined in:
- lib/crud_components/config.rb
Constant Summary collapse
- DEFAULT_CSS =
When changed, add it to initializer.rb
{ table: 'table align-middle', thead: '', toolbar: 'd-flex justify-content-between align-items-center gap-2 mb-2', search_form: 'd-flex gap-1', filter_row: 'crud-filter-row', sort_link: 'text-reset text-decoration-none', record_link: 'fw-medium', filter_link: 'text-reset text-decoration-none', actions_cell: 'text-end', button_group: 'btn-group btn-group-sm', button: 'btn btn-sm btn-outline-secondary', button_primary: 'btn btn-sm btn-primary', button_danger: 'btn btn-sm btn-outline-danger', pagination: 'pagination pagination-sm', badge: 'badge text-bg-secondary', badge_muted: 'badge text-bg-light', input: 'form-control', input_sm: 'form-control form-control-sm', # named *_input to avoid OrderedOptions#select (Hash#select) collisions select_input: 'form-select', select_input_sm: 'form-select form-select-sm', form_label: 'form-label', form_summary: 'alert alert-danger', filter_grid: 'row row-cols-1 g-2', input_group: 'input-group flex-nowrap', boolean_true: 'text-success', boolean_false: 'text-danger', muted: 'text-muted', # icon font base + name prefix; built-in icon names are Bootstrap Icons. # Swap the whole library here, e.g. 'fa fa-' for Font Awesome. icon_prefix: 'bi bi-', dl: 'row', dt: 'col-sm-3', dd: 'col-sm-9' }.freeze
- DEFAULT_ACTION_ICONS =
Icon name (no library prefix — paired with css.icon_prefix) for each derived action. Override a glyph, or set one to nil for no icon:
config.action_icons[:destroy] = 'trash-fill' { new: 'plus-lg', show: 'eye', edit: 'pencil', destroy: 'trash' }.freeze
- DEFAULT_FILE_ICONS =
Map of file extension → icon name (no library prefix — paired with css.icon_prefix) for the attachment icon fallback; an unmapped extension uses file_fallback_icon. Full names (not a prefix) so non-conforming ones fit too — e.g. yaml→filetype-yml, zip→file-earmark-zip. Bootstrap Icons’ whole ‘filetype-*` family is included; override/extend per your set.
%w[ aac ai bmp cs css csv doc docx exe gif heic html java jpg js json jsx key m4p md mdx mov mp3 mp4 otf pdf php png ppt pptx psd py raw rb sass scss sh sql svg tiff tsx ttf txt wav woff xls xlsx xml yml ].to_h { |ext| [ext, "filetype-#{ext}"] }.merge( 'yaml' => 'filetype-yml', # alias of yml 'jpeg' => 'filetype-jpg', # alias of jpg 'zip' => 'file-earmark-zip' # no filetype- glyph exists ).freeze
- DEFAULT_MODEL_ICONS =
A guessed icon (no library prefix — paired with css.icon_prefix) per model, keyed by the model’s singular underscored name (‘model_name.element`, so `Admin::User` → “user”). Used wherever a model is badged: column-picker groups, association links, path-column cells. A model can override with `icon ’building’‘ in its `crud_structure`; an unmapped model with no declaration falls back to model_fallback_icon (nil = no icon). Extend it:
config.model_icons['widget'] = 'box-seam' { 'user' => 'person', 'person' => 'person', 'author' => 'person', 'member' => 'person', 'customer' => 'person', 'contact' => 'person-lines-fill', 'account' => 'person-circle', 'profile' => 'person-badge', 'admin' => 'person-gear', 'participant' => 'person', 'student' => 'mortarboard', 'teacher' => 'easel', 'team' => 'people', 'group' => 'people', 'role' => 'person-badge', 'organization' => 'building', 'company' => 'building', 'publisher' => 'building', 'department' => 'building', 'vendor' => 'shop', 'supplier' => 'shop', 'store' => 'shop', 'shop' => 'shop', 'book' => 'book', 'article' => 'file-earmark-text', 'post' => 'file-earmark-post', 'page' => 'file-earmark', 'document' => 'file-earmark', 'file' => 'file-earmark', 'attachment' => 'paperclip', 'report' => 'file-earmark-bar-graph', 'order' => 'cart', 'cart' => 'cart', 'product' => 'box-seam', 'item' => 'box', 'invoice' => 'receipt', 'receipt' => 'receipt', 'payment' => 'credit-card', 'transaction' => 'credit-card', 'subscription' => 'arrow-repeat', 'comment' => 'chat', 'message' => 'chat-dots', 'review' => 'star', 'rating' => 'star', 'notification' => 'bell', 'email' => 'envelope', 'mail' => 'envelope', 'tag' => 'tag', 'label' => 'tag', 'category' => 'collection', 'genre' => 'collection', 'project' => 'kanban', 'task' => 'check2-square', 'todo' => 'check2-square', 'ticket' => 'ticket', 'event' => 'calendar-event', 'appointment' => 'calendar-check', 'booking' => 'calendar-check', 'course' => 'mortarboard', 'lesson' => 'easel', 'address' => 'geo-alt', 'location' => 'geo-alt', 'place' => 'geo-alt', 'country' => 'globe', 'city' => 'geo-alt', 'image' => 'image', 'photo' => 'image', 'video' => 'camera-video', 'media' => 'collection-play', 'setting' => 'gear', 'permission' => 'shield-lock' }.freeze
Instance Attribute Summary collapse
-
#action_icons ⇒ Object
Returns the value of attribute action_icons.
-
#css ⇒ Object
readonly
Returns the value of attribute css.
-
#fast_cells ⇒ Object
Returns the value of attribute fast_cells.
-
#file_fallback_icon ⇒ Object
Returns the value of attribute file_fallback_icon.
-
#file_icons ⇒ Object
Returns the value of attribute file_icons.
-
#group_collapse_threshold ⇒ Object
Returns the value of attribute group_collapse_threshold.
-
#max_path_depth ⇒ Object
Returns the value of attribute max_path_depth.
-
#model_fallback_icon ⇒ Object
Returns the value of attribute model_fallback_icon.
-
#model_icons ⇒ Object
Returns the value of attribute model_icons.
-
#select_limit ⇒ Object
Returns the value of attribute select_limit.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/crud_components/config.rb', line 104 def initialize @select_limit = 250 # Grouped collections open every group when the total row count is below # this, and only the first group above it (the rest collapse). @group_collapse_threshold = 50 # How many associations a path column (e.g. `publisher.country.name`) may # chain through. A guard rail against runaway joins — raise it if you have # legitimately deeper paths. (Crossing more than one *to-many* association # is forbidden regardless of this, since that yields a list-of-lists.) @max_path_depth = 3 # Render built-in cell types inline (in Ruby) instead of one partial per # cell — an order of magnitude faster on big tables. A host override of a # field partial is still honored; set false to force partials everywhere. @fast_cells = true @css = ActiveSupport::OrderedOptions.new.merge!(DEFAULT_CSS) @action_icons = DEFAULT_ACTION_ICONS.dup @file_icons = DEFAULT_FILE_ICONS.dup @file_fallback_icon = 'file-earmark-text' @model_icons = DEFAULT_MODEL_ICONS.dup # No generic badge for an unmapped, undeclared model — set a glyph here to # icon every model (e.g. 'box') if you prefer. @model_fallback_icon = nil end |
Instance Attribute Details
#action_icons ⇒ Object
Returns the value of attribute action_icons.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def action_icons @action_icons end |
#css ⇒ Object (readonly)
Returns the value of attribute css.
102 103 104 |
# File 'lib/crud_components/config.rb', line 102 def css @css end |
#fast_cells ⇒ Object
Returns the value of attribute fast_cells.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def fast_cells @fast_cells end |
#file_fallback_icon ⇒ Object
Returns the value of attribute file_fallback_icon.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def file_fallback_icon @file_fallback_icon end |
#file_icons ⇒ Object
Returns the value of attribute file_icons.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def file_icons @file_icons end |
#group_collapse_threshold ⇒ Object
Returns the value of attribute group_collapse_threshold.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def group_collapse_threshold @group_collapse_threshold end |
#max_path_depth ⇒ Object
Returns the value of attribute max_path_depth.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def max_path_depth @max_path_depth end |
#model_fallback_icon ⇒ Object
Returns the value of attribute model_fallback_icon.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def model_fallback_icon @model_fallback_icon end |
#model_icons ⇒ Object
Returns the value of attribute model_icons.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def model_icons @model_icons end |
#select_limit ⇒ Object
Returns the value of attribute select_limit.
99 100 101 |
# File 'lib/crud_components/config.rb', line 99 def select_limit @select_limit end |