Content: type annotations
authorTomas Zeman <tzeman@volny.cz>
Thu, 13 Dec 2018 17:33:35 +0100
changeset 21 1fa630ed9b8a
parent 20 677672b9e386
child 22 b5c85ad66f17
Content: type annotations
example/src/sqwl/cms/Articles.scala
example/src/sqwl/cms/Content.scala
--- a/example/src/sqwl/cms/Articles.scala	Thu Dec 13 17:29:58 2018 +0100
+++ b/example/src/sqwl/cms/Articles.scala	Thu Dec 13 17:33:35 2018 +0100
@@ -5,20 +5,20 @@
 import scalatags.Text.all._
 
 object Articles {
-  case class Id(val v: String)
+  case class Id(v: String)
   case class Article(
-    val id: Id,
-    val title: String,
-    val category: Option[iCategory],
-    val tags: Seq[iTag] = Seq(),
-    val htmlContent: String
+    id: Id,
+    title: String,
+    category: Option[iCategory],
+    tags: Seq[iTag] = Seq(),
+    htmlContent: String
   ) extends iArticle {
     override def assets: Path = Paths.get(s"example/content/${id.v}")
     override def pathSegment: String = id.v
   }
   private val all = mutable.ArrayBuffer[iArticle]()
 
-  def values: Seq[iArticle] = all.toSeq
+  def values: Seq[iArticle] = all.toIndexedSeq
 
   def article(title: String, cat: iCategory, tags: Seq[iTag] = Seq())(
     body: Frag*)(implicit articleId: Id): SeqFrag[Frag] = {
--- a/example/src/sqwl/cms/Content.scala	Thu Dec 13 17:29:58 2018 +0100
+++ b/example/src/sqwl/cms/Content.scala	Thu Dec 13 17:33:35 2018 +0100
@@ -5,8 +5,8 @@
 
 import enumeratum.EnumEntry.Hyphencase
 import enumeratum._
-import scala.io.Source
-import scalatags.Text.all._
+
+import scala.collection.immutable
 
 sealed abstract class Category(val name: String) extends EnumEntry with
   iCategory with Hyphencase {
@@ -14,7 +14,7 @@
 }
 
 object Category extends Enum[Category] {
-  val values = findValues
+  val values: immutable.IndexedSeq[Category] = findValues
   case object Cat1 extends Category("Category 1")
   case object Cat2 extends Category("Category 2")
   case object Cat3 extends Category("Category 3")
@@ -29,7 +29,7 @@
 }
 
 object Tag extends Enum[Tag] {
-  val values = findValues
+  val values: immutable.IndexedSeq[Tag] = findValues
   case object Tag1 extends Tag("Tag 1")
   case object Tag2 extends Tag("Tag 2")
   case object Tag3 extends Tag("Tag 3")
@@ -45,19 +45,19 @@
 
   def appTitleShort: String = "CMS"
 
-  def icon =
+  def icon: (String, Path) =
     ("icon.png", Paths.get("example/content/public/images/icon.png"))
 
   def publicAssets: Path = Paths.get("example/content/public")
 
-  def styleSheet =
+  def styleSheet: (String, Path) =
     ("site.css", Paths.get("example/content/public/css/site.css"))
 
   def articlesByTag(t: iTag): Seq[iArticle] =
-    Articles.values.filter(_.tags contains(t))
+    Articles.values.filter(_.tags contains t)
 
   def articlesByCategory(c: iCategory): Seq[iArticle] =
-    Articles.values.filter(_.category contains(c))
+    Articles.values.filter(_.category contains c)
 
   def tags: Seq[iTag] = Tag.values