Class: Ea::Spa::Output::SingleFileStrategy

Inherits:
Strategy
  • Object
show all
Defined in:
lib/ea/spa/output/single_file_strategy.rb

Overview

Embeds skeleton + search + every shard AND the pre-built SPA bundle (JS + CSS) in one HTML file. Suitable for small models only; not appropriate when shard count or total payload is large.

Constant Summary

Constants inherited from Strategy

Ea::Spa::Output::Strategy::FRONTEND_APP_JS, Ea::Spa::Output::Strategy::FRONTEND_DIST_DIR, Ea::Spa::Output::Strategy::FRONTEND_STYLE_CSS, Ea::Spa::Output::Strategy::SIZE_THRESHOLD_BYTES

Instance Attribute Summary

Attributes inherited from Strategy

#output_path

Instance Method Summary collapse

Methods inherited from Strategy

#initialize

Constructor Details

This class inherits a constructor from Ea::Spa::Output::Strategy

Instance Method Details

#render(projector) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ea/spa/output/single_file_strategy.rb', line 14

def render(projector)
  assert_frontend_bundle!
  FileUtils.mkdir_p(File.dirname(output_path))

  skeleton = projector.skeleton
  payload = {
    metadata: skeleton.,
    packageTree: skeleton.package_tree,
    skeletonEntries: skeleton.entries,
    searchIndex: projector.search_index,
    shards: projector.each_shard.to_a
  }
  payload[:viewExtras] = skeleton.view_extras unless skeleton.view_extras.nil? || skeleton.view_extras.empty?

  File.write(output_path, build_html(payload))
  output_path
end