Class: Solidstats::AssetManifest
- Inherits:
-
Object
- Object
- Solidstats::AssetManifest
- Defined in:
- lib/solidstats/asset_manifest.rb
Constant Summary collapse
- PRECOMPILE_ASSETS =
Define all assets that should be precompiled
[ # Main application assets "solidstats/application.css", "solidstats/application.js", # Component-specific CSS files (using actual filenames) "solidstats/components/summary_card.css", "solidstats/components/dashboard_layout.css", "solidstats/components/tab_navigation.css", "solidstats/components/quick_navigation.css", "solidstats/components/action_button.css", "solidstats/components/dashboard_header.css", "solidstats/components/navigation.css", "solidstats/components/security.css", "solidstats/components/status_badge.css", "solidstats/components/dashboard.css" ].freeze
- DEVELOPMENT_ASSETS =
Assets that should be included in development mode
[ # Preview and development-only assets "solidstats/component_preview.css", "solidstats/development_toolbar.css" ].freeze
- IMAGE_ASSETS =
Image assets to precompile
[ # Add image assets here when they exist # "solidstats/icons/*.png", # "solidstats/logos/*.svg" ].freeze
Class Method Summary collapse
-
.add_asset_paths(app) ⇒ Object
Add engine asset paths to application.
-
.assets_for_environment(environment = Rails.env) ⇒ Array<String>
Get all assets for precompilation based on environment.
-
.configure_fingerprinting(app, environment = Rails.env) ⇒ Object
Apply fingerprinting configuration to application.
-
.configure_precompilation(app) ⇒ Object
Configure asset precompilation for a Rails application.
-
.fingerprint_config(environment = Rails.env) ⇒ Hash
Get asset fingerprinting configuration.
-
.missing_assets ⇒ Array<String>
Check if all required assets exist.
-
.validate_assets! ⇒ Object
Validate that all assets are available.
Class Method Details
.add_asset_paths(app) ⇒ Object
Add engine asset paths to application
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/solidstats/asset_manifest.rb', line 76 def add_asset_paths(app) return unless app.config.respond_to?(:assets) engine_paths = [ Solidstats::Engine.root.join("app", "assets", "stylesheets"), Solidstats::Engine.root.join("app", "assets", "javascripts"), Solidstats::Engine.root.join("app", "assets", "images") ] engine_paths.each do |path| path_str = path.to_s unless app.config.assets.paths.include?(path_str) app.config.assets.paths << path_str end end end |
.assets_for_environment(environment = Rails.env) ⇒ Array<String>
Get all assets for precompilation based on environment
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/solidstats/asset_manifest.rb', line 46 def assets_for_environment(environment = Rails.env) assets = PRECOMPILE_ASSETS.dup if environment == "development" assets.concat(DEVELOPMENT_ASSETS) end assets.concat(IMAGE_ASSETS) assets.uniq end |
.configure_fingerprinting(app, environment = Rails.env) ⇒ Object
Apply fingerprinting configuration to application
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/solidstats/asset_manifest.rb', line 142 def configure_fingerprinting(app, environment = Rails.env) return unless app.config.respond_to?(:assets) config = fingerprint_config(environment) config.each do |key, value| if app.config.assets.respond_to?("#{key}=") app.config.assets.public_send("#{key}=", value) end end Rails.logger.info "[Solidstats] Applied #{environment} asset fingerprinting configuration" end |
.configure_precompilation(app) ⇒ Object
Configure asset precompilation for a Rails application
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/solidstats/asset_manifest.rb', line 59 def configure_precompilation(app) return unless app.config.respond_to?(:assets) assets_to_add = assets_for_environment - app.config.assets.precompile assets_to_add.each do |asset| app.config.assets.precompile << asset end # Add asset paths if not already present add_asset_paths(app) Rails.logger.info "[Solidstats] Added #{assets_to_add.size} assets to precompilation list" end |
.fingerprint_config(environment = Rails.env) ⇒ Hash
Get asset fingerprinting configuration
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/solidstats/asset_manifest.rb', line 96 def fingerprint_config(environment = Rails.env) case environment when "production" { digest: true, compile: false, compress: true, gzip: true } when "staging" { digest: true, compile: false, compress: true, gzip: false } when "development" { digest: false, compile: true, compress: false, gzip: false, debug: true } when "test" { digest: false, compile: true, compress: false, gzip: false, debug: false } else # Default safe configuration { digest: true, compile: false, compress: true, gzip: false } end end |
.missing_assets ⇒ Array<String>
Check if all required assets exist
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/solidstats/asset_manifest.rb', line 158 def missing_assets missing = [] PRECOMPILE_ASSETS.each do |asset| asset_path = resolve_asset_path(asset) unless File.exist?(asset_path) missing << asset end end missing end |
.validate_assets! ⇒ Object
Validate that all assets are available
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/solidstats/asset_manifest.rb', line 173 def validate_assets! missing = missing_assets unless missing.empty? raise Solidstats::Error, "Missing required assets: #{missing.join(', ')}" end true end |