Module: CrudComponents::Admin
- Defined in:
- lib/crud_components/admin.rb,
lib/crud_components/admin/gate.rb,
lib/crud_components/admin/entry.rb,
lib/crud_components/admin/engine.rb,
lib/crud_components/admin/registry.rb,
lib/crud_components/admin/dependents.rb,
lib/crud_components/admin/view_helpers.rb,
lib/crud_components/admin/configuration.rb,
app/controllers/crud_components/admin/dashboard_controller.rb,
app/controllers/crud_components/admin/resources_controller.rb,
app/controllers/crud_components/admin/application_controller.rb
Overview
The optional, mountable admin UI:
mount CrudComponents::Admin::Engine => '/admin'
See docs/admin.md.
Defined Under Namespace
Modules: ViewHelpers Classes: ApplicationController, Configuration, DashboardController, Dependents, Engine, Entry, Error, ForbiddenError, Gate, Registry, ResourcesController, UnauthorizedError
Class Method Summary collapse
-
.bundled_css ⇒ Object
The admin layout's own stylesheet, read once from the packaged file.
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
-
.mount_path ⇒ Object
Where the host mounted the engine, or nil when it did not.
-
.path_for(subject, action = :show) ⇒ Object
The admin's path for a record (or a model class, for its index), or nil when the admin isn't mounted, the model isn't registered, or the action is not enabled for it.
- .registry ⇒ Object
-
.reset! ⇒ Object
Drops both the configuration and the resolved registry.
Class Method Details
.bundled_css ⇒ Object
The admin layout's own stylesheet, read once from the packaged file.
48 49 50 51 52 |
# File 'lib/crud_components/admin.rb', line 48 def bundled_css @bundled_css ||= File.read( File.('../../app/assets/stylesheets/crud_components_admin.css', __dir__) ) end |
.config ⇒ Object
26 27 28 |
# File 'lib/crud_components/admin.rb', line 26 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
30 31 32 33 34 |
# File 'lib/crud_components/admin.rb', line 30 def configure yield config registry.reload! config end |
.mount_path ⇒ Object
Where the host mounted the engine, or nil when it did not.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/crud_components/admin.rb', line 55 def mount_path return @mount_path if @mount_path return nil unless defined?(Engine) && defined?(Rails) && Rails.application route = Rails.application.routes.routes.find do |candidate| candidate.app.respond_to?(:app) && candidate.app.app == Engine end path = route&.path&.spec.to_s @mount_path = path == '/' ? '' : path.presence end |
.path_for(subject, action = :show) ⇒ Object
The admin's path for a record (or a model class, for its index), or nil when the admin isn't mounted, the model isn't registered, or the action is not enabled for it.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/crud_components/admin.rb', line 69 def path_for(subject, action = :show) model = subject.is_a?(Class) ? subject : subject.class entry = registry[model] return nil unless entry&.allows?(action) && mount_path helper, args = helper_for(entry, action, subject) return nil unless Engine.routes.url_helpers.respond_to?(helper) Engine.routes.url_helpers.public_send(helper, *args, script_name: mount_path) end |
.registry ⇒ Object
36 37 38 |
# File 'lib/crud_components/admin.rb', line 36 def registry @registry ||= Registry.new(config) end |
.reset! ⇒ Object
Drops both the configuration and the resolved registry.
41 42 43 44 45 |
# File 'lib/crud_components/admin.rb', line 41 def reset! @config = nil @registry = nil @mount_path = nil end |