example/src/sqwl/cms/Articles.scala
author Tomas Zeman <tomas@functionals.cz>
Tue, 29 Dec 2020 16:46:47 +0100
changeset 33 fa0f19a74283
parent 27 8529ce302f7c
permissions -rw-r--r--
CMS API update

/*
 * Copyright 2018-2020 Tomas Zeman <tomas@functionals.cz>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package sqwl.cms

import scalatags.Text.all._

import scala.collection.mutable

object Articles {
  case class Id(v: String)
  case class Article(
    id: Id,
    title: String,
    category: Option[iCategory],
    tags: Seq[iTag] = Seq(),
    htmlContent: SeqFrag[Frag],
    rank: Int = 0
  ) extends iArticle {
    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, rank)
    body
  }
}