plutonium 0.23.4 → 0.23.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/plutonium.css +2 -2
  3. data/config/initializers/sqlite_json_alias.rb +1 -1
  4. data/docs/.vitepress/config.ts +60 -19
  5. data/docs/guide/cursor-rules.md +75 -0
  6. data/docs/guide/deep-dive/authorization.md +189 -0
  7. data/docs/guide/{getting-started → deep-dive}/resources.md +137 -0
  8. data/docs/guide/getting-started/{installation.md → 01-installation.md} +0 -105
  9. data/docs/guide/index.md +28 -0
  10. data/docs/guide/introduction/02-core-concepts.md +440 -0
  11. data/docs/guide/tutorial/01-project-setup.md +75 -0
  12. data/docs/guide/tutorial/02-creating-a-feature-package.md +45 -0
  13. data/docs/guide/tutorial/03-defining-resources.md +90 -0
  14. data/docs/guide/tutorial/04-creating-a-portal.md +101 -0
  15. data/docs/guide/tutorial/05-customizing-the-ui.md +128 -0
  16. data/docs/guide/tutorial/06-adding-custom-actions.md +101 -0
  17. data/docs/guide/tutorial/07-implementing-authorization.md +90 -0
  18. data/docs/index.md +24 -31
  19. data/docs/modules/action.md +190 -0
  20. data/docs/modules/authentication.md +236 -0
  21. data/docs/modules/configuration.md +599 -0
  22. data/docs/modules/controller.md +398 -0
  23. data/docs/modules/core.md +316 -0
  24. data/docs/modules/definition.md +876 -0
  25. data/docs/modules/display.md +759 -0
  26. data/docs/modules/form.md +605 -0
  27. data/docs/modules/generator.md +288 -0
  28. data/docs/modules/index.md +167 -0
  29. data/docs/modules/interaction.md +470 -0
  30. data/docs/modules/package.md +151 -0
  31. data/docs/modules/policy.md +176 -0
  32. data/docs/modules/portal.md +710 -0
  33. data/docs/modules/query.md +287 -0
  34. data/docs/modules/resource_record.md +618 -0
  35. data/docs/modules/routing.md +641 -0
  36. data/docs/modules/table.md +293 -0
  37. data/docs/modules/ui.md +631 -0
  38. data/docs/public/plutonium.mdc +667 -0
  39. data/lib/generators/pu/core/assets/assets_generator.rb +0 -5
  40. data/lib/plutonium/ui/display/resource.rb +7 -2
  41. data/lib/plutonium/ui/table/resource.rb +8 -3
  42. data/lib/plutonium/version.rb +1 -1
  43. metadata +36 -9
  44. data/docs/guide/getting-started/authorization.md +0 -296
  45. data/docs/guide/getting-started/core-concepts.md +0 -432
  46. data/docs/guide/getting-started/index.md +0 -21
  47. data/docs/guide/tutorial.md +0 -401
  48. /data/docs/guide/{what-is-plutonium.md → introduction/01-what-is-plutonium.md} +0 -0
