plutonium 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a68eccc72cf54155fa9d9959a22b60d13ea434a4faf34221ec0314e5ab74124
4
- data.tar.gz: 99c748e56b3b07eb7361f67887137430eef9cb35a3e0b3bd04c1de831ae68b04
3
+ metadata.gz: fba393cb403832162cff127ae398c28751984ad8070292ea2e4bc0b01e726678
4
+ data.tar.gz: deeca5afea70265663e0343d2b23fb7f0522fcacbd8c6f79fe864b6b0b2fd7a7
5
5
  SHA512:
6
- metadata.gz: 6ada4ff77eddc1daa695bd4ff96542f5f72b378ab7826c99f256faa089182c9084edd5db2433d044d6270df5714097e9e46add301631446ead9c1ae034ead0b9
7
- data.tar.gz: e600eb51acf5873891b4c38b4541e1220c4e62f19eb74b9194c68203e73e0178d3e6ef74ee9437daf9dd27ced14b93ebe2807d3f4338b160e3de26dddd21691b
6
+ metadata.gz: aad819f43bb0a0707d02649fc169b9f4fa9e3bac860bb7fb01530d4f630a36e025eaea4f6e1502c94cb50b04c139735ad46eb9bef1de91d27ebfaf1e6461f589
7
+ data.tar.gz: 9c3bdb87605c5fa2339285b8a0ae6347016f40b72fbbfcdf93cadaf21281a0a1ce07dfb2630bc006a404e2265eefbc20dc238272c6e5091b8e6eaf871e5f892d
@@ -37,8 +37,8 @@ module Pu
37
37
  registerControllers(application)
38
38
  EOT
39
39
 
40
- environment "config.plutonium.assets.stylesheet = \"application\""
41
- environment "config.plutonium.assets.script = \"application\""
40
+ configure_plutonium "config.assets.stylesheet = \"application\""
41
+ configure_plutonium "config.assets.script = \"application\""
42
42
  end
43
43
  end
44
44
  end
@@ -31,9 +31,6 @@ module Pu
31
31
  def setup_app
32
32
  directory "config"
33
33
  directory "app"
34
-
35
- environment "# config.plutonium.assets.favicon = \"favicon.ico\""
36
- environment "# config.plutonium.assets.logo = \"logo.png\""
37
34
  end
38
35
 
39
36
  def eject_views
@@ -1,5 +1,15 @@
1
1
  # Configure plutonium
2
2
 
3
+ Plutonium.configure do |config|
4
+ config.load_defaults 1.0
5
+
6
+ # config.assets.logo = "logo.png"
7
+ # Configure plutonium above this
8
+ end
9
+
3
10
  Rails.application.config.to_prepare do
4
11
  # Register components here
12
+
13
+ # e.g
14
+ # Plutonium::Core::Fields::Renderers::Factory.map_type :mapped_collection, to: Fields::Renderers::MappedCollectionRenderer
5
15
  end
@@ -272,6 +272,25 @@ module PlutoniumGenerators
272
272
  end
273
273
  end
274
274
 
275
+ def configure_plutonium(data = nil, options = {})
276
+ data ||= yield if block_given?
277
+
278
+ log :configure_plutonium, data
279
+
280
+ in_root do
281
+ replace_existing = ->(file, data) do
282
+ gsub_file file, Regexp.new(".*#{data.split("=").first.strip}.*=.*\n"), data, verbose: false
283
+ end
284
+
285
+ data = optimize_indentation(data, 2)
286
+ file = "config/initializers/plutonium.rb"
287
+ replace_existing.call file, data
288
+ break if File.read(file).match? regexify_config(data)
289
+
290
+ inject_into_file file, data, before: /.*# Configure plutonium above this.*/, verbose: false
291
+ end
292
+ end
293
+
275
294
  #
276
295
  # Set a config in the application generator block
