36 case object Tag4 extends Tag("Tag 4") |
36 case object Tag4 extends Tag("Tag 4") |
37 case object Tag5 extends Tag("Tag 5") |
37 case object Tag5 extends Tag("Tag 5") |
38 case object Tag6 extends Tag("Tag 6") |
38 case object Tag6 extends Tag("Tag 6") |
39 } |
39 } |
40 |
40 |
41 sealed abstract class Article(val title: String, |
|
42 val category: Option[iCategory], |
|
43 val tags: Seq[iTag] = Seq(), |
|
44 val tex: Option[SeqFrag[Frag]] = None |
|
45 ) extends EnumEntry with ScalatexOrFsArticle with Hyphencase { |
|
46 |
|
47 override protected def content: Either[Path, SeqFrag[Frag]] = tex match { |
|
48 case Some(v) => Right(v) |
|
49 case _ => |
|
50 Left(Paths.get(s"example/content/${entryName}.html")) |
|
51 } |
|
52 |
|
53 override def assets: Path = Paths.get(s"example/content/${entryName}") |
|
54 override def pathSegment: String = entryName |
|
55 } |
|
56 |
|
57 object Article extends Enum[Article] { |
|
58 import Category._ |
|
59 import Tag._ |
|
60 val values = findValues |
|
61 case object A1 extends Article("Article 1", Some(Cat1), |
|
62 Seq(Tag1, Tag2, Tag3)) |
|
63 case object A2 extends Article("Article 2", Some(Cat1)) |
|
64 case object A3 extends Article("Article 3", Some(Cat1), |
|
65 Seq(Tag4, Tag5)) |
|
66 case object A4 extends Article("Article 4", Some(Cat2), Seq(Tag4)) |
|
67 case object A5 extends Article("Article 5", Some(Cat2), Seq(Tag5)) |
|
68 import scalatex._ |
|
69 case object A6 extends Article("Article 6", Some(Cat1), |
|
70 Seq(Tag1), Some(twf("example/content/a6.scalatex"))) |
|
71 } |
|
72 |
|
73 object Content extends iContent { |
41 object Content extends iContent { |
|
42 InitializeContent() |
74 |
43 |
75 def appTitle: String = "Content management system example" |
44 def appTitle: String = "Content management system example" |
76 |
45 |
77 def appTitleShort: String = "CMS" |
46 def appTitleShort: String = "CMS" |
78 |
47 |
83 |
52 |
84 def styleSheet = |
53 def styleSheet = |
85 ("site.css", Paths.get("example/content/public/css/site.css")) |
54 ("site.css", Paths.get("example/content/public/css/site.css")) |
86 |
55 |
87 def articlesByTag(t: iTag): Seq[iArticle] = |
56 def articlesByTag(t: iTag): Seq[iArticle] = |
88 Article.values.filter(_.tags contains(t)) |
57 Articles.values.filter(_.tags contains(t)) |
89 |
58 |
90 def articlesByCategory(c: iCategory): Seq[iArticle] = |
59 def articlesByCategory(c: iCategory): Seq[iArticle] = |
91 Article.values.filter(_.category contains(c)) |
60 Articles.values.filter(_.category contains(c)) |
92 |
61 |
93 def tags: Seq[iTag] = Tag.values |
62 def tags: Seq[iTag] = Tag.values |
94 |
63 |
95 def categories: Seq[iCategory] = Category.values |
64 def categories: Seq[iCategory] = Category.values |
96 |
65 |
97 def articleByPath(path: String): Option[iArticle] = |
66 def articleByPath(path: String): Option[iArticle] = |
98 Article.withNameOption(path) |
67 Articles.values.find(_.pathSegment == path) |
99 |
68 |
100 def categoryByPath(path: String): Option[iCategory] = |
69 def categoryByPath(path: String): Option[iCategory] = |
101 Category.withNameOption(path) |
70 Category.withNameOption(path) |
102 |
71 |
103 def tagByPath(path: String): Option[iTag] = Tag.withNameOption(path) |
72 def tagByPath(path: String): Option[iTag] = Tag.withNameOption(path) |