Class: Panda::CMS::AssetLoader

Inherits:
Object
  • Object
show all
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

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 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)



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



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

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_urlObject

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

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/panda/cms/asset_loader.rb', line 37

def use_github_assets?
  # Panda CMS uses importmaps for JavaScript (no compilation needed)
  # Only use GitHub assets in production or when explicitly enabled
  false # Always use importmaps like panda-core
end