|
1 | | -package dotty.tools.scaladoc |
2 | | -package site |
| 1 | +package dotty.tools.scaladoc.site |
3 | 2 |
|
4 | 3 | import com.fasterxml.jackson.databind.ObjectMapper |
5 | 4 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory |
6 | 5 | import com.fasterxml.jackson.databind.DeserializationFeature |
7 | 6 | import java.io.File |
8 | | -import scala.beans._ |
| 7 | +import scala.beans.{BooleanBeanProperty, BeanProperty} |
| 8 | +import scala.util.Try |
9 | 9 |
|
10 | 10 | case class BlogConfig( |
11 | | - @BeanProperty var input: String, |
12 | | - @BeanProperty var output: String, |
13 | | - @BooleanBeanProperty var hidden: Boolean |
| 11 | + @BeanProperty input: String, |
| 12 | + @BeanProperty output: String, |
| 13 | + @BooleanBeanProperty hidden: Boolean |
14 | 14 | ): |
15 | | - def this() = this(null, null, false) |
| 15 | + def this() = this(null, null, false) |
16 | 16 |
|
17 | 17 | object BlogParser: |
18 | | - def readYml(root: File): BlogConfig = |
19 | | - val ymlFile = root.toPath |
20 | | - .resolve("blog.yml") |
21 | | - .toFile |
| 18 | + def readYml(content: File | String): BlogConfig = |
| 19 | + val mapper = ObjectMapper(YAMLFactory()) |
| 20 | + .findAndRegisterModules() |
22 | 21 |
|
23 | | - if ymlFile.exists then |
24 | | - val mapper = new ObjectMapper(new YAMLFactory()) |
25 | | - mapper.findAndRegisterModules(); |
26 | | - |
27 | | - val blogConfig: BlogConfig = mapper.readValue(ymlFile, classOf[BlogConfig]) |
28 | | - blogConfig |
29 | | - else new BlogConfig |
| 22 | + content match |
| 23 | + case f: File => |
| 24 | + val ymlFile = f.toPath.resolve("blog.yml").toFile |
| 25 | + if ymlFile.exists then mapper.readValue(ymlFile, classOf[BlogConfig]) else new BlogConfig |
| 26 | + case s: String => Try(mapper.readValue(s, classOf[BlogConfig])).getOrElse(new BlogConfig) |
0 commit comments