277
296
  # If the configuration exists already, it is updated
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plutonium
4
+ module Config
5
+ # OverlayedHash provides a hash-like structure that overlays values on top of a base hash.
6
+ #
7
+ # This class allows you to create a new hash-like object that uses a base hash for default values,
8
+ # but can be modified without affecting the original base hash. When a key is accessed, it first
9
+ # checks if the key exists in the overlay; if not, it falls back to the base hash.
10
+ #
11
+ # @example Usage
12
+ # base = { a: 1, b: 2 }
13
+ # overlay = OverlayedHash.new(base)
14
+ # overlay[:b] = 3
15
+ # overlay[:c] = 4
16
+ #
17
+ # overlay[:a] # => 1 (from base)
18
+ # overlay[:b] # => 3 (from overlay)
19
+ # overlay[:c] # => 4 (from overlay)
20
+ # base[:b] # => 2 (unchanged)
21
+ class OverlayedHash
22
+ # Initialize a new OverlayedHash with a base hash.
23
+ #
24
+ # @param base [Hash] The base hash to use for fallback values.
25
+ def initialize(base)
26
+ @base = base
27
+ @overlay = {}
28
+ end
29
+
30
+ # Retrieve a value from the overlay hash or the base hash.
31
+ #
32
+ # @param key The key to look up.
33
+ # @return The value associated with the key, or nil if not found.
34
+ def [](key)
35
+ @overlay.key?(key) ? @overlay[key] : @base[key]
36
+ end
37
+
38
+ # Set a value in the overlay hash.
39
+ #
40
+ # @param key The key to set.
41
+ # @param value The value to associate with the key.
42
+ def []=(key, value)
43
+ @overlay[key] = value
44
+ end
45
+
46
+ # Check if a key exists in either the overlay or base hash.
47
+ #
48
+ # @param key The key to check for.
49
+ # @return [Boolean] true if the key exists, false otherwise.
50
+ def key?(key)
51
+ @overlay.key?(key) || @base.key?(key)
52
+ end
53
+
54
+ # Enumerate over all keys in both the overlay and base hash.
55
+ #
56
+ # @yield [key] Gives each key to the block.
57
+ # @return [Enumerator] If no block is given.
58
+ def each_key
59
+ return to_enum(:each_key) unless block_given?
60
+
61
+ keys.each { |key| yield key }
62
+ end
63
+
64
+ # Retrieve all keys from both the overlay and base hash.
65
+ #
66
+ # @return [Array] An array of all unique keys.
67
+ def keys
68
+ (@overlay.keys + @base.keys).uniq
69
+ end
70
+
71
+ # Retrieve all values, prioritizing the overlay over the base.
72
+ #
73
+ # @return [Array] An array of values corresponding to all keys.
74
+ def values
75
+ keys.map { |key| self[key] }
76
+ end
77
+
78
+ # Convert the OverlayedHash to a regular Hash.
79
+ #
80
+ # @return [Hash] A new Hash with all keys and values from the OverlayedHash.
81
+ def to_h
82
+ keys.each_with_object({}) { |key, hash| hash[key] = self[key] }
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plutonium
4
+ # Configuration class for Plutonium module
5
+ #
6
+ # @example
7
+ # Plutonium.configure do |config|
8
+ # config.load_defaults 1.0
9
+ # config.development = true
10
+ # config.cache_discovery = false
11
+ # config.enable_hotreload = true
12
+ # config.assets.logo = "custom_logo.png"
13
+ # end
14
+ class Configuration
15
+ # @return [Boolean] whether Plutonium is in development mode
16
+ attr_accessor :development
17
+
18
+ # @return [Boolean] whether to cache discovery
19
+ attr_accessor :cache_discovery
20
+
21
+ # @return [Boolean] whether to enable hot reloading
22
+ attr_accessor :enable_hotreload
23
+
24
+ # @return [AssetConfiguration] asset configuration
25
+ attr_reader :assets
26
+
27
+ # @return [Float] the current defaults version
28
+ attr_reader :defaults_version
29
+
30
+ # Map of version numbers to their default configurations
31
+ VERSION_DEFAULTS = {
32
+ 1.0 => proc do |config|
33
+ # No changes for 1.0 yet as it's the current base configuration
34
+ end
35
+ # Add more version configurations here as needed
36
+ # 1.1 => proc do |config|
37
+ # config.some_new_setting = true
38
+ # end
39
+ }.freeze
40
+
41
+ # Initialize a new Configuration instance
42
+ #
43
+ # @note This method sets initial values
44
+ def initialize
45
+ @defaults_version = nil
46
+ @assets = AssetConfiguration.new
47
+
48
+ @development = parse_boolean_env("PLUTONIUM_DEV")
49
+ @cache_discovery = !Rails.env.development?
50
+ @enable_hotreload = Rails.env.development?
51
+ end
52
+
53
+ # Load default configuration for a specific version
54
+ #
55
+ # @param version [Float] the version to load defaults for
56
+ # @return [void]
57
+ def load_defaults(version)
58
+ available_versions = VERSION_DEFAULTS.keys.sort
59
+ applicable_versions = available_versions.select { |v| v <= version }
60
+
61
+ if applicable_versions.empty?
62
+ raise "No applicable defaults found for version #{version}."
63
+ end
64
+
65
+ applicable_versions.each do |v|
66
+ VERSION_DEFAULTS[v].call(self)
67
+ end
68
+
69
+ @defaults_version = applicable_versions.last
70
+ end
71
+
72
+ # whether Plutonium is in development mode
73
+ #
74
+ # @return [Boolean]
75
+ def development?
76
+ @development
77
+ end
78
+
79
+ private
80
+
81
+ # Parse boolean environment variable
82
+ #
83
+ # @param env_var [String] name of the environment variable
84
+ # @return [Boolean] parsed boolean value
85
+ def parse_boolean_env(env_var)
86
+ ActiveModel::Type::Boolean.new.cast(ENV[env_var]).present?
87
+ end
88
+
89
+ # Asset configuration for Plutonium
90
+ class AssetConfiguration
91
+ # @return [String] path to logo file
92
+ attr_accessor :logo
93
+
94
+ # @return [String] path to favicon file
95
+ attr_accessor :favicon
96
+
97
+ # @return [String] path to stylesheet file
98
+ attr_accessor :stylesheet
99
+
100
+ # @return [String] path to JavaScript file
101
+ attr_accessor :script
102
+
103
+ # Initialize a new AssetConfiguration instance with default values
104
+ def initialize
105
+ @logo = "plutonium.png"
106
+ @favicon = "plutonium.ico"
107
+ @stylesheet = "plutonium.css"
108
+ @script = "plutonium.min.js"
109
+ end
110
+ end
111
+ end
112
+
113
+ class << self
114
+ # Get the current configuration
115
+ #
116
+ # @return [Configuration] current configuration instance
117
+ def configuration
118
+ @configuration ||= Configuration.new
119
+ end
120
+
121
+ # Configure Plutonium
122
+ #
123
+ # @yield [config] Configuration instance
124
+ # @yieldparam config [Configuration] current configuration instance
125
+ # @return [void]
126
+ def configure
127
+ yield(configuration)
128
+ end
129
+
130
+ # Load default configuration for a specific version
131
+ #
132
+ # @param version [Float] the version to load defaults for
133
+ # @return [void]
134
+ def load_defaults(version)
135
+ configuration.load_defaults(version)
136
+ end
137
+ end
138
+ end
@@ -14,7 +14,7 @@ module Plutonium
14
14
  # If cache_discovery is enabled, use the class level cache that persists
