Class: Metanorma::Mirror::Output::Formats::InlineFormat

Inherits:
BaseFormat
  • Object
show all
Defined in:
lib/metanorma/mirror/output/formats/inline_format.rb

Instance Attribute Summary

Attributes inherited from BaseFormat

#dist_dir

Instance Method Summary collapse

Methods inherited from BaseFormat

default_dist_dir, #initialize

Constructor Details

This class inherits a constructor from Metanorma::Mirror::Output::Formats::BaseFormat

Instance Method Details

#write(output_path, guide, title: "Metanorma") ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/metanorma/mirror/output/formats/inline_format.rb', line 11

def write(output_path, guide, title: "Metanorma")
  FileUtils.mkdir_p(File.dirname(output_path))

  data_script = "window.METANORMA_DATA = #{safe_json(guide)};"
  ssr_body = HtmlRenderer.new(guide).render
  head_parts = []
  css_inline = read_css_inline
  if css_inline && !css_inline.empty?
    head_parts << build_style(css_inline)
  end
  head_parts << build_script_src("app.iife.js") if iife_bundle_exists?
  head_extra = head_parts.join("\n")

  html = html_boilerplate(
    title: title,
    body_content: ssr_body,
    head_extra: head_extra,
    script_data: data_script,
    app_mount_id: iife_bundle_exists? ? "metanorma-app" : nil,
  )

  File.write(output_path, html)

  if iife_bundle_exists?
    copy_if_exists(iife_bundle_path,
                   File.join(File.dirname(output_path),
                             "app.iife.js"))
  end

  output_path
end