@@ -0,0 +1,599 @@
1
+ ---
2
+ title: Configuration Module
3
+ ---
4
+
5
+ # Configuration Module
6
+
7
+ The Configuration module provides centralized configuration management for Plutonium applications. It allows you to customize various aspects of Plutonium's behavior through a clean, versioned configuration API with environment-specific settings and asset management.
8
+
9
+ ::: tip
10
+ The main configuration file is located at `config/initializers/plutonium.rb`.
11
+ :::
12
+
13
+ ## Overview
14
+
15
+ - **Centralized Configuration**: Single point of configuration for all Plutonium settings.
16
+ - **Version-Based Defaults**: Versioned configuration system for backward compatibility.
17
+ - **Asset Configuration**: Centralized asset path and file management.
18
+ - **Environment Variables**: Support for environment-based configuration.
19
+ - **Development Features**: Hot reloading and development-specific settings.
20
+ - **Rails Integration**: Seamless integration with Rails configuration system.
21
+
22
+ ## Basic Configuration
23
+
24
+ All configuration happens within the `Plutonium.configure` block in `config/initializers/plutonium.rb`.
25
+
26
+ ```ruby
27
+ # config/initializers/plutonium.rb
28
+ Plutonium.configure do |config|
29
+ # Load version-specific defaults first
30
+ config.load_defaults 1.0
31
+
32
+ # Core settings
33
+ config.development = Rails.env.development?
34
+ config.cache_discovery = !Rails.env.development?
35
+ config.enable_hotreload = Rails.env.development?
36
+
37
+ # Asset configuration
38
+ config.assets.logo = "custom_logo.png"
39
+ config.assets.favicon = "custom_favicon.ico"
40
+ config.assets.stylesheet = "custom_plutonium.css"
41
+ config.assets.script = "custom_plutonium.js"
42
+ end
43
+ ```
44
+
45
+ ## Configuration Options
46
+
47
+ ### Core Settings
48
+
49
+ ::: code-group
50
+ ```ruby [config.development]
51
+ # Controls whether Plutonium operates in development mode.
52
+ # Can also be set via PLUTONIUM_DEV environment variable.
53
+ config.development = Rails.env.development?
54
+ ```
55
+ ```ruby [config.cache_discovery]
56
+ # Controls whether resource discovery is cached.
57
+ # Typically disabled in development for faster iteration.
58
+ config.cache_discovery = !Rails.env.development?
59
+ ```
60
+ ```ruby [config.enable_hotreload]
61
+ # Controls whether hot reloading is enabled.
62
+ # Only recommended for development environments.
63
+ config.enable_hotreload = Rails.env.development?
64
+ ```
65
+ :::
66
+
67
+ ### Asset Configuration
68
+
69
+ All asset paths are relative to your application's asset directories.
70
+
71
+ ::: code-group
72
+ ```ruby [config.assets.logo]
73
+ # Path to the logo file.
74
+ config.assets.logo = "custom_logo.svg" # default: "plutonium.png"
75
+ ```
76
+ ```ruby [config.assets.favicon]
77
+ # Path to the favicon file.
78
+ config.assets.favicon = "custom_favicon.ico" # default: "plutonium.ico"
79
+ ```
80
+ ```ruby [config.assets.stylesheet]
81
+ # Path to the main stylesheet.
82
+ config.assets.stylesheet = "custom_theme.css" # default: "plutonium.css"
83
+ ```
84
+ ```ruby [config.assets.script]
85
+ # Path to the main JavaScript file.
86
+ config.assets.script = "custom_plutonium.js" # default: "plutonium.min.js"
87
+ ```
88
+ :::
89
+
90
+ ## Version Management
91
+
92
+ Plutonium uses a versioned configuration system to maintain backward compatibility. When upgrading, you can update the version number to adopt new defaults without breaking your existing setup.
93
+
94
+ ```ruby
95
+ Plutonium.configure do |config|
96
+ # Load defaults for version 1.0
97
+ config.load_defaults 1.0
98
+
99
+ # Override specific settings after loading defaults
100
+ config.assets.logo = "custom_logo.png"
101
+ end
102
+ ```
103
+
104
+ ::: details Version History
105
+ - **1.0**: Initial configuration version with base settings for development, caching, and asset management.
106
+ :::
107
+
108
+ ## Environment Variables
109
+
110
+ Some configuration options can be controlled via environment variables.
111
+
112
+ ::: code-group
113
+ ```bash [PLUTONIUM_DEV]
114
+ # Enable development mode
115
+ export PLUTONIUM_DEV=true
116
+
117
+ # Disable development mode
118
+ export PLUTONIUM_DEV=false
119
+ ```
120
+ ```ruby [Implementation]
121
+ # This is automatically parsed as a boolean:
122
+ config.development = parse_boolean_env("PLUTONIUM_DEV")
123
+ ```
124
+ :::
125
+
126
+ ::: details Adding Custom Environment Variables
127
+ You can extend the configuration object to support your own environment variables.
128
+ ```ruby
129
+ class CustomConfiguration < Plutonium::Configuration
130
+ attr_accessor :api_timeout, :max_file_size
131
+
132
+ def initialize
133
+ super
134
+ @api_timeout = parse_integer_env("PLUTONIUM_API_TIMEOUT", default: 30)
135
+ @max_file_size = parse_integer_env("PLUTONIUM_MAX_FILE_SIZE", default: 10.megabytes)
136
+ end
137
+
138
+ private
139
+
140
+ def parse_integer_env(env_var, default:)
141
+ ENV[env_var]&.to_i || default
142
+ end
143
+ end
144
+ ```
145
+ :::
146
+
147
+ ## Asset Management
148
+
149
+ ### Custom Assets
150
+
151
+ To use your own assets, place them in the appropriate `app/assets` directory and update the configuration in `plutonium.rb`.
152
+
153
+ ::: code-group
154
+ ```ruby [config/initializers/plutonium.rb]
155
+ Plutonium.configure do |config|
156
+ config.assets.logo = "custom_logo.png"
157
+ config.assets.stylesheet = "custom_theme.css"
158
+ end
159
+ ```
160
+ ```bash [File Structure]
161
+ app/assets/
162
+ ├── images/
163
+ │ └── custom_logo.png
164
+ └── stylesheets/
165
+ └── custom_theme.css
166
+ ```
167
+ :::
168
+
169
+ ### Asset Precompilation
170
+
171
+ Plutonium automatically adds its default assets to the precompile list.
172
+
173
+ ::: details Precompilation Control
174
+ To exclude default Plutonium assets from precompilation (for example, if you are providing your own builds), you can modify the precompile list.
175
+ ```ruby
176
+ # config/initializers/assets.rb
177
+ Rails.application.config.after_initialize do
178
+ Rails.application.config.assets.precompile -= Plutonium::Railtie::PRECOMPILE_ASSETS
179
+ end
180
+ ```
181
+ The `PRECOMPILE_ASSETS` constant contains a list of all default asset files.
182
+ :::
183
+
184
+ ## Development Features
185
+
186
+ ### Hot Reloading
187
+
188
+ Enable automatic reloading of Plutonium components during development:
189
+
190
+ ```ruby
191
+ Plutonium.configure do |config|
192
+ config.enable_hotreload = Rails.env.development?
193
+ end
194
+
195
+ # This starts the Plutonium::Reloader in after_initialize
196
+ ```
197
+
198
+ ### Development Asset Server
199
+
200
+ In development mode, Plutonium can serve assets directly from the source:
201
+
202
+ ```ruby
203
+ # Automatically configured when development = true
204
+ if Plutonium.configuration.development?
205
+ config.app_middleware.insert_before(
206
+ ActionDispatch::Static,
207
+ Rack::Static,
208
+ urls: ["/build"],
209
+ root: Plutonium.root.join("src").to_s
210
+ )
211
+ end
212
+ ```
213
+
214
+ ### Cache Discovery
215
+
216
+ Control resource discovery caching for development speed:
217
+
218
+ ```ruby
219
+ Plutonium.configure do |config|
220
+ # Disable caching in development for faster iteration
221
+ config.cache_discovery = !Rails.env.development?
222
+
223
+ # Or force enable for testing cache behavior
224
+ config.cache_discovery = true
225
+ end
226
+ ```
227
+
228
+ ## Environment-Specific Configuration
229
+
230
+ ### Development Configuration
231
+
232
+ ```ruby
233
+ # config/initializers/plutonium.rb
234
+ Plutonium.configure do |config|
235
+ config.load_defaults 1.0
236
+
237
+ if Rails.env.development?
238
+ config.development = true
239
+ config.cache_discovery = false
240
+ config.enable_hotreload = true
241
+
242
+ # Development-specific assets
243
+ config.assets.stylesheet = "plutonium_dev.css"
244
+ end
245
+ end
246
+ ```
247
+
248
+ ### Production Configuration
249
+
250
+ ```ruby
251
+ Plutonium.configure do |config|
252
+ config.load_defaults 1.0
253
+
254
+ if Rails.env.production?
255
+ config.development = false
256
+ config.cache_discovery = true
257
+ config.enable_hotreload = false
258
+
259
+ # Production-optimized assets
260
+ config.assets.script = "plutonium.min.js"
261
+ config.assets.stylesheet = "plutonium.min.css"
262
+ end
263
+ end
264
+ ```
265
+
266
+ ### Test Configuration
267
+
268
+ ```ruby
269
+ Plutonium.configure do |config|
270
+ config.load_defaults 1.0
271
+
272
+ if Rails.env.test?
273
+ config.development = false
274
+ config.cache_discovery = false
275
+ config.enable_hotreload = false
276
+
277
+ # Test-specific settings for speed
278
+ config.assets.script = "plutonium_test.js"
279
+ end
280
+ end
281
+ ```
282
+
283
+ ## Advanced Configuration
284
+
285
+ ### Custom Configuration Classes
286
+
287
+ Extend the configuration system with custom options:
288
+
289
+ ```ruby
290
+ # lib/my_app/configuration.rb
291
+ module MyApp
292
+ class Configuration < Plutonium::Configuration
293
+ attr_accessor :custom_feature_enabled
294
+ attr_accessor :api_timeout
295
+ attr_accessor :theme_mode
296
+
297
+ def initialize
298
+ super
299
+ @custom_feature_enabled = false
300
+ @api_timeout = 30
301
+ @theme_mode = "auto"
302
+ end
303
+
304
+ def load_defaults(version)
305
+ super
306
+
307
+ # Custom defaults for your application
308
+ case version
309
+ when 1.0
310
+ @custom_feature_enabled = true
311
+ @theme_mode = "light"
312
+ end
313
+ end
314
+ end
315
+ end
316
+
317
+ # Replace Plutonium's configuration
318
+ Plutonium.instance_variable_set(:@configuration, MyApp::Configuration.new)
319
+ ```
320
+
321
+ ### Conditional Configuration
322
+
323
+ Apply configuration based on various conditions:
324
+
325
+ ```ruby
326
+ Plutonium.configure do |config|
327
+ config.load_defaults 1.0
328
+
329
+ # Feature flags from environment
330
+ config.development = Rails.env.development? || ENV['FORCE_DEV_MODE'] == 'true'
331
+
332
+ # Multi-tenant asset configuration
333
+ if defined?(Current) && Current.tenant&.custom_branding?
334
+ config.assets.logo = "tenant_#{Current.tenant.id}_logo.png"
335
+ config.assets.stylesheet = "tenant_#{Current.tenant.id}_theme.css"
336
+ end
337
+
338
+ # Performance settings based on server capacity
339
+ if ENV['SERVER_TIER'] == 'high'
340
+ config.cache_discovery = true
341
+ config.enable_hotreload = false
342
+ elsif ENV['SERVER_TIER'] == 'development'
343
+ config.cache_discovery = false
344
+ config.enable_hotreload = true
345
+ end
346
+ end
347
+ ```
348
+
349
+ ### Configuration Validation
350
+
351
+ Add validation to ensure configuration integrity:
352
+
353
+ ```ruby
354
+ class ValidatedConfiguration < Plutonium::Configuration
355
+ def validate!
356
+ raise "Logo file not found: #{assets.logo}" unless logo_exists?
357
+ raise "Invalid theme" unless %w[light dark auto].include?(theme_mode)
358
+ raise "API timeout must be positive" unless api_timeout > 0
359
+ end
360
+
361
+ private
362
+
363
+ def logo_exists?
364
+ Rails.application.assets.find_asset(assets.logo) ||
365
+ File.exist?(Rails.root.join("app/assets/images", assets.logo))
366
+ end
367
+ end
368
+ ```
369
+
370
+ ## Integration with Rails
371
+
372
+ ### Railtie Integration
373
+
374
+ Configuration is integrated with Rails through the Railtie system:
375
+
376
+ ```ruby
377
+ # lib/plutonium/railtie.rb
378
+ initializer "plutonium.base" do
379
+ Rails.application.class.include Plutonium::Engine
380
+ end
381
+
382
+ initializer "plutonium.asset_server" do
383
+ setup_development_asset_server if Plutonium.configuration.development?
384
+ end
385
+
386
+ config.after_initialize do
387
+ Plutonium::Reloader.start! if Plutonium.configuration.enable_hotreload
388
+ Plutonium::Loader.eager_load if Rails.env.production?
389
+ end
390
+ ```
391
+
392
+ ### Engine Configuration
393
+
394
+ Configuration affects how Plutonium engines behave:
395
+
396
+ ```ruby
397
+ # Conditional middleware setup based on configuration
398
+ if Plutonium.configuration.development?
399
+ config.app_middleware.insert_before(
400
+ ActionDispatch::Static,
401
+ Rack::Static,
402
+ urls: ["/build"],
403
+ root: Plutonium.root.join("src").to_s
404
+ )
405
+ end
406
+ ```
407
+
408
+ ## Testing Configuration
409
+
410
+ ### Test Environment Setup
411
+
412
+ ```ruby
413
+ # spec/spec_helper.rb or test/test_helper.rb
414
+ Plutonium.configure do |config|
415
+ config.load_defaults 1.0
416
+ config.development = false
417
+ config.cache_discovery = false
418
+ config.enable_hotreload = false
419
+
420
+ # Test-specific asset configuration
421
+ config.assets.logo = "test_logo.png"
422
+ config.assets.stylesheet = "test_theme.css"
423
+ end
424
+ ```
425
+
426
+ ### Configuration Testing
427
+
428
+ ```ruby
429
+ RSpec.describe 'Plutonium configuration' do
430
+ let(:config) { Plutonium::Configuration.new }
431
+
432
+ describe '#load_defaults' do
433
+ it 'loads version 1.0 defaults' do
434
+ config.load_defaults 1.0
435
+ expect(config.defaults_version).to eq(1.0)
436
+ end
437
+
438
+ it 'raises error for unknown version' do
439
+ expect { config.load_defaults 2.0 }.to raise_error(/No applicable defaults/)
440
+ end
441
+ end
442
+
443
+ describe 'asset configuration' do
444
+ it 'has default asset paths' do
445
+ expect(config.assets.logo).to eq("plutonium.png")
446
+ expect(config.assets.favicon).to eq("plutonium.ico")
447
+ expect(config.assets.stylesheet).to eq("plutonium.css")
448
+ expect(config.assets.script).to eq("plutonium.min.js")
449
+ end
450
+
451
+ it 'allows custom asset configuration' do
452
+ config.assets.logo = "custom_logo.svg"
453
+ expect(config.assets.logo).to eq("custom_logo.svg")
454
+ end
455
+ end
456
+
457
+ describe 'environment variable parsing' do
458
+ around do |example|
459
+ original_env = ENV["PLUTONIUM_DEV"]
460
+ example.run
461
+ ENV["PLUTONIUM_DEV"] = original_env
462
+ end
463
+
464
+ it 'parses PLUTONIUM_DEV as boolean' do
465
+ ENV["PLUTONIUM_DEV"] = "true"
466
+ config = Plutonium::Configuration.new
467
+ expect(config.development?).to be true
468
+
469
+ ENV["PLUTONIUM_DEV"] = "false"
470
+ config = Plutonium::Configuration.new
471
+ expect(config.development?).to be false
472
+ end
473
+ end
474
+ end
475
+ ```
476
+
477
+ ### Configuration Helpers
478
+
479
+ ```ruby
480
+ # spec/support/configuration_helpers.rb
481
+ module ConfigurationHelpers
482
+ def with_plutonium_config(**options)
483
+ original_config = Plutonium.configuration.dup
484
+
485
+ options.each do |key, value|
486
+ if key.to_s.include?('.')
487
+ # Handle nested configuration like 'assets.logo'
488
+ keys = key.to_s.split('.')
489
+ target = keys[0..-2].reduce(Plutonium.configuration) { |config, k| config.send(k) }
490
+ target.send("#{keys.last}=", value)
491
+ else
492
+ Plutonium.configuration.send("#{key}=", value)
493
+ end
494
+ end
495
+
496
+ yield
497
+ ensure
498
+ Plutonium.instance_variable_set(:@configuration, original_config)
499
+ end
500
+ end
501
+
502
+ # Usage in tests
503
+ RSpec.describe "Feature with custom config" do
504
+ include ConfigurationHelpers
505
+
506
+ it "works with development mode enabled" do
507
+ with_plutonium_config(development: true, enable_hotreload: true) do
508
+ # Test behavior with development mode
509
+ end
510
+ end
511
+
512
+ it "works with custom assets" do
513
+ with_plutonium_config('assets.logo' => 'custom.png') do
514
+ # Test behavior with custom logo
515
+ end
516
+ end
517
+ end
518
+ ```
519
+
520
+ ## Best Practices
521
+
522
+ ### Configuration Organization
523
+
524
+ 1. **Use initializers**: Place configuration in `config/initializers/plutonium.rb`
525
+ 2. **Load defaults first**: Always call `load_defaults` before customizing settings
526
+ 3. **Environment-specific**: Use environment checks for conditional configuration
527
+ 4. **Document custom settings**: Comment any non-standard configuration options
528
+
529
+ ### Performance Considerations
530
+
531
+ 1. **Cache in production**: Enable `cache_discovery` in production environments
532
+ 2. **Disable dev features**: Turn off development features in production
533
+ 3. **Optimize assets**: Use minified assets for production
534
+ 4. **Selective hot reload**: Only enable hot reloading in development
535
+
536
+ ### Security Considerations
537
+
538
+ 1. **Environment variables**: Use environment variables for sensitive configuration
539
+ 2. **Validate asset paths**: Ensure custom asset paths are safe and exist
540
+ 3. **Production mode**: Never enable development mode in production
541
+ 4. **Access control**: Restrict who can modify configuration in production
542
+
543
+ ### Maintenance Guidelines
544
+
545
+ 1. **Version compatibility**: Test configuration changes across supported versions
546
+ 2. **Gradual adoption**: Introduce new configuration options incrementally
547
+ 3. **Backward compatibility**: Maintain compatibility when adding new options
548
+ 4. **Documentation**: Keep configuration documentation up to date
549
+
550
+ ## Migration and Upgrade Guide
551
+
552
+ ### Upgrading Configuration Versions
553
+
554
+ When upgrading Plutonium versions:
555
+
556
+ ```ruby
557
+ # Before (v1.0)
558
+ Plutonium.configure do |config|
559
+ config.development = Rails.env.development?
560
+ config.cache_discovery = !Rails.env.development?
561
+ # ... other settings
562
+ end
563
+
564
+ # After (hypothetical v1.1)
565
+ Plutonium.configure do |config|
566
+ config.load_defaults 1.1 # Load new version defaults
567
+ config.development = Rails.env.development?
568
+ config.cache_discovery = !Rails.env.development?
569
+ # ... existing settings
570
+ # ... any new v1.1 features
571
+ end
572
+ ```
573
+
574
+ ### Configuration File Migration
575
+
576
+ When moving from older configuration approaches:
577
+
578
+ ```ruby
579
+ # Old approach (deprecated)
580
+ Rails.application.configure do
581
+ config.plutonium.development = true
582
+ end
583
+
584
+ # New approach (recommended)
585
+ Plutonium.configure do |config|
586
+ config.load_defaults 1.0
587
+ config.development = true
588
+ end
589
+ ```
590
+
591
+ ## Integration Points
592
+
593
+ - **Core Module**: Configuration affects core controller behavior and features
594
+ - **Asset Module**: Asset configuration controls frontend resource loading
595
+ - **Portal Module**: Configuration can affect portal-specific behaviors
596
+ - **Authentication Module**: Development settings affect authentication flows
597
+ - **Resource Module**: Cache settings affect resource discovery and loading
598
+
599
+ The Configuration module provides a flexible, extensible foundation for customizing Plutonium behavior while maintaining compatibility and providing sensible defaults for different environments.