15
15
  # between requests, otherwise use the instance one.
16
16
  def autodiscovery_association_renderer_cache
17
- if Rails.application.config.plutonium.cache_discovery
17
+ if Plutonium.configuration.cache_discovery
18
18
  self.class.autodiscovery_association_renderer_cache
19
19
  else
20
20
  @autodiscovery_association_renderer_cache ||= {}
@@ -14,7 +14,7 @@ module Plutonium
14
14
  # If cache_discovery is enabled, use the class level cache that persists
15
15
  # between requests, otherwise use the instance one.
16
16
  def autodiscovery_input_cache
17
- if Rails.application.config.plutonium.cache_discovery
17
+ if Plutonium.configuration.cache_discovery
18
18
  self.class.autodiscovery_input_cache
19
19
  else
20
20
  @autodiscovery_input_cache ||= {}
@@ -14,7 +14,7 @@ module Plutonium
14
14
  # If cache_discovery is enabled, use the class level cache that persists
15
15
  # between requests, otherwise use the instance one.
16
16
  def autodiscovery_renderer_cache
17
- if Rails.application.config.plutonium.cache_discovery
17
+ if Plutonium.configuration.cache_discovery
18
18
  self.class.autodiscovery_renderer_cache
19
19
  else
20
20
  @autodiscovery_renderer_cache ||= {}
