# HG changeset patch # User Tomas Zeman # Date 1544537037 -3600 # Node ID 1e1b0a1a4d63460c2d3b0b4a197ab72ec0e7477b # Parent 7c4b054676303c59dbd6265f92f1e01be07b0603 Filesystem based article implementation diff -r 7c4b05467630 -r 1e1b0a1a4d63 base/src/sqwl/cms/FsArticle.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/src/sqwl/cms/FsArticle.scala Tue Dec 11 15:03:57 2018 +0100 @@ -0,0 +1,22 @@ +package sqwl.cms + +import java.nio.file.Path + +import scala.io.Source + +trait FsArticle extends iArticle { + + protected def contentPath: Path + protected def encoding: String = "UTF-8" + + override def htmlContent: String = { + val src = Source.fromFile(contentPath.toFile, encoding) + try { + src.getLines.mkString + } catch { + case _: Throwable => "" + } finally { + src.close() + } + } +} diff -r 7c4b05467630 -r 1e1b0a1a4d63 example/src/sqwl/cms/Content.scala --- a/example/src/sqwl/cms/Content.scala Thu Dec 06 17:01:32 2018 +0100 +++ b/example/src/sqwl/cms/Content.scala Tue Dec 11 15:03:57 2018 +0100 @@ -43,18 +43,10 @@ val category: Option[iCategory], val tags: Seq[iTag], -) extends EnumEntry with iArticle with Hyphencase { - override def htmlContent: String = { - val src = Source.fromFile(s"example/content/${entryName}.html", "UTF-8") - try { - src.getLines.mkString - } catch { - case _: Throwable => "" - } finally { - src.close() - } - } +) extends EnumEntry with FsArticle with Hyphencase { + override protected def contentPath: Path = Paths.get( + s"example/content/${entryName}.html") override def assets: Path = Paths.get(s"example/content/${entryName}") override def pathSegment: String = entryName }