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 in one HTML file (data inlined as a JSON blob). 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::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



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

def render(projector)
  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