@@ -1,41 +1,94 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plutonium
2
4
  module Helpers
5
+ # Helper module for managing asset-related functionality
3
6
  module AssetsHelper
7
+ # Generate a stylesheet tag for the resource
8
+ #
9
+ # @return [ActiveSupport::SafeBuffer] HTML stylesheet link tag
4
10
  def resource_stylesheet_tag
5
- url = if Plutonium.development?
6
- filename = JSON.parse(File.read(Plutonium.root.join("src", "build", "css.manifest")))["plutonium.css"]
7
- "/build/#{filename}"
8
- else
9
- resource_stylesheet_asset
10
- end
11
- stylesheet_link_tag url, "data-turbo-track": "reload"
11
+ url = resource_asset_url_for(:css, resource_stylesheet_asset)
12
+ stylesheet_link_tag(url, "data-turbo-track": "reload")
12
13
  end
13
14
 
15
+ # Generate a script tag for the resource
16
+ #
17
+ # @return [ActiveSupport::SafeBuffer] HTML script tag
14
18
  def resource_script_tag
15
- url = if Plutonium.development?
16
- filename = JSON.parse(File.read(Plutonium.root.join("src", "build", "js.manifest")))["plutonium.js"]
17
- "/build/#{filename}"
18
- else
19
- resource_script_asset
20
- end
21
- javascript_include_tag url, "data-turbo-track": "reload", type: "module"
19
+ url = resource_asset_url_for(:js, resource_script_asset)
20
+ javascript_include_tag(url, "data-turbo-track": "reload", type: "module")
22
21
  end
23
22
 
23
+ # Generate a favicon link tag
24
+ #
25
+ # @return [ActiveSupport::SafeBuffer] HTML favicon link tag
24
26
  def resource_favicon_tag
25
- favicon_link_tag resource_favicon_asset
27
+ favicon_link_tag(resource_favicon_asset)
26
28
  end
27
29
 
30
+ # Generate an image tag for the logo
31
+ #
32
+ # @param classname [String] CSS class name for the image tag
33
+ # @return [ActiveSupport::SafeBuffer] HTML image tag
28
34
  def resource_logo_tag(classname:)
29
- image_tag resource_logo_asset, class: classname
35
+ image_tag(resource_logo_asset, class: classname)
30
36
  end
31
37
 
32
- def resource_logo_asset = Rails.application.config.plutonium.assets.logo
38
+ # Get the logo asset path
39
+ #
40
+ # @return [String] path to the logo asset
41
+ def resource_logo_asset
42
+ Plutonium.configuration.assets.logo
43
+ end
33
44
 
34
- def resource_stylesheet_asset = Rails.application.config.plutonium.assets.stylesheet
45
+ # Get the stylesheet asset path
46
+ #
47
+ # @return [String] path to the stylesheet asset
48
+ def resource_stylesheet_asset
49
+ Plutonium.configuration.assets.stylesheet
50
+ end
35
51
 
