Class: Relaton::Cli::XmlToHtmlRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton/cli/xml_to_html_renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(liquid_dir: nil, stylesheet: nil) ⇒ XmlToHtmlRenderer

Returns a new instance of XmlToHtmlRenderer.



6
7
8
9
10
# File 'lib/relaton/cli/xml_to_html_renderer.rb', line 6

def initialize(liquid_dir: nil, stylesheet: nil)
  @liquid_dir = liquid_dir
  @stylesheet = read_file(stylesheet)
  init_liquid_template_and_filesystem
end

Class Method Details

.render(file, options) ⇒ String

Render HTML

This interface allow us to convert a Relaton XML to HTML using the specified liquid template and stylesheets. It also do some minor clean during this conversion.

Parameters:

  • file (String)

    Relaton XML

  • options (Hash)

Returns:

  • (String)

    HTML



33
34
35
# File 'lib/relaton/cli/xml_to_html_renderer.rb', line 33

def self.render(file, options)
  new(**options).render(file)
end

Instance Method Details

#render(index_xml) ⇒ String

Returns HTML.

Parameters:

  • index_xml (String)

    Relaton XML

Returns:

  • (String)

    HTML



14
15
16
17
18
# File 'lib/relaton/cli/xml_to_html_renderer.rb', line 14

def render(index_xml)
  Liquid::Template
    .parse(template)
    .render(build_liquid_document(index_xml))
end

#uri_for_extension(uri, extension) ⇒ Object



20
21
22
# File 'lib/relaton/cli/xml_to_html_renderer.rb', line 20

def uri_for_extension(uri, extension)
  uri&.sub(/\.[^.]+$/, ".#{extension}")
end