All Downloads are FREE. Search and download functionalities are using the official Maven repository.

os.browse.Page.scala Maven / Gradle / Ivy

The newest version!
// Copyright 2015 ~ Optersoft SL 

package os.browse

import scalatags.Text
import scala.collection.mutable.ArrayBuffer

object Page {

  class AdSense(val client: String, val slot: String)
  class Analytics(val trackingID: String, val domain: String)

  def apply()(handler: Page => Unit) = {
    val page = new Page()
    handler(page)
    page.write().toString()
  }

}

class Page {

  val writer = new StringBuilder

  var app: String = null
  var title = ""

  //  var adsense: Option[Page.AdSense] = None
  //  var analitycs: Option[Page.Analytics] = None

  private var scripts: ArrayBuffer[Script] = null
  private var styles = new ArrayBuffer[Style]

  def +=(script: Script) {
    if (scripts == null)
      scripts = new ArrayBuffer[Script](10)
    scripts += script

  }

  def +=(style: Style) {
    styles += style

  }

  def <(tag: Text.TypedTag[String]) {

    tag.writeTo(writer)

  }

  def write(): StringBuilder = {

    val sb = new StringBuilder
    sb.append("\n\n\n")
    sb.append(title)
    sb append """



"""

    for (style <- styles) {
      sb append """"
    }

    sb append "\n"

    // body

    sb.append(writer)

    if (scripts != null)
      scripts foreach { script =>
        sb append "\n"
      }

    sb append ""

    sb
  }

  def getUri(resource: Resource) = {
    val uri = Resource.uri(resource)
    if (uri.startsWith("//")) uri else "/R/" + uri
  }

  //    adsense.map { adsense =>
  //
  //      w < """
  //  "
  //    }

  // TODO adsense
  //if (adSense != null)
  //AdSense.writeScript(w)

  //    adsense.map { adsense =>
  //      w write "\n"
  //      w write "\n"
  //
  //    }
  //
  //    analitycs.map { analytics =>
  //      w write """

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy