<commit_before>package io.youi.template

import com.outr.reactify.Var
import io.youi.activate.ActivationSupport
import io.youi.app.ClientApplication
import io.youi.app.screen.ContentScreen
import io.youi.{History, dom}
import org.scalajs.dom._

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.scalajs.js.annotation.JSExportTopLevel

object ClientTemplateApplication extends TemplateApplication with ClientApplication {
  private lazy val pages = dom.byId[html.Input]("template_pages").value.split(';').toSet

  @JSExportTopLevel("application")
  def main(): Unit = {
    val paths = pages.map { page =>
      s"/${page.substring(0, page.indexOf('.'))}"
    }
    val screens = paths.map { p =>
      new TemplateScreen(p)
    }

    println("Template initialized!")
  }

  private def fixAnchors(pages: Set[String]): Unit = {
    dom.byTag[html.Anchor]("a").foreach { anchor =>
      val host = window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1)
      val hrefOption = anchor.href match {
        case h if h.startsWith(host) && !h.endsWith("#") => Some(h.substring(host.length))
        case h => None
      }
      hrefOption match {
        case Some(href) => {
          if (pages.contains(href)) {
            val path = s"/${href.substring(0, href.length - 5)}"
            anchor.href = path
            anchor.addEventListener("click", (evt: Event) => {
              evt.preventDefault()
              evt.stopPropagation()

              History.pushPath(path)
            })
          }
        }
        case None => // Ignore
      }
    }
  }

  def screenFixes(): Unit = fixAnchors(pages)
}

class TemplateScreen(val path: String) extends ContentScreen with ActivationSupport {
  override protected def testing = true

  override protected def load(): Future[Unit] = super.load().map { _ =>
    ClientTemplateApplication.screenFixes()
  }

  override protected def activate(): Future[Unit] = super.activate().map { _ =>
    println(s"Activating: $path")
    activation.activate()
  }
}<commit_msg>Added proper deactivation integration for ActivationSupport into TemplateScreen.<commit_after>package io.youi.template

import com.outr.reactify.Var
import io.youi.activate.ActivationSupport
import io.youi.app.ClientApplication
import io.youi.app.screen.ContentScreen
import io.youi.{History, dom}
import org.scalajs.dom._

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.scalajs.js.annotation.JSExportTopLevel

object ClientTemplateApplication extends TemplateApplication with ClientApplication {
  private lazy val pages = dom.byId[html.Input]("template_pages").value.split(';').toSet

  @JSExportTopLevel("application")
  def main(): Unit = {
    val paths = pages.map { page =>
      s"/${page.substring(0, page.indexOf('.'))}"
    }
    val screens = paths.map { p =>
      new TemplateScreen(p)
    }

    println("Template initialized!")
  }

  private def fixAnchors(pages: Set[String]): Unit = {
    dom.byTag[html.Anchor]("a").foreach { anchor =>
      val host = window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1)
      val hrefOption = anchor.href match {
        case h if h.startsWith(host) && !h.endsWith("#") => Some(h.substring(host.length))
        case h => None
      }
      hrefOption match {
        case Some(href) => {
          if (pages.contains(href)) {
            val path = s"/${href.substring(0, href.length - 5)}"
            anchor.href = path
            anchor.addEventListener("click", (evt: Event) => {
              evt.preventDefault()
              evt.stopPropagation()

              History.pushPath(path)
            })
          }
        }
        case None => // Ignore
      }
    }
  }

  def screenFixes(): Unit = fixAnchors(pages)
}

class TemplateScreen(val path: String) extends ContentScreen with ActivationSupport {
  override protected def testing = true

  override protected def load(): Future[Unit] = super.load().map { _ =>
    ClientTemplateApplication.screenFixes()
  }

  override protected def activate(): Future[Unit] = super.activate().map { _ =>
    println(s"Activating: $path")
    activation.activate()
  }

  override protected def deactivate(): Future[Unit] = Future.successful(activation.deactivate()).map(_ => super.deactivate())
}
{'fraction_non_alphanumeric': 0.12951119232526268, 'fraction_numerical': 0.0022841480127912287, 'mean_word_length': 3.0583873957367933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '378252', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1262, 'n_words': 274}