Module: Panda::Core::AssetHelper
- Defined in:
- app/helpers/panda/core/asset_helper.rb
Instance Method Summary collapse
-
#panda_core_assets ⇒ Object
Include Panda Core JavaScript and CSS assets.
-
#panda_core_javascript ⇒ Object
Include only Core JavaScript.
-
#panda_core_stylesheet ⇒ Object
Include only Core CSS.
Instance Method Details
#panda_core_assets ⇒ Object
Include Panda Core JavaScript and CSS assets
7 8 9 |
# File 'app/helpers/panda/core/asset_helper.rb', line 7 def panda_core_assets Panda::Core::AssetLoader..html_safe end |
#panda_core_javascript ⇒ Object
Include only Core JavaScript
This is the single entry point for all Panda JavaScript loading. It automatically includes JavaScript from Core and all registered modules via ModuleRegistry.
Note: Always uses importmap (Rails 8 approach), regardless of asset source
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/panda/core/asset_helper.rb', line 18 def panda_core_javascript # Use ModuleRegistry to combine all Panda module importmaps imports = Panda::Core::ModuleRegistry.combined_importmap importmap_json = JSON.generate({"imports" => imports}) # Generate entry point script tags for all registered modules (including Core) entry_points = [] # Add entry points for each registered module Panda::Core::ModuleRegistry.modules.each do |gem_name, info| # Extract module namespace from gem name (e.g., "panda-cms" -> "cms") module_slug = gem_name.sub(/^panda-/, "") # Check if the module is actually loaded module_name = info[:engine].sub(/::Engine$/, "") next unless Object.const_defined?(module_name) entry_points << %(<script type="module">import "panda/#{module_slug}/application"</script>) entry_points << %(<script type="module">import "panda/#{module_slug}/controllers/index"</script>) end <<~HTML.html_safe <script type="importmap">#{importmap_json}</script> #{entry_points.join("\n")} HTML end |
#panda_core_stylesheet ⇒ Object
Include only Core CSS
47 48 49 50 51 52 |
# File 'app/helpers/panda/core/asset_helper.rb', line 47 def panda_core_stylesheet css_url = Panda::Core::AssetLoader.css_url return "" unless css_url stylesheet_link_tag(css_url) end |