Class: Panda::CMS::AssetLoader
- Inherits:
-
Object
- Object
- Panda::CMS::AssetLoader
- Defined in:
- lib/panda/cms/asset_loader.rb
Overview
AssetLoader handles loading compiled assets from GitHub releases Falls back to local development assets when GitHub assets unavailable
Defined Under Namespace
Classes: Response
Class Method Summary collapse
-
.asset_tags(options = {}) ⇒ Object
Generate HTML tags for loading Panda CMS assets.
-
.css_url ⇒ Object
Get the CSS asset URL (if exists).
-
.ensure_assets_available! ⇒ Object
Download assets from GitHub to local cache.
-
.javascript_url ⇒ Object
Get the JavaScript asset URL.
-
.use_github_assets? ⇒ Boolean
Check if GitHub-hosted assets should be used.
Class Method Details
.asset_tags(options = {}) ⇒ Object
Generate HTML tags for loading Panda CMS assets
10 11 12 13 14 15 16 |
# File 'lib/panda/cms/asset_loader.rb', line 10 def ( = {}) if use_github_assets? () else () end end |
.css_url ⇒ Object
Get the CSS asset URL (if exists)
28 29 30 31 32 33 34 |
# File 'lib/panda/cms/asset_loader.rb', line 28 def css_url if use_github_assets? github_css_url else development_css_url end end |
.ensure_assets_available! ⇒ Object
Download assets from GitHub to local cache
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/panda/cms/asset_loader.rb', line 57 def ensure_assets_available! return if development_assets_available? && !use_github_assets? cache_dir = local_cache_directory version = `git rev-parse --short HEAD`.strip # Check if we already have cached assets for this version if cached_assets_exist?(version) Rails.logger.info "[Panda CMS] Using cached assets #{version}" return end Rails.logger.info "[Panda CMS] Downloading assets #{version} from GitHub..." download_github_assets(version, cache_dir) end |
.javascript_url ⇒ Object
Get the JavaScript asset URL
19 20 21 22 23 24 25 |
# File 'lib/panda/cms/asset_loader.rb', line 19 def javascript_url if use_github_assets? github_javascript_url else development_javascript_url end end |
.use_github_assets? ⇒ Boolean
Check if GitHub-hosted assets should be used
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/panda/cms/asset_loader.rb', line 37 def use_github_assets? # In test, never use GitHub assets return false if Rails.env.test? || in_test_environment? # In production, prefer local assets over GitHub # CMS uses importmap for JS and gets CSS from panda-core # Only use GitHub as fallback if explicitly enabled if Rails.env.production? # Check if compiled assets exist locally (though CMS doesn't bundle) return false if compiled_assets_available? # Only use GitHub as fallback if explicitly enabled return ENV["PANDA_CMS_USE_GITHUB_ASSETS"] == "true" end # In development, use GitHub assets only when explicitly enabled or development assets unavailable ENV["PANDA_CMS_USE_GITHUB_ASSETS"] == "true" || !development_assets_available? end |