36
- def resource_script_asset = Rails.application.config.plutonium.assets.script
52
+ # Get the script asset path
53
+ #
54
+ # @return [String] path to the script asset
55
+ def resource_script_asset
56
+ Plutonium.configuration.assets.script
57
+ end
37
58
 
38
- def resource_favicon_asset = Rails.application.config.plutonium.assets.favicon
59
+ # Get the favicon asset path
60
+ #
61
+ # @return [String] path to the favicon asset
62
+ def resource_favicon_asset
63
+ Plutonium.configuration.assets.favicon
64
+ end
65
+
66
+ private
67
+
68
+ # Generate the appropriate asset URL based on the environment
69
+ #
70
+ # @param type [Symbol] asset type (:css or :js)
71
+ # @param fallback [String] fallback asset path
72
+ # @return [String] asset URL
73
+ def resource_asset_url_for(type, fallback)
74
+ if Plutonium.configuration.development?
75
+ resource_development_asset_url(type)
76
+ else
77
+ fallback
78
+ end
79
+ end
80
+
81
+ # Generate the asset URL for development environment
82
+ #
83
+ # @param type [Symbol] asset type (:css or :js)
84
+ # @return [String] asset URL for development
85
+ def resource_development_asset_url(type)
86
+ manifest_file = (type == :css) ? "css.manifest" : "js.manifest"
87
+ asset_key = (type == :css) ? "plutonium.css" : "plutonium.js"
88
+
89
+ filename = JSON.parse(File.read(Plutonium.root.join("src", "build", manifest_file)))[asset_key]
90
+ "/build/#{filename}"
91
+ end
39
92
  end
40
93
  end
41
94
  end
@@ -8,18 +8,6 @@ module Plutonium
8
8
  # This Railtie sets up configurations, initializers, and tasks for Plutonium
9
9
  # to work seamlessly within a Rails environment.
10
10
  class Railtie < Rails::Railtie
11
- # Configuration options for Plutonium
12
- config.plutonium = ActiveSupport::OrderedOptions.new
13
- config.plutonium.cache_discovery = !Rails.env.development?
14
- config.plutonium.enable_hotreload = Rails.env.development?
15
-
16
- # Asset configuration
17
- config.plutonium.assets = ActiveSupport::OrderedOptions.new
18
- config.plutonium.assets.logo = "plutonium.png"
19
- config.plutonium.assets.favicon = "plutonium.ico"
20
- config.plutonium.assets.stylesheet = "plutonium.css"
21
- config.plutonium.assets.script = "plutonium.min.js"
22
-
23
11
  # Assets to be precompiled
24
12
  #
25
13
  # If you don't want to precompile Plutonium's assets (eg. because you're using webpack),
@@ -46,7 +34,7 @@ module Plutonium
46
34
  end
47
35
 
48
36
  initializer "plutonium.asset_server" do
49
- setup_development_asset_server if Plutonium.development?
37
+ setup_development_asset_server if Plutonium.configuration.development?
50
38
  end
51
39
 
52
40
  initializer "plutonium.view_components_capture_compat" do
@@ -62,7 +50,7 @@ module Plutonium
62
50
  end
63
51
 
64
52
  config.after_initialize do
65
- Plutonium::Reloader.start! if Rails.application.config.plutonium.enable_hotreload
53
+ Plutonium::Reloader.start! if Plutonium.configuration.enable_hotreload
66
54
  Plutonium::ZEITWERK_LOADER.eager_load if Rails.env.production?
67
55
  end
68
56
 
@@ -1,15 +1,21 @@
1
- require "active_support/notifications"
1
+ # frozen_string_literal: true
2
2
 
3
- # Be sure to restart your server when you modify this file.
3
+ require "active_support/notifications"
4
4
 
