|
1 /* |
|
2 * Copyright 2018-2020 Tomas Zeman <tomas@functionals.cz> |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
1 package sqwl.cms |
16 package sqwl.cms |
2 |
17 |
3 import java.nio.file.{Path, Paths} |
18 import scalatags.Text.all._ |
|
19 |
4 import scala.collection.mutable |
20 import scala.collection.mutable |
5 import scalatags.Text.all._ |
|
6 |
21 |
7 object Articles { |
22 object Articles { |
8 case class Id(v: String) |
23 case class Id(v: String) |
9 case class Article( |
24 case class Article( |
10 id: Id, |
25 id: Id, |
11 title: String, |
26 title: String, |
12 category: Option[iCategory], |
27 category: Option[iCategory], |
13 tags: Seq[iTag] = Seq(), |
28 tags: Seq[iTag] = Seq(), |
14 htmlContent: String, |
29 htmlContent: SeqFrag[Frag], |
15 rank: Int = 0 |
30 rank: Int = 0 |
16 ) extends iArticle { |
31 ) extends iArticle { |
17 override def assets: Path = Paths.get(s"example/content/${id.v}") |
|
18 override def pathSegment: String = id.v |
32 override def pathSegment: String = id.v |
19 } |
33 } |
20 private val all = mutable.ArrayBuffer[iArticle]() |
34 private val all = mutable.ArrayBuffer[iArticle]() |
21 |
35 |
22 def values: Seq[iArticle] = all.toIndexedSeq |
36 def values: Seq[iArticle] = all.toIndexedSeq |
23 |
37 |
24 def article(title: String, cat: iCategory, tags: Seq[iTag] = Seq(), |
38 def article(title: String, cat: iCategory, tags: Seq[iTag] = Seq(), |
25 rank: Int = 0)(body: Frag*)(implicit articleId: Id): SeqFrag[Frag] = { |
39 rank: Int = 0)(body: Frag*)(implicit articleId: Id): SeqFrag[Frag] = { |
26 |
40 |
27 all += Article(articleId, title, Option(cat), tags, body.render, rank) |
41 all += Article(articleId, title, Option(cat), tags, body, rank) |
28 body |
42 body |
29 } |
43 } |
30 } |
44 } |