| author | Tomas Zeman <tzeman@volny.cz> |
| Thu, 06 Dec 2018 13:52:06 +0100 | |
| changeset 9 | 7d5ed4c927ce |
| parent 7 | 50a354e5bda4 |
| child 10 | 4b5313097a4d |
| permissions | -rw-r--r-- |
|
4
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
1 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
2 |
package sqwl.cms |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
3 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
4 |
import java.nio.file.{FileSystems, Path, Paths}
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
5 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
6 |
import akka.stream.scaladsl.FileIO |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
7 |
import enumeratum.EnumEntry.Hyphencase |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
8 |
import enumeratum._ |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
9 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
10 |
import scala.io.Source |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
11 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
12 |
sealed abstract class Category(val name: String) extends EnumEntry with iCategory with Hyphencase {
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
13 |
override def pathSegment: String = entryName |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
14 |
} |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
15 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
16 |
object Category extends Enum[Category] {
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
17 |
val values = findValues |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
18 |
case object Cat1 extends Category("Category 1")
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
19 |
case object Cat2 extends Category("Category 2")
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
20 |
} |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
21 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
22 |
sealed abstract class Article(val title: String, |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
23 |
val category: Option[iCategory], |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
24 |
val tags: Seq[iTag], |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
25 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
26 |
) extends EnumEntry with iArticle with Hyphencase {
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
27 |
override def htmlContent: String = {
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
28 |
val src = Source.fromFile(s"example/content/${entryName}.html", "UTF-8")
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
29 |
try {
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
30 |
src.getLines.mkString |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
31 |
} catch {
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
32 |
case _: Throwable => "" |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
33 |
} finally {
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
34 |
src.close() |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
35 |
} |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
36 |
} |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
37 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
38 |
override def assets: Path = Paths.get(s"example/content/${entryName}")
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
39 |
override def pathSegment: String = entryName |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
40 |
} |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
41 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
42 |
object Article extends Enum[Article] {
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
43 |
import Category._ |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
44 |
val values = findValues |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
45 |
case object A1 extends Article("Article 1", Some(Cat1), Seq())
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
46 |
} |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
47 |
|
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
48 |
object Content extends iContent {
|
| 9 | 49 |
def appTitle: String = "Content management system example" |
50 |
def appTitleShort: String = "CMS" |
|
| 7 | 51 |
def icon = ("icon.png", Paths.get("example/content/public/images/icon.png"))
|
52 |
def publicAssets: Path = Paths.get("example/content/public")
|
|
53 |
def styleSheet = ("site.css", Paths.get("example/content/public/css/site.css"))
|
|
|
4
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
54 |
def articlesByTag(t: iTag): Seq[iArticle] = Seq() |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
55 |
def articlesByCategory(c: iCategory): Seq[iArticle] = Seq() |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
56 |
def tags: Seq[iTag] = Seq() |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
57 |
def categories: Seq[iCategory] = Category.values |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
58 |
def articleByPath(path: String): Option[iArticle] = Article.withNameOption(path) |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
59 |
def categoryByPath(path: String): Option[iCategory] = Category.withNameOption(path) |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
60 |
def tagByPath(path: String): Option[iTag] = None |
|
1a1347e8c5be
Build modules: base, content, app; example content, minimal layout
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
61 |
} |