example/src/sqwl/cms/Articles.scala
author Tomas Zeman <tzeman@volny.cz>
Thu, 13 Dec 2018 17:33:35 +0100
changeset 21 1fa630ed9b8a
parent 18 8cfd67425811
child 27 8529ce302f7c
permissions -rw-r--r--
Content: type annotations

package sqwl.cms

import java.nio.file.{Path, Paths}
import scala.collection.mutable
import scalatags.Text.all._

object Articles {
  case class Id(v: String)
  case class Article(
    id: Id,
    title: String,
    category: Option[iCategory],
    tags: Seq[iTag] = Seq(),
    htmlContent: String
  ) extends iArticle {
    override def assets: Path = Paths.get(s"example/content/${id.v}")
    override def pathSegment: String = id.v
  }
  private val all = mutable.ArrayBuffer[iArticle]()

  def values: Seq[iArticle] = all.toIndexedSeq

  def article(title: String, cat: iCategory, tags: Seq[iTag] = Seq())(
    body: Frag*)(implicit articleId: Id): SeqFrag[Frag] = {

    all += Article(articleId, title, Option(cat), tags, body.render)
    body
  }
}