Class: Panda::Core::AssetLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/panda/core/asset_loader.rb

Overview

AssetLoader handles loading compiled assets from GitHub releases Falls back to local development assets when GitHub assets unavailable

Class Method Summary collapse

Class Method Details

.asset_tags(options = {}) ⇒ Object

Generate HTML tags for loading Panda Core assets



14
15
16
17
18
19
20
# File 'lib/panda/core/asset_loader.rb', line 14

def asset_tags(options = {})
  if use_github_assets?
    github_asset_tags(options)
  else
    development_asset_tags(options)
  end
end

.css_urlObject

Get the CSS asset URL (if exists)



32
33
34
35
36
37
38
# File 'lib/panda/core/asset_loader.rb', line 32

def css_url
  if use_github_assets?
    github_css_url
  else
    development_css_url
  end
end

.javascript_urlObject

Get the JavaScript asset URL



23
24
25
26
27
28
29
# File 'lib/panda/core/asset_loader.rb', line 23

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/panda/core/asset_loader.rb', line 41

def use_github_assets?
  # In test, never use GitHub assets (use local engine assets instead)
  # This allows system tests to load CSS/JS from the engine's public directory
  return false if Rails.env.test? || in_test_environment?

  # In production, prefer local compiled assets over GitHub
  # Only use GitHub assets when explicitly enabled or when local assets aren't available
  if Rails.env.production?
    # Check if compiled assets exist locally
    return false if compiled_assets_available?

    # Only use GitHub as fallback if explicitly enabled
    return ENV["PANDA_CORE_USE_GITHUB_ASSETS"] == "true"
  end

  # In development, use GitHub assets only when explicitly enabled or development assets unavailable
  ENV["PANDA_CORE_USE_GITHUB_ASSETS"] == "true" || !development_assets_available?
end