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.



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

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



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

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



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

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

#uri_for_extension(uri, extension) ⇒ Object



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

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