Class: Lutaml::Xsd::Spa::Strategies::VueCdnStrategy

Inherits:
OutputStrategy show all
Defined in:
lib/lutaml/xsd/spa/strategies/vue_cdn_strategy.rb

Overview

VueCdnStrategy - Generates HTML that loads Vue app from CDN

This strategy generates an HTML file that loads Vue.js and the pre-built application assets from CDN/external sources. The resulting HTML is smaller but requires network access and must be served via HTTP (not file://).

Note: When opening HTML via file:// protocol, browsers block loading external JS files due to CORS. Use VueInlinedStrategy for local files.

Examples:

strategy = VueCdnStrategy.new(
  'output/docs.html',
  config_loader,
  verbose: true
)
files = strategy.generate(data, renderer)

Constant Summary collapse

VUE_CDN_URL =

Vue 3 CDN URLs

"https://unpkg.com/vue@3.4.21/dist/vue.global.prod.js"
VUE_ROUTER_CDN_URL =
"https://unpkg.com/vue-router@4.3.0/dist/vue-router.global.prod.js"
PINIA_CDN_URL =
"https://unpkg.com/pinia@2.1.7/dist/pinia.iife.prod.js"
DEFAULT_CDN_BASE =

Default CDN base URL for app assets

"https://cdn.example.com/lutaml-xsd"

Instance Attribute Summary collapse

Attributes inherited from OutputStrategy

#verbose

Instance Method Summary collapse

Methods inherited from OutputStrategy

#write

Constructor Details

#initialize(output_path, config_loader, verbose: false, **options) ⇒ VueCdnStrategy

Initialize Vue CDN strategy

Parameters:

  • output_path (String)

    Output file path

  • config_loader (ConfigurationLoader)

    Configuration loader

  • verbose (Boolean) (defaults to: false)

    Enable verbose output

  • options (Hash)

    Additional options

Options Hash (**options):

  • :cdn_base (String)

    Base URL for external assets



43
44
45
46
47
48
# File 'lib/lutaml/xsd/spa/strategies/vue_cdn_strategy.rb', line 43

def initialize(output_path, config_loader, verbose: false, **options)
  super(verbose: verbose)
  @output_path = output_path
  @config_loader = config_loader
  @options = options
end

Instance Attribute Details

#config_loaderObject (readonly)

Returns the value of attribute config_loader.



34
35
36
# File 'lib/lutaml/xsd/spa/strategies/vue_cdn_strategy.rb', line 34

def config_loader
  @config_loader
end

#optionsObject (readonly)

Returns the value of attribute options.



34
35
36
# File 'lib/lutaml/xsd/spa/strategies/vue_cdn_strategy.rb', line 34

def options
  @options
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



34
35
36
# File 'lib/lutaml/xsd/spa/strategies/vue_cdn_strategy.rb', line 34

def output_path
  @output_path
end

Instance Method Details

#generate(data, _renderer) ⇒ Array<String>

Generate HTML file with CDN-loaded Vue app

Parameters:

  • data (Hash)

    Serialized schema data

  • renderer (TemplateRenderer)

    Template renderer (unused for Vue mode)

Returns:

  • (Array<String>)

    List containing single file path



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/lutaml/xsd/spa/strategies/vue_cdn_strategy.rb', line 55

def generate(data, _renderer)
  log "Generating Vue CDN SPA (HTML loads Vue from CDN)..."

  # Build complete HTML document
  html = build_html_document(data)

  # Write to file
  prepare_output
  files = [write_file(output_path, html)]

  # Copy assets to output directory
  asset_files = copy_assets

  log "✓ Vue CDN SPA generated: #{output_path}"
  log "  Note: Assets copied to #{output_dir}/app.iife.js and #{output_dir}/style.css"
  log "  Serve via HTTP to load assets correctly (not file://)"

  files + asset_files
end