example/src/sqwl/cms/Content.scala
changeset 33 fa0f19a74283
parent 27 8529ce302f7c
equal deleted inserted replaced
32:2d14f02ba3bd 33:fa0f19a74283
     1 
     1 
     2 package sqwl.cms
     2 package sqwl.cms
     3 
     3 
     4 import java.nio.file.{Path, Paths}
     4 import java.nio.file.Path
     5 
     5 
     6 import enumeratum.EnumEntry.Hyphencase
     6 import enumeratum.EnumEntry.Hyphencase
     7 import enumeratum._
     7 import enumeratum._
     8 
     8 
     9 import scala.collection.immutable
     9 import scala.collection.immutable
    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 object Content extends iContent {
    41 class Content(val root: Path) extends iContent {
    42   InitializeContent()
    42   InitializeContent()
    43 
    43 
    44   def appTitle: String = "Content management system example"
    44   def appTitle: String = "Content management system example"
    45 
    45 
    46   def appTitleShort: String = "CMS"
    46   def appTitleShort: String = "CMS"
    47 
    47 
    48   def icon: (String, Path) =
    48   def icon: (String, Path) =
    49     ("icon.png", Paths.get("example/content/public/images/icon.png"))
    49     ("icon.png", root.resolve("public/images/icon.png"))
    50 
    50 
    51   def publicAssets: Path = Paths.get("example/content/public")
    51   def publicAssets: Path = root.resolve("public")
    52 
    52 
    53   def styleSheet: (String, Path) =
    53   def styleSheet: (String, Path) =
    54     ("site.css", Paths.get("example/content/public/css/site.css"))
    54     ("site.css", root.resolve("public/css/site.css"))
    55 
    55 
    56   def articlesByTag(t: iTag): Seq[iArticle] =
    56   def articlesByTag(t: iTag): Seq[iArticle] =
    57     Articles.values filter(_.tags contains t) sortBy(_.rank)
    57     Articles.values filter(_.tags contains t) sortBy(_.rank)
    58 
    58 
    59   def articlesByCategory(c: iCategory): Seq[iArticle] =
    59   def articlesByCategory(c: iCategory): Seq[iArticle] =
    68 
    68 
    69   def categoryByPath(path: String): Option[iCategory] =
    69   def categoryByPath(path: String): Option[iCategory] =
    70     Category.withNameOption(path)
    70     Category.withNameOption(path)
    71 
    71 
    72   def tagByPath(path: String): Option[iTag] = Tag.withNameOption(path)
    72   def tagByPath(path: String): Option[iTag] = Tag.withNameOption(path)
       
    73 
       
    74   def articleAssets(a: iArticle): Path = root.resolve(a.pathSegment)
    73 }
    75 }