5
5
  module Plutonium
6
+ # Reloader class for Plutonium
7
+ #
8
+ # This class is responsible for managing the reloading of Plutonium components
9
+ # and related files during development.
6
10
  class Reloader
7
11
  class << self
12
+ # Start the reloader
13
+ #
14
+ # @return [void]
8
15
  def start!
9
16
  puts "=> [plutonium] starting reloader"
10
17
 
11
18
  ActiveSupport::Notifications.instrument("plutonium.reloader.start") do
12
- # Task code here
13
19
  @listener&.stop
14
20
  @listener = initialize_listener
15
21
  end
@@ -17,34 +23,46 @@ module Plutonium
17
23
 
18
24
  private
19
25
 
26
+ # Initialize the file listener
27
+ #
28
+ # @return [Listen::Listener, nil] the initialized listener or nil if no paths to watch
20
29
  def initialize_listener
21
30
  require "listen"
22
31
 
23
32
  reload_paths = gather_reload_paths
24
- return unless reload_paths.any?
33
+ return if reload_paths.empty?
25
34
 
26
- listener = Listen.to(*reload_paths, only: /\.rb$/) do |modified, added, removed|
35
+ Listen.to(*reload_paths, only: /\.rb$/) { |modified, added, removed|
27
36
  handle_file_changes(modified, added, removed)
28
- end
29
- listener.start
30
- listener
37
+ }.tap(&:start)
31
38
  end
32
39
 
40
+ # Gather paths to be watched for changes
41
+ #
42
+ # @return [Array<String>] list of paths to watch
33
43
  def gather_reload_paths
34
44
  reload_paths = []
35
45
 
36
- if Plutonium.development?
37
- reload_paths << Plutonium.lib_root.to_s
38
- reload_paths << Plutonium.root.join("app", "views", "components").to_s
39
- reload_paths << Plutonium.root.join("config", "initializers").to_s
46
+ if Plutonium.configuration.development?
47
+ reload_paths.concat([
48
+ Plutonium.lib_root.to_s,
49
+ Plutonium.root.join("app", "views", "components").to_s,
50
+ Plutonium.root.join("config", "initializers").to_s
51
+ ])
40
52
  end
41
53
 
42
- packages_dir = Rails.root.join("packages/").to_s
54
+ packages_dir = Rails.root.join("packages").to_s
43
55
  reload_paths << packages_dir if File.directory?(packages_dir)
44
56
 
45
57
  reload_paths
46
58
  end
47
59
 
60
+ # Handle file changes detected by the listener
61
+ #
62
+ # @param modified [Array<String>] list of modified files
63
+ # @param added [Array<String>] list of added files
64
+ # @param removed [Array<String>] list of removed files
65
+ # @return [void]
48
66
  def handle_file_changes(modified, added, removed)
49
67
  (modified + added).each do |file|
50
68
  Plutonium.logger.debug "[plutonium] change detected: #{file}"
@@ -62,46 +80,70 @@ module Plutonium
62
80
  end
63
81
  end
64
82
 
83
+ # Check if the file is within the packages directory
84
+ #
85
+ # @param file [String] path to the file
86
+ # @return [Boolean] true if the file is within the packages directory
65
87
  def file_starts_with_packages_dir?(file)
66
- packages_dir = Rails.root.join("packages/").to_s
67
- file.starts_with?(packages_dir)
88
+ file.start_with?(Rails.root.join("packages").to_s)
68
89
  end
69
90
 
91
+ # Handle changes to files within the packages directory
92
+ #
93
+ # @param file [String] path to the changed file
94
+ # @param added [Array<String>] list of added files
95
+ # @return [void]
70
96
  def handle_package_file_changes(file, added)
71
97
  return if added.include?(file)
72
98
 
73
99
  case File.basename(file)
74
100
  when "engine.rb"
75
101
  reload_engine_and_routes(file)
