Last active
November 24, 2015 08:58
Revisions
-
chandu0101 revised this gist
Nov 24, 2015 . 1 changed file with 20 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,16 @@ import org.scalajs.dom object ScalaJSExample extends js.JSApp{ case class FieldName(name : String , tpe : String) def main(): Unit = { val name = "SeedCategory" val input = s""" |val id: String |val category: String """.stripMargin @@ -25,22 +20,35 @@ object ScalaJSExample extends js.JSApp{ FieldName(s2.head,s2.last) }).filter(ft => ft.name.nonEmpty && ft.tpe.nonEmpty) val comanionObject = s""" |object $name { | | def apply(${fieldTypes.map(ft => s"${ft.name}: ${ft.tpe}").mkString(", ")})= { | ${fieldTypes.map(ft => s"val ${ft.name}_sh = ${ft.name} ").mkString("\n")} | new $name { | ${fieldTypes.map(ft => s"val ${ft.name} = ${ft.name}_sh").mkString("\n")} | } | } | |} """.stripMargin val copyMethod = s""" | def copy(${fieldTypes.map(ft => s"${ft.name}: ${ft.tpe} = ${ft.name}").mkString(", ")})= { | ${fieldTypes.map(ft => s"val ${ft.name}_sh = ${ft.name} ").mkString("\n")} | new $name { | ${fieldTypes.map(ft => s"val ${ft.name} = ${ft.name}_sh").mkString("\n")} | } | } | """.stripMargin println(comanionObject) dom.window.console.log(comanionObject) println(copyMethod) dom.window.console.log(copyMethod) } } -
chandu0101 created this gist
Nov 24, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ import Math._ import org.scalajs.dom object ScalaJSExample extends js.JSApp{ case class FieldName(name : String , tpe : String) def main(): Unit = { val name = "Seed" val input = s""" |val id: String |val name: String | val category: SeedCategory | val duration: Int | val geolocations: js.Array[GeoJsonFeature] | val info: String | val image: Image """.stripMargin val fieldTypes = input.split("\n").filter(_.nonEmpty).map(s => { val s1 = s.trim.replace("val","").replace(" ","") val s2 = s1.split(":") FieldName(s2.head,s2.last) }).filter(ft => ft.name.nonEmpty && ft.tpe.nonEmpty) val result = s""" |object $name { | | def apply(${fieldTypes.map(ft => s"${ft.name}: ${ft.tpe}").mkString(", ")})= { | ${fieldTypes.map(ft => s"val ${ft.name}_sh = ${ft.name} ").mkString("\n")} | new $name { | ${fieldTypes.map(ft => s"val ${ft.name} = ${ft.name}_sh").mkString("\n\n")} | } | } | |} """.stripMargin println(result) dom.window.console.log(result) } }