plutonium 0.15.5 → 0.15.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/plutonium.css +1 -1
- data/app/assets/plutonium.ico +0 -0
- data/app/assets/plutonium.png +0 -0
- data/docs/.vitepress/config.ts +61 -0
- data/docs/.vitepress/theme/custom.css +61 -0
- data/docs/.vitepress/theme/index.ts +4 -0
- data/docs/api-examples.md +49 -0
- data/docs/guide/getting-started/authorization.md +296 -0
- data/docs/guide/getting-started/core-concepts.md +432 -0
- data/docs/guide/getting-started/index.md +18 -0
- data/docs/guide/getting-started/installation.md +269 -0
- data/docs/guide/getting-started/resources.md +254 -0
- data/docs/guide/what-is-plutonium.md +211 -0
- data/docs/index.md +43 -0
- data/docs/markdown-examples.md +85 -0
- data/docs/public/android-chrome-192x192.png +0 -0
- data/docs/public/android-chrome-512x512.png +0 -0
- data/docs/public/apple-touch-icon.png +0 -0
- data/docs/public/favicon-16x16.png +0 -0
- data/docs/public/favicon-32x32.png +0 -0
- data/docs/public/favicon.ico +0 -0
- data/docs/public/plutonium.png +0 -0
- data/docs/public/site.webmanifest +1 -0
- data/docs/public/templates/plutonium.rb +21 -0
- data/lib/generators/pu/core/assets/assets_generator.rb +2 -3
- data/lib/generators/pu/core/assets/templates/tailwind.config.js +2 -2
- data/lib/generators/pu/core/install/install_generator.rb +9 -1
- data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +0 -1
- data/lib/plutonium/core/controllers/authorizable.rb +1 -1
- data/lib/plutonium/railtie.rb +0 -10
- data/lib/plutonium/resource/controllers/crud_actions.rb +1 -1
- data/lib/plutonium/resource/policy.rb +4 -5
- data/lib/plutonium/resource/register.rb +3 -0
- data/lib/plutonium/ui/action_button.rb +34 -19
- data/lib/plutonium/ui/form/resource.rb +2 -1
- data/lib/plutonium/ui/table/components/search_bar.rb +1 -1
- data/lib/plutonium/version.rb +1 -1
- data/package-lock.json +5767 -1851
- data/package.json +10 -4
- data/src/js/core.js +0 -1
- data/tailwind.options.js +89 -11
- metadata +27 -11
- data/app/assets/plutonium-original.png +0 -0
- data/app/assets/plutonium-white.png +0 -0
- data/public/plutonium-assets/fonts/bootstrap-icons.woff +0 -0
- data/public/plutonium-assets/fonts/bootstrap-icons.woff2 +0 -0
- /data/{templates → docs/public/templates}/base.rb +0 -0
@@ -0,0 +1,432 @@
|
|
1
|
+
# Core Concepts
|
2
|
+
|
3
|
+
::: tip What you'll learn
|
4
|
+
- Understanding Plutonium's architecture and core abstractions
|
5
|
+
- How resources and packages work together
|
6
|
+
- How to organize your application effectively
|
7
|
+
- Best practices for building maintainable applications
|
8
|
+
:::
|
9
|
+
|
10
|
+
## Resources
|
11
|
+
|
12
|
+
Resources are the fundamental building blocks of a Plutonium application. They represent your business domain objects and their associated behavior.
|
13
|
+
|
14
|
+
### Anatomy of a Resource
|
15
|
+
|
16
|
+
A resource consists of several interconnected components:
|
17
|
+
|
18
|
+
```mermaid
|
19
|
+
graph TD
|
20
|
+
A[Resource] --> B[Model]
|
21
|
+
A --> C[Definition]
|
22
|
+
A --> D[Policy]
|
23
|
+
A --> G[Actions]
|
24
|
+
|
25
|
+
B --> H[Database Schema]
|
26
|
+
C --> I[Fields & UI Logic]
|
27
|
+
C --> F[QueryObject]
|
28
|
+
D --> J[Authorization]
|
29
|
+
F --> L[Querying & Filtering]
|
30
|
+
G --> M[User Operations]
|
31
|
+
```
|
32
|
+
|
33
|
+
::: details Complete Resource Example
|
34
|
+
|
35
|
+
::: code-group
|
36
|
+
```ruby [Model]
|
37
|
+
# app/models/user.rb
|
38
|
+
class User < ApplicationRecord
|
39
|
+
include Plutonium::Resource::Record
|
40
|
+
|
41
|
+
# Associations
|
42
|
+
has_many :posts
|
43
|
+
has_many :comments
|
44
|
+
belongs_to :organization
|
45
|
+
|
46
|
+
# Scopes
|
47
|
+
scope :active, -> { where(status: :active) }
|
48
|
+
|
49
|
+
# Validations
|
50
|
+
validates :name, presence: true
|
51
|
+
validates :email, presence: true, uniqueness: true
|
52
|
+
validates :role, presence: true, inclusion: {in: %w[admin user]}
|
53
|
+
|
54
|
+
def admin? = role == "admin"
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
```ruby [Definition]
|
59
|
+
# app/definitions/user_definition.rb
|
60
|
+
class UserDefinition < Plutonium::Resource::Definition
|
61
|
+
# Display configuration
|
62
|
+
field :name, as: :string
|
63
|
+
field :email, as: :email
|
64
|
+
|
65
|
+
# Search configuration
|
66
|
+
search do |scope, query|
|
67
|
+
scope.where("name LIKE :q OR email LIKE :q", q: "%#{query}%")
|
68
|
+
end
|
69
|
+
|
70
|
+
# Filters
|
71
|
+
filter :role, with: SelectFilter, choices: %w[admin user guest]
|
72
|
+
filter :status, with: SelectFilter, choices: %w[active inactive]
|
73
|
+
|
74
|
+
# Scopes
|
75
|
+
scope :active
|
76
|
+
|
77
|
+
scope :admins do
|
78
|
+
where(role: :admin)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Actions
|
82
|
+
action :deactivate,
|
83
|
+
interaction: DeactivateUser,
|
84
|
+
color: :warning,
|
85
|
+
icon: Phlex::TablerIcons::UserOff
|
86
|
+
|
87
|
+
# UI Customization
|
88
|
+
show_page_title "User Details"
|
89
|
+
show_page_description "View and manage user information"
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
```ruby [Policy]
|
94
|
+
# app/policies/user_policy.rb
|
95
|
+
class UserPolicy < Plutonium::Resource::Policy
|
96
|
+
# Basic permissions
|
97
|
+
def read?
|
98
|
+
true
|
99
|
+
end
|
100
|
+
|
101
|
+
def create?
|
102
|
+
user.admin?
|
103
|
+
end
|
104
|
+
|
105
|
+
def update?
|
106
|
+
user.admin? || record.id == user.id
|
107
|
+
end
|
108
|
+
|
109
|
+
def destroy?
|
110
|
+
user.admin? && record.id != user.id
|
111
|
+
end
|
112
|
+
|
113
|
+
# Action permissions
|
114
|
+
def deactivate?
|
115
|
+
user.admin? && record.status == :active && record.id != user.id
|
116
|
+
end
|
117
|
+
|
118
|
+
# Attribute permissions
|
119
|
+
def permitted_attributes_for_read
|
120
|
+
if user.admin?
|
121
|
+
%i[name email role status created_at updated_at]
|
122
|
+
else
|
123
|
+
%i[name email status]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def permitted_attributes_for_create
|
128
|
+
if user.admin?
|
129
|
+
%i[name email role status password]
|
130
|
+
else
|
131
|
+
%i[name email password]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def permitted_attributes_for_update
|
136
|
+
if user.admin?
|
137
|
+
%i[name email role]
|
138
|
+
else
|
139
|
+
%i[name email]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Association permissions
|
144
|
+
def permitted_associations
|
145
|
+
%i[posts comments]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
|
151
|
+
```ruby [Deactivate Interaction]
|
152
|
+
# app/interactions/user_interactions/deactivate.rb
|
153
|
+
module UserInteractions
|
154
|
+
class Deactivate < Plutonium::Resource::Interaction
|
155
|
+
# Define presentable metadata
|
156
|
+
presents label: "Deactivate User",
|
157
|
+
icon: Phlex::TablerIcons::UserOff,
|
158
|
+
description: "Deactivate user account"
|
159
|
+
|
160
|
+
# Define attributes
|
161
|
+
attribute :resource, class: User
|
162
|
+
attribute :reason, :string
|
163
|
+
|
164
|
+
# Validations
|
165
|
+
validates :resource, presence: true
|
166
|
+
validates :reason, presence: true
|
167
|
+
|
168
|
+
# Business logic
|
169
|
+
def execute
|
170
|
+
resource.transaction do
|
171
|
+
resource.status = :inactive
|
172
|
+
resource.deactivated_at = Time.current
|
173
|
+
resource.deactivation_reason = reason
|
174
|
+
|
175
|
+
if resource.save
|
176
|
+
succeed(resource)
|
177
|
+
.with_message("User was successfully deactivated")
|
178
|
+
.with_redirect_response(resource)
|
179
|
+
else
|
180
|
+
failed(resource.errors)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
```
|
187
|
+
:::
|
188
|
+
|
189
|
+
## Packages
|
190
|
+
|
191
|
+
Packages are the way Plutonium helps you modularize your application. They're built on top of Rails Engines but provide additional structure and conventions.
|
192
|
+
|
193
|
+
There are two main types:
|
194
|
+
|
195
|
+
### Feature Packages
|
196
|
+
|
197
|
+
|
198
|
+
Feature packages help you organize your application into logical, reusable modules.
|
199
|
+
They contain your business domain logic and resources. They're self-contained and independent.
|
200
|
+
|
201
|
+
::: tip Key Characteristics
|
202
|
+
- Domain Models
|
203
|
+
- Business Logic
|
204
|
+
- No Web Interface
|
205
|
+
- Reusable Components
|
206
|
+
:::
|
207
|
+
|
208
|
+
::: code-group
|
209
|
+
```ruby [Directory Structure]
|
210
|
+
packages/
|
211
|
+
└── blogging/
|
212
|
+
├── app/
|
213
|
+
│ ├── models/
|
214
|
+
│ │ └── blogging/
|
215
|
+
│ │ ├── post.rb
|
216
|
+
│ │ └── comment.rb
|
217
|
+
│ ├── definitions/
|
218
|
+
│ │ └── blogging/
|
219
|
+
│ │ ├── post_definition.rb
|
220
|
+
│ │ └── comment_definition.rb
|
221
|
+
│ ├── policies/
|
222
|
+
│ │ └── blogging/
|
223
|
+
│ │ ├── post_policy.rb
|
224
|
+
│ │ └── comment_policy.rb
|
225
|
+
│ └── interactions/
|
226
|
+
│ └── blogging/
|
227
|
+
│ └── post_interactions/
|
228
|
+
│ ├── publish.rb
|
229
|
+
│ └── archive.rb
|
230
|
+
├── config/
|
231
|
+
│ └── routes.rb
|
232
|
+
└── lib/
|
233
|
+
└── engine.rb
|
234
|
+
```
|
235
|
+
|
236
|
+
```ruby [Engine Configuration]
|
237
|
+
# packages/blogging/lib/engine.rb
|
238
|
+
module Blogging
|
239
|
+
class Engine < ::Rails::Engine
|
240
|
+
include Plutonium::Package::Engine
|
241
|
+
|
242
|
+
# Package configuration goes here
|
243
|
+
isolate_namespace Blogging
|
244
|
+
end
|
245
|
+
end
|
246
|
+
```
|
247
|
+
:::
|
248
|
+
|
249
|
+
### Portal Packages
|
250
|
+
|
251
|
+
Portal packages provide web interfaces and control how users interact with features.
|
252
|
+
|
253
|
+
::: tip Key Characteristics
|
254
|
+
- Web Interface
|
255
|
+
- Authentication
|
256
|
+
- Resource Access Control
|
257
|
+
- Feature Composition
|
258
|
+
:::
|
259
|
+
|
260
|
+
::: code-group
|
261
|
+
```ruby [Directory Structure]
|
262
|
+
packages/
|
263
|
+
└── admin_portal/
|
264
|
+
├── app/
|
265
|
+
│ ├── controllers/
|
266
|
+
│ │ └── admin_portal/
|
267
|
+
│ │ ├── concerns/
|
268
|
+
│ │ │ └── controller.rb
|
269
|
+
│ │ ├── plutonium_controller.rb
|
270
|
+
│ │ └── resource_controller.rb
|
271
|
+
│ └── views/
|
272
|
+
│ └── layouts/
|
273
|
+
│ └── admin_portal.html.erb
|
274
|
+
├── config/
|
275
|
+
│ └── routes.rb
|
276
|
+
└── lib/
|
277
|
+
└── engine.rb
|
278
|
+
```
|
279
|
+
|
280
|
+
```ruby [Engine Configuration]
|
281
|
+
# packages/admin_portal/lib/engine.rb
|
282
|
+
module AdminPortal
|
283
|
+
class Engine < ::Rails::Engine
|
284
|
+
include Plutonium::Portal::Engine
|
285
|
+
|
286
|
+
# Scope all resources to organization
|
287
|
+
scope_to_entity Organization, strategy: :path
|
288
|
+
end
|
289
|
+
end
|
290
|
+
```
|
291
|
+
|
292
|
+
```ruby [Routes Configuration]
|
293
|
+
# packages/admin_portal/config/routes.rb
|
294
|
+
AdminPortal::Engine.routes.draw do
|
295
|
+
root to: "dashboard#index"
|
296
|
+
|
297
|
+
# Register resources from feature packages
|
298
|
+
register_resource Blogging::Post
|
299
|
+
register_resource Blogging::Comment
|
300
|
+
end
|
301
|
+
```
|
302
|
+
|
303
|
+
```ruby [Controller Configuration]
|
304
|
+
# packages/admin_portal/app/controllers/admin_portal/concerns/controller.rb
|
305
|
+
module AdminPortal
|
306
|
+
module Concerns
|
307
|
+
class Controller < ::Rails::Engine
|
308
|
+
extend ActiveSupport::Concern
|
309
|
+
include Plutonium::Portal::Controller
|
310
|
+
# Integrate authentication
|
311
|
+
include Plutonium::Auth::Rodauth(:admin)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
```
|
316
|
+
:::
|
317
|
+
|
318
|
+
## Entity Scoping
|
319
|
+
|
320
|
+
Entity scoping is a powerful feature that allows you to partition resources based on a parent entity (like Organization or Account).
|
321
|
+
It's how Plutonium achieve's multitenancy.
|
322
|
+
|
323
|
+
By properly defining associations to an entity, row-level multitenancy comes for free, out of the box.
|
324
|
+
|
325
|
+
```ruby
|
326
|
+
# Scope definition in engine
|
327
|
+
module AdminPortal
|
328
|
+
class Engine < ::Rails::Engine
|
329
|
+
include Plutonium::Portal::Engine
|
330
|
+
|
331
|
+
# Path-based scoping (/org_123/posts)
|
332
|
+
scope_to_entity Organization, strategy: :path
|
333
|
+
|
334
|
+
# Or custom scoping
|
335
|
+
scope_to_entity Organization, strategy: :current_organization
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
# Model implementation
|
340
|
+
class Post < ApplicationRecord
|
341
|
+
include Plutonium::Resource::Record
|
342
|
+
|
343
|
+
# Define a direct relationship to the entity
|
344
|
+
belongs_to :user
|
345
|
+
belongs_to :organization, through: :user
|
346
|
+
|
347
|
+
# Alternatively, if there's no direct relationship
|
348
|
+
scope :associated_with_organization, ->(organization) do
|
349
|
+
# custom scoping logic goes here
|
350
|
+
joins(:user).where(users: { organization_id: organization.id })
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
# Controller config
|
355
|
+
class ResourceController < PlutoniumController
|
356
|
+
include Plutonium::Resource::Controller
|
357
|
+
|
358
|
+
private
|
359
|
+
|
360
|
+
def current_organization
|
361
|
+
# Get tenant from the current subdomain
|
362
|
+
@current_organization ||= Organization.where(subdomain: request.subdomain).first!
|
363
|
+
end
|
364
|
+
end
|
365
|
+
```
|
366
|
+
|
367
|
+
## Best Practices
|
368
|
+
|
369
|
+
### Package Organization
|
370
|
+
|
371
|
+
::: tip Feature Packages
|
372
|
+
1. Keep domain logic isolated
|
373
|
+
2. Clear boundaries between features
|
374
|
+
3. Minimal dependencies between packages
|
375
|
+
4. Well-defined interfaces
|
376
|
+
:::
|
377
|
+
|
378
|
+
::: tip Portal Packages
|
379
|
+
1. Single responsibility (admin, customer)
|
380
|
+
2. Consistent authentication strategy
|
381
|
+
3. Clear resource scoping rules
|
382
|
+
4. Feature composition over duplication
|
383
|
+
:::
|
384
|
+
|
385
|
+
### Resource Design
|
386
|
+
|
387
|
+
::: tip Model Layer
|
388
|
+
1. Clear validations and constraints
|
389
|
+
2. Proper association setup
|
390
|
+
3. Meaningful scopes
|
391
|
+
:::
|
392
|
+
|
393
|
+
::: tip Definition Layer
|
394
|
+
1. Appropriate field types
|
395
|
+
2. Clear action definitions
|
396
|
+
3. Efficient search implementation
|
397
|
+
:::
|
398
|
+
|
399
|
+
::: tip Policy Layer
|
400
|
+
1. Granular permissions
|
401
|
+
2. Attribute-level access control
|
402
|
+
3. Action-specific rules
|
403
|
+
4. Association permissions
|
404
|
+
:::
|
405
|
+
|
406
|
+
### Security Considerations
|
407
|
+
|
408
|
+
::: warning Important
|
409
|
+
1. Always implement proper policies
|
410
|
+
2. Use entity scoping consistently
|
411
|
+
3. Validate all inputs
|
412
|
+
4. Control association access
|
413
|
+
5. Audit sensitive actions
|
414
|
+
:::
|
415
|
+
|
416
|
+
## Generator Support
|
417
|
+
|
418
|
+
Plutonium provides generators to quickly scaffold components:
|
419
|
+
|
420
|
+
```bash
|
421
|
+
# Create a new feature package
|
422
|
+
rails generate pu:pkg:package blogging
|
423
|
+
|
424
|
+
# Create a new portal package
|
425
|
+
rails generate pu:pkg:portal admin
|
426
|
+
|
427
|
+
# Create a new resource
|
428
|
+
rails generate pu:res:scaffold post title:string content:text
|
429
|
+
|
430
|
+
# Connect a resource to a portal
|
431
|
+
rails generate pu:res:conn
|
432
|
+
```
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Getting Started with Plutonium
|
2
|
+
|
3
|
+
<!--
|
4
|
+
This guide covers getting up and running with Plutonium.
|
5
|
+
|
6
|
+
After reading this guide, you will know:
|
7
|
+
|
8
|
+
- How to install Plutonium.
|
9
|
+
- The general layout of a Plutonium application.
|
10
|
+
- The basic principles of Resource design.
|
11
|
+
- How to quickly generate the starting pieces of a Plutonium application.
|
12
|
+
-->
|
13
|
+
|
14
|
+
## Prerequisites
|
15
|
+
|
16
|
+
Before using Plutonium, you should be familiar with Rails.
|
17
|
+
Plutonium builds upon many core Rails concepts and conventions.
|
18
|
+
If you're new to Rails or need a refresher, we highly recommend reading the [Rails' guide](https://guides.rubyonrails.org/getting_started.html).
|
@@ -0,0 +1,269 @@
|
|
1
|
+
# Installation and Setup
|
2
|
+
|
3
|
+
::: tip VERSION REQUIREMENTS
|
4
|
+
- Ruby 3.2.2 or higher
|
5
|
+
- Rails 7.1 or higher
|
6
|
+
:::
|
7
|
+
|
8
|
+
## Quick Start
|
9
|
+
|
10
|
+
Get up and running with Plutonium in seconds:
|
11
|
+
|
12
|
+
::: code-group
|
13
|
+
```bash [New App]
|
14
|
+
rails new plutonium_app -a propshaft -j esbuild -c tailwind \
|
15
|
+
-m https://radioactive-labs.github.io/plutonium-core/templates/plutonium.rb
|
16
|
+
```
|
17
|
+
|
18
|
+
```bash [Existing App]
|
19
|
+
bin/rails app:template \
|
20
|
+
LOCATION=https://radioactive-labs.github.io/plutonium-core/templates/base.rb
|
21
|
+
```
|
22
|
+
:::
|
23
|
+
|
24
|
+
## Detailed Installation Guide
|
25
|
+
|
26
|
+
1. Add Plutonium to your Gemfile:
|
27
|
+
|
28
|
+
::: code-group
|
29
|
+
```ruby [Gemfile]
|
30
|
+
gem "plutonium"
|
31
|
+
```
|
32
|
+
|
33
|
+
```bash [Terminal]
|
34
|
+
bundle install
|
35
|
+
```
|
36
|
+
:::
|
37
|
+
|
38
|
+
2. Run the installation generator:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
rails generate pu:core:install
|
42
|
+
```
|
43
|
+
|
44
|
+
This will:
|
45
|
+
- Set up the basic Plutonium structure
|
46
|
+
- Create necessary configuration files
|
47
|
+
- Configure your application for Plutonium
|
48
|
+
|
49
|
+
### Project Structure
|
50
|
+
|
51
|
+
After installation, your project will have the following new directories and files:
|
52
|
+
|
53
|
+
```
|
54
|
+
my_rails_app/
|
55
|
+
├── app/
|
56
|
+
│ ├── controllers/
|
57
|
+
│ │ ├── plutonium_controller.rb # Base controller for Plutonium
|
58
|
+
│ │ └── resource_controller.rb # Base controller for resources
|
59
|
+
│ ├── definitions/
|
60
|
+
│ │ └── resource_definition.rb # Base class for resource definitions
|
61
|
+
│ ├── interactions/
|
62
|
+
│ │ └── resource_interaction.rb # Base class for resource interactions
|
63
|
+
│ ├── models/
|
64
|
+
│ │ └── resource_record.rb # Base module for resource models
|
65
|
+
│ ├── policies/
|
66
|
+
│ │ └── resource_policy.rb # Base class for resource policies
|
67
|
+
│ └── views/
|
68
|
+
│ └── layouts/
|
69
|
+
│ └── resource.html.erb # Base layout for resources
|
70
|
+
├── config/
|
71
|
+
│ ├── initializers/
|
72
|
+
│ │ └── plutonium.rb # Main configuration
|
73
|
+
│ └── packages.rb # Package registration
|
74
|
+
└── packages/ # Directory for modular features
|
75
|
+
└── .keep
|
76
|
+
```
|
77
|
+
|
78
|
+
## Configuration
|
79
|
+
|
80
|
+
### Basic Configuration
|
81
|
+
|
82
|
+
Configure Plutonium in `config/initializers/plutonium.rb`:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
Plutonium.configure do |config|
|
86
|
+
# Load default configuration for version 1.0
|
87
|
+
config.load_defaults 1.0
|
88
|
+
|
89
|
+
# Asset configuration
|
90
|
+
config.assets.stylesheet = "plutonium.css" # Default stylesheet
|
91
|
+
config.assets.script = "plutonium.js" # Default JavaScript
|
92
|
+
config.assets.logo = "plutonium.png" # Default logo
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
### Authentication Setup
|
97
|
+
|
98
|
+
Plutonium supports multiple authentication strategies. Here's how to set up the recommended Rodauth integration:
|
99
|
+
|
100
|
+
1. Install Rodauth:
|
101
|
+
|
102
|
+
```bash
|
103
|
+
rails generate pu:rodauth:install
|
104
|
+
```
|
105
|
+
|
106
|
+
2. Create an authentication account:
|
107
|
+
|
108
|
+
::: code-group
|
109
|
+
```bash [Basic Setup]
|
110
|
+
rails generate pu:rodauth:account user
|
111
|
+
```
|
112
|
+
|
113
|
+
```bash [Custom Setup]
|
114
|
+
# Include selected authentication features
|
115
|
+
rails generate pu:rodauth:account admin --no-defaults \
|
116
|
+
--login --logout --remember --lockout \
|
117
|
+
--create-account --verify-account --close-account \
|
118
|
+
--change-password --reset-password --reset-password-notify \
|
119
|
+
--active-sessions --password-grace-period --otp \
|
120
|
+
--recovery-codes --audit-logging --internal-request
|
121
|
+
```
|
122
|
+
:::
|
123
|
+
|
124
|
+
3. Configure the authentication controller:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
# app/controllers/resource_controller.rb
|
128
|
+
class ResourceController < PlutoniumController
|
129
|
+
include Plutonium::Resource::Controller
|
130
|
+
include Plutonium::Auth::Rodauth(:user)
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
::: tip
|
135
|
+
You can use your existing authentication system by implementing the `current_user` method in `ResourceController`.
|
136
|
+
:::
|
137
|
+
|
138
|
+
<!--
|
139
|
+
## Asset Pipeline Setup
|
140
|
+
|
141
|
+
### JavaScript Setup
|
142
|
+
|
143
|
+
|
144
|
+
Plutonium uses modern JavaScript features. Here's how to set it up:
|
145
|
+
|
146
|
+
1. Install required npm packages:
|
147
|
+
|
148
|
+
::: code-group
|
149
|
+
```bash [importmap]
|
150
|
+
bin/importmap pin @radioactive-labs/plutonium
|
151
|
+
```
|
152
|
+
|
153
|
+
```bash [esbuild]
|
154
|
+
npm install @radioactive-labs/plutonium
|
155
|
+
```
|
156
|
+
:::
|
157
|
+
|
158
|
+
|
159
|
+
2. Configure JavaScript:
|
160
|
+
|
161
|
+
::: code-group
|
162
|
+
```js [app/javascript/controllers/index.js]
|
163
|
+
import { application } from "controllers/application"
|
164
|
+
import { registerControllers } from "@radioactive-labs/plutonium" // [!code ++]
|
165
|
+
registerControllers(application) // [!code ++]
|
166
|
+
```
|
167
|
+
|
168
|
+
```js [app/javascript/application.js]
|
169
|
+
import "@hotwired/turbo-rails"
|
170
|
+
import "controllers"
|
171
|
+
```
|
172
|
+
:::
|
173
|
+
|
174
|
+
### CSS Setup
|
175
|
+
|
176
|
+
Plutonium uses Tailwind CSS. Configure it in your `tailwind.config.js`:
|
177
|
+
|
178
|
+
```js
|
179
|
+
const defaultTheme = require('tailwindcss/defaultTheme')
|
180
|
+
|
181
|
+
module.exports = {
|
182
|
+
content: [
|
183
|
+
'./app/views/**/*.erb',
|
184
|
+
'./app/helpers/**/*.rb',
|
185
|
+
'./app/javascript/**/*.js',
|
186
|
+
'./app/components/**/*.{erb,rb}',
|
187
|
+
'./node_modules/@radioactive-labs/plutonium/**/*.{js,ts}'
|
188
|
+
],
|
189
|
+
theme: {
|
190
|
+
extend: {
|
191
|
+
fontFamily: {
|
192
|
+
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
|
193
|
+
},
|
194
|
+
},
|
195
|
+
},
|
196
|
+
plugins: [
|
197
|
+
require('@tailwindcss/forms'),
|
198
|
+
require('flowbite/plugin')
|
199
|
+
],
|
200
|
+
}
|
201
|
+
```
|
202
|
+
-->
|
203
|
+
|
204
|
+
## Optional Enhancements
|
205
|
+
|
206
|
+
### Database Performance
|
207
|
+
|
208
|
+
For PostgreSQL/MySQL users, add these recommended gems:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
group :development, :test do
|
212
|
+
# N+1 query detection
|
213
|
+
gem "prosopite"
|
214
|
+
end
|
215
|
+
|
216
|
+
# Automatic eager loading
|
217
|
+
gem "goldiloader"
|
218
|
+
```
|
219
|
+
|
220
|
+
### Development Tools
|
221
|
+
|
222
|
+
Add helpful development gems:
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
# Generate model annotations
|
226
|
+
rails generate pu:gem:annotate
|
227
|
+
|
228
|
+
# Set up environment variables
|
229
|
+
rails generate pu:gem:dotenv
|
230
|
+
```
|
231
|
+
|
232
|
+
<!--
|
233
|
+
## Verification
|
234
|
+
|
235
|
+
Verify your installation:
|
236
|
+
|
237
|
+
```bash
|
238
|
+
# Start your Rails server
|
239
|
+
rails server
|
240
|
+
|
241
|
+
# Check your logs for any warnings or errors
|
242
|
+
tail -f log/development.log
|
243
|
+
|
244
|
+
# Generate and test a sample resource
|
245
|
+
rails generate pu:res:scaffold Post title:string content:text
|
246
|
+
```
|
247
|
+
|
248
|
+
Visit `http://localhost:3000/posts` to verify everything is working.
|
249
|
+
-->
|
250
|
+
|
251
|
+
<!--
|
252
|
+
::: tip Next Steps
|
253
|
+
Now that you have Plutonium installed and configured, you're ready to:
|
254
|
+
1. [Create your first resource](/guide/resources/creating-resources)
|
255
|
+
2. [Set up your first package](/guide/packages/creating-packages)
|
256
|
+
3. [Configure authorization](/guide/authorization/basic-setup)
|
257
|
+
:::
|
258
|
+
-->
|
259
|
+
|
260
|
+
<!--
|
261
|
+
### Getting Help
|
262
|
+
|
263
|
+
If you run into issues:
|
264
|
+
|
265
|
+
1. Check the [FAQ](/guide/faq)
|
266
|
+
2. Search [GitHub Issues](https://github.com/radioactive-labs/plutonium-core/issues)
|
267
|
+
3. Join our [Discord Community](https://discord.gg/plutonium)
|
268
|
+
4. Create a new [GitHub Issue](https://github.com/radioactive-labs/plutonium-core/issues/new)
|
269
|
+
-->
|