76
- else
77
- # Non-engine package files are reloaded by Rails automatically
78
102
  end
79
103
  end
80
104
 
105
+ # Reload engine and routes
106
+ #
107
+ # @param file [String] path to the engine file
108
+ # @return [void]
81
109
  def reload_engine_and_routes(file)
82
110
  Plutonium.logger.debug "[plutonium] reloading: engine+routes"
83
111
  load file
84
112
  Rails.application.reload_routes!
85
113
  end
86
114
 
115
+ # Reload the framework and file
116
+ #
117
+ # @param file [String] path to the file
118
+ # @return [void]
87
119
  def reload_framework_and_file(file)
88
- # # Ensure that the file loads correctly before we do any reloading
89
- # load file
90
-
91
120
  Plutonium.logger.debug "[plutonium] reloading: app+framework"
92
121
  Rails.application.reloader.reload!
93
122
  Plutonium::ZEITWERK_LOADER.reload
94
- # reload components
123
+ reload_components
124
+ end
125
+
126
+ # Reload components
127
+ #
128
+ # @return [void]
129
+ def reload_components
95
130
  Object.send(:remove_const, "PlutoniumUi")
96
131
  load Plutonium.root.join("app", "views", "components", "base.rb")
97
- # # Ensure files that do not contain constants are loaded again e.g. initializers
98
- # load file
99
132
  end
100
133
 
134
+ # Reload a single file
135
+ #
136
+ # @param file [String] path to the file
137
+ # @return [Boolean] true if the file was successfully loaded
101
138
  def reload_file(file)
102
- load file
139
+ load(file)
103
140
  end
104
141
 
142
+ # Log reload failure
143
+ #
144
+ # @param file [String] path to the file that failed to reload
145
+ # @param error [StandardError] the error that occurred during reloading
146
+ # @return [void]
105
147
  def log_reload_failure(file, error)
106
148
  Plutonium.logger.error "\n[plutonium] reloading failed\n\n#{error.message}\n"
107
149
  end
@@ -1,3 +1,3 @@
1
1
  module Plutonium
2
- VERSION = "0.14.0"
2
+ VERSION = "0.14.1"
3
3
  end
data/lib/plutonium.rb CHANGED
@@ -1,57 +1,71 @@
1
- require "zeitwerk"
2
-
3
- # Zeitwerk loader setup for the Plutonium gem
4
- loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
5
- loader.ignore("#{__dir__}/generators")
6
- loader.ignore("#{__dir__}/plutonium/railtie.rb")
7
- loader.enable_reloading if defined?(Rails.env) && Rails.env.development?
8
- loader.setup
1
+ # frozen_string_literal: true
9
2
 
10
- require_relative "plutonium/railtie" if defined?(Rails::Railtie)
3
+ require "zeitwerk"
4
+ require_relative "plutonium/configuration"
11
5
 
6
+ # Plutonium module
7
+ #
8
+ # This module provides the main functionality for the Plutonium gem.
9
+ # It sets up autoloading using Zeitwerk and provides utility methods
10
+ # for accessing gem-related information.
12
11
  module Plutonium
13
- # Custom error class for the Plutonium module
12
+ # Custom error class for Plutonium-specific exceptions
14
13
  class Error < StandardError; end
15
14
 
15
+ # Set up Zeitwerk loader for the Plutonium gem
16
+ # @return [Zeitwerk::Loader] configured Zeitwerk loader instance
17
+ ZEITWERK_LOADER = Zeitwerk::Loader.for_gem(warn_on_extra_files: false).tap do |loader|
18
+ loader.ignore("#{__dir__}/generators")
19
+ loader.ignore("#{__dir__}/plutonium/railtie.rb")
20
+ loader.enable_reloading if defined?(Rails.env) && Rails.env.development?
21
+ loader.setup
22
+ end
23
+
16
24
  class << self
17
- # @return [Pathname] the root directory of the gem
25
+ # Get the root directory of the gem
26
+ #
27
+ # @return [Pathname] the root directory path
18
28
  def root
