summaryrefslogtreecommitdiffstats
path: root/container-core/src/main/scala/com/yahoo/container/handler/observability/HtmlUtil.scala
blob: 77fd46b0c5b65e93836c0f418fe251a90f7511cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
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
42
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.handler.observability

import xml.{PrettyPrinter, Elem}


/**
 * @author gjoranv
 * @author tonytv
 */
object HtmlUtil {
  def link(target: String, anchor: String): Elem =
    <a href={target}>{anchor}</a>

  def link(targetAndAnchor: String): Elem = link(targetAndAnchor, targetAndAnchor)

  def unorderedList(items: Elem*) =
    <ul>
      {items}
    </ul>

  def li[T](children: T*) =
    <li>{children}</li>

  def h1(name: String) =
    <h1>{name}</h1>

  def html(title: String, body: Elem*) =
    <html>
      <head>
        <title>{title}</title>
      </head>
      <body>
        {body}
      </body>
    </html>

  def prettyPrintXhtml(elem: Elem): String = {
    """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">""" +
      "\n" + new PrettyPrinter(120, 2).format(elem)
  }
}