From 7101f781efcef4b37fb7f7d55c1c9091224d732a Mon Sep 17 00:00:00 2001 From: ellemenno Date: Sun, 21 Aug 2016 20:23:45 -0400 Subject: [PATCH 1/7] change version to 0.0.2 --- lib/src/pixeldroid/json/Json.ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/pixeldroid/json/Json.ls b/lib/src/pixeldroid/json/Json.ls index b18aed7..4c2303a 100644 --- a/lib/src/pixeldroid/json/Json.ls +++ b/lib/src/pixeldroid/json/Json.ls @@ -6,7 +6,7 @@ package pixeldroid.json public class Json { - public static const version:String = '0.0.1'; + public static const version:String = '0.0.2'; static public function fromString(value:String):Json { From 0435a680888d2441d1096d654e8f444205533d13 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Sun, 21 Aug 2016 20:25:47 -0400 Subject: [PATCH 2/7] update to sprint34; accommodate API change for Type.getMethodInfo() --- lib/loom.config | 2 +- lib/src/pixeldroid/json/Json.ls | 2 +- test/loom.config | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/loom.config b/lib/loom.config index 12977d9..345d99b 100644 --- a/lib/loom.config +++ b/lib/loom.config @@ -1,3 +1,3 @@ { - "sdk_version": "sprint33" + "sdk_version": "sprint34" } \ No newline at end of file diff --git a/lib/src/pixeldroid/json/Json.ls b/lib/src/pixeldroid/json/Json.ls index 4c2303a..b063ddf 100644 --- a/lib/src/pixeldroid/json/Json.ls +++ b/lib/src/pixeldroid/json/Json.ls @@ -66,7 +66,7 @@ package pixeldroid.json default : if (item.hasOwnProperty('toJson')) { - var method:MethodInfo = item.getType().getMethodInfo('toJson'); + var method:MethodInfo = item.getType().getMethodInfoByName('toJson'); if (method) json = method.invokeSingle(item, null) as Json; } break; diff --git a/test/loom.config b/test/loom.config index 89957d1..1d34867 100644 --- a/test/loom.config +++ b/test/loom.config @@ -1,5 +1,5 @@ { - "sdk_version": "sprint33", + "sdk_version": "sprint34", "executable": "Main.loom", "display": { "width": 480, @@ -11,4 +11,4 @@ "app_id": "pixeldroid.JsonTest", "app_name": "JsonTest", "app_version": "0.0.1" -} +} \ No newline at end of file From e08082975a9bdbcf25054aa42ceb7fbef75c9b10 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Sun, 21 Aug 2016 20:26:06 -0400 Subject: [PATCH 3/7] update gitignore --- .gitignore | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 768cae4..df723dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -/releases +bin/ +lib/build/ logs/ -lib/build -test/bin +releases/ +test/bin/ TEST-*.xml From f31230b5fcd792ecee83c4f33a90f32e5098ab2f Mon Sep 17 00:00:00 2001 From: ellemenno Date: Sun, 21 Aug 2016 20:26:56 -0400 Subject: [PATCH 4/7] update spec test harness to handle --seed option and process exit code --- test/src/app/JsonTest.ls | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/src/app/JsonTest.ls b/test/src/app/JsonTest.ls index e8fb42b..b88889a 100644 --- a/test/src/app/JsonTest.ls +++ b/test/src/app/JsonTest.ls @@ -2,6 +2,7 @@ package { + import system.Process; import system.application.ConsoleApplication; import pixeldroid.bdd.Spec; @@ -16,23 +17,28 @@ package public class JsonTest extends ConsoleApplication { + private var seed:Number = -1; + private const SUCCESS:Number = 0; + private const FAILURE:Number = 1; + override public function run():void { JsonSpec.describe(); JsonPrinterSpec.describe(); - addReporters(); + parseArgs(); - Spec.execute(); + Process.exit(Spec.execute(seed) ? SUCCESS : FAILURE); } - private function addReporters():void + private function parseArgs():void { var arg:String; - for (var i = 2; i < CommandLine.getArgCount(); i++) + for (var i = 0; i < CommandLine.getArgCount(); i++) { arg = CommandLine.getArg(i); if (arg == '--format') Spec.addReporter(reporterByName(CommandLine.getArg(++i))); + if (arg == '--seed') seed = Number.fromString(CommandLine.getArg(++i)); } if (Spec.numReporters == 0) Spec.addReporter(new ConsoleReporter()); From 29c19610a428fd422d55103b9ac1aa22ce05f6b6 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Sun, 21 Aug 2016 22:15:26 -0400 Subject: [PATCH 5/7] update README for release --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7f8ab52..ad381a7 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,20 @@ json-ls JSON helpers for Loom +- `Json` - a utility to simplify json data access +- `JsonPrinter` - a pretty printer for json data + ## installation Download the library into its matching sdk folder: - $ curl -L -o ~/.loom/sdks/sprint33/libs/Json.loomlib \ - https://github.com/pixeldroid/json-ls/releases/download/v0.0.1/Json-sprint33.loomlib + $ curl -L -o ~/.loom/sdks/sprint34/libs/Json.loomlib \ + https://github.com/pixeldroid/json-ls/releases/download/v0.0.2/Json-sprint34.loomlib To uninstall, simply delete the file: - $ rm ~/.loom/sdks/sprint33/libs/Json.loomlib + $ rm ~/.loom/sdks/sprint34/libs/Json.loomlib ## usage @@ -43,6 +46,50 @@ var j:Json = Json.fromObject(jsonObject); trace(JsonPrinter.print(j, JsonPrinterOptions.compact)); ``` +### Json + +Loom provides the [JSON][loom-json] class, which provides strongly typed access to values, requiring separate accessors for every data type, and two families of these accessors for retrieving from Objects or Arrays. There are 18 basic accessors, and 2 methods for determining type. + +The `Json` class in this library aims to simplify access to json data, using the `Json` class itself as the single container type, which exposes only 3 basic accessors, and 1 more for type retrieval: + +- `keys` - a Dictionary of Json instances, indexed by Strings +- `items` - an Array of Json instances +- `value` - the actual data for the instance +- `type` - any basic System type, or Json + * `Null`, `Boolean`, `Number`, `String`, `Vector`, `Dictionary`, `Json` + +For comparison, the code snippets below present two ways to retrieve the second value of the nested array indexed by `r` in the following json data: + +```json +{ + "key": [ + {"a":1.23, "b":45.67}, + {"x":8, "y":9}, + {"q":[1,2], "r":[3,4], "n":null} + ], +} +``` + +> `json.json` + +#### Using `system.JSON` + +```ls +var jsonString:String = File.loadTextFile('assets/json.json'); +var j:JSON = JSON.parse(jsonString); +trace(j.getArray('key').getArrayObject(2).getArray('r').getArrayNumber(1)); +``` + +#### Using `pixeldroid.json.Json` + + +```ls +var jsonString:String = File.loadTextFile('assets/json.json'); +var j:Json = Json.fromString(jsonString); +trace(j.keys['key'].items[2].keys['r'].items[1]); +``` + + ### JsonPrinter This library includes a configurable JSON pretty-printer, with three pre-defined configurations for convenience: @@ -116,5 +163,6 @@ Pull requests are welcome! [loomtasks]: https://github.com/pixeldroid/loomtasks "loomtasks" +[loom-json]: http://docs.theengine.co/loom/1.1.4813/api/system/JSON.html "Loom JSON class" [JsonDemo.build]: ./test/src/JsonDemo.build "build file for the demo" [JsonDemo.ls]: ./test/src/JsonDemo.ls "source file for the demo" From 89db15ad2ebfc7b033327c7a9f6647ff19d98fbf Mon Sep 17 00:00:00 2001 From: ellemenno Date: Sat, 27 Aug 2016 21:08:21 -0400 Subject: [PATCH 6/7] clean up line breaks in license file --- LICENSE | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/LICENSE b/LICENSE index 183d7ca..8105a86 100644 --- a/LICENSE +++ b/LICENSE @@ -1,22 +1,21 @@ The MIT License (MIT) Copyright (c) pixeldroid +https://github.com/pixeldroid/json-ls -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 3f80314d1fd1ed0c09089b069d0ff5d7ce5039a0 Mon Sep 17 00:00:00 2001 From: ellemenno Date: Sat, 27 Aug 2016 21:08:52 -0400 Subject: [PATCH 7/7] cleanup readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ad381a7..bb9efd7 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,6 @@ trace(j.getArray('key').getArrayObject(2).getArray('r').getArrayNumber(1)); #### Using `pixeldroid.json.Json` - ```ls var jsonString:String = File.loadTextFile('assets/json.json'); var j:Json = Json.fromString(jsonString);