19
- Pathname.new(File.expand_path("..", __dir__))
29
+ @root ||= Pathname.new(File.expand_path("..", __dir__))
20
30
  end
21
31
 
22
- # @return [Pathname] the root directory of the lib folder of the gem
32
+ # Get the root directory of the lib folder of the gem
33
+ #
34
+ # @return [Pathname] the lib root directory path
23
35
  def lib_root
24
- root.join("lib", "plutonium")
36
+ @lib_root ||= root.join("lib", "plutonium")
25
37
  end
26
38
 
27
- # @return [Logger] the Rails logger
39
+ # Get the Rails logger
40
+ #
41
+ # @return [Logger] the Rails logger instance
28
42
  def logger
29
43
  Rails.logger
30
44
  end
31
45
 
32
- # @return [String] the name of the application
46
+ # Get the name of the application
47
+ #
48
+ # @return [String] the application name
33
49
  def application_name
34
50
  @application_name || Rails.application.class.module_parent_name
35
51
  end
36
52
 
37
- # @param [String] application_name the name of the application
38
- # @return [void]
53
+ # Set the name of the application
54
+ #
55
+ # @param [String] name the name of the application
39
56
  attr_writer :application_name
40
57
 
41
- # @return [Boolean] whether the gem is in development mode
42
- def development?
43
- ActiveModel::Type::Boolean.new.cast(ENV["PLUTONIUM_DEV"]).present?
44
- end
45
-
46
- # Eager loads Rails application if not already eager loaded
58
+ # Eager load Rails application if not already eager loaded
59
+ #
47
60
  # @return [void]
48
61
  def eager_load_rails!
49
- return if Rails.env.production? && defined?(@rails_eager_loaded)
62
+ return if @rails_eager_loaded || Rails.application.config.eager_load
50
63
 
51
- Rails.application.eager_load! unless Rails.application.config.eager_load
64
+ Rails.application.eager_load!
52
65
  @rails_eager_loaded = true
53
66
  end
54
67
  end
55
68
  end
56
69
 
57
- Plutonium::ZEITWERK_LOADER = loader
70
+ # Load Railtie if Rails is defined
71
+ require_relative "plutonium/railtie" if defined?(Rails::Railtie)
data/sig/.keep ADDED
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plutonium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
@@ -1128,6 +1128,8 @@ files:
1128
1128
  - lib/plutonium/component_registry.rb
1129
1129
  - lib/plutonium/concerns/resource_validatable.rb
1130
1130
  - lib/plutonium/config.rb
1131
+ - lib/plutonium/config/overlayed_hash.rb
1132
+ - lib/plutonium/configuration.rb
1131
1133
  - lib/plutonium/core/.DS_Store
1132
1134
  - lib/plutonium/core/action.rb
1133
1135
  - lib/plutonium/core/actions/basic_action.rb
@@ -1236,7 +1238,7 @@ files:
1236
1238
  - public/plutonium-assets/plutonium-logo-white.png
1237
1239
  - public/plutonium-assets/plutonium-logo.png
1238
1240
  - public/plutonium-assets/plutonium.ico
1239
- - sig/plutonium.rbs
1241
+ - sig/.keep
1240
1242
  - src/.npmignore
1241
1243
  - src/css/plutonium.css
1242
1244
  - src/js/controllers/color_mode_controller.js
data/sig/plutonium.rbs DELETED
@@ -1,12 +0,0 @@
1
- # plutonium.rbs
2
- module Plutonium
3
- class Error < StandardError; end
4
-
5
- def self.root: () -> Pathname
6
- def self.lib_root: () -> Pathname
7
- def self.logger: () -> Logger
8
- def self.application_name: () -> String
9
- def self.application_name=: (String) -> void
10
- def self.development?: () -> bool
11
- def self.eager_load_rails!: () -> void
12
- end