example/src/sqwl/cms/Articles.scala
author Tomas Zeman <tomas@functionals.cz>
Tue, 24 Nov 2020 11:17:26 +0100
changeset 31 5c4364d6e726
parent 27 8529ce302f7c
child 33 fa0f19a74283
permissions -rw-r--r--
SQWL#2003 Studie -> Projekt

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,
    rank: Int = 0
  ) 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(),
    rank: Int = 0)(body: Frag*)(implicit articleId: Id): SeqFrag[Frag] = {

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