example/src/sqwl/cms/Articles.scala
changeset 18 8cfd67425811
child 21 1fa630ed9b8a
equal deleted inserted replaced
17:0ebcd5464503 18:8cfd67425811
       
     1 package sqwl.cms
       
     2 
       
     3 import java.nio.file.{Path, Paths}
       
     4 import scala.collection.mutable
       
     5 import scalatags.Text.all._
       
     6 
       
     7 object Articles {
       
     8   case class Id(val v: String)
       
     9   case class Article(
       
    10     val id: Id,
       
    11     val title: String,
       
    12     val category: Option[iCategory],
       
    13     val tags: Seq[iTag] = Seq(),
       
    14     val htmlContent: String
       
    15   ) extends iArticle {
       
    16     override def assets: Path = Paths.get(s"example/content/${id.v}")
       
    17     override def pathSegment: String = id.v
       
    18   }
       
    19   private val all = mutable.ArrayBuffer[iArticle]()
       
    20 
       
    21   def values: Seq[iArticle] = all.toSeq
       
    22 
       
    23   def article(title: String, cat: iCategory, tags: Seq[iTag] = Seq())(
       
    24     body: Frag*)(implicit articleId: Id): SeqFrag[Frag] = {
       
    25 
       
    26     all += Article(articleId, title, Option(cat), tags, body.render)
       
    27     body
       
    28   }
       
    29 }