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

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

Constant Summary collapse

CONTENT_CSS_MODULES =

Classic content styles inlined for the no-JS SSR body: reset + typography + block/inline component styles from the classic asset pipeline. Page chrome (layout, print, transitions, dark, cover, header, footer, toc, search, progress, shortcuts, glossary panel, flavor modules) is owned by the SPA and excluded.

%w[
  base/_reset
  base/_typography
  components/section
  components/note
  components/example
  components/sourcecode
  components/formula
  components/admonition
  components/table
  components/footnote
  components/figure
  components/term
  components/bibliography
  components/inline
  components/index
].freeze

Class Attribute Summary collapse

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

Class Attribute Details

.missing_bundle_warnedObject

Returns the value of attribute missing_bundle_warned.



36
37
38
# File 'lib/metanorma/mirror/output/formats/inline_format.rb', line 36

def missing_bundle_warned
  @missing_bundle_warned
end

Instance Method Details

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/metanorma/mirror/output/formats/inline_format.rb', line 39

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

  warn_missing_bundle unless iife_bundle_exists?

  data_script = "window.METANORMA_DATA = #{safe_json(guide.to_h)};"
  ssr_body = render_ssr_body(guide)
  head_parts = [build_style(classic_content_css)]
  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