Skip to content

Commit f3476f1

Browse files
authored
Merge pull request #3 from ellemenno/v0.0.3
v0.0.3
2 parents 7e46151 + 4bea271 commit f3476f1

File tree

15 files changed

+256
-258
lines changed

15 files changed

+256
-258
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
bin/
1+
cli/bin/
22
lib/build/
3-
logs/
43
releases/
54
test/bin/
6-
TEST-*.xml
5+
test/TEST-*.xml

README.md

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,14 @@ json-ls
33

44
JSON helpers for Loom
55

6-
- `Json` - a utility to simplify json data access
7-
- `JsonPrinter` - a pretty printer for json data
6+
- [rationale](#rationale)
7+
- [installation](#installation)
8+
- [usage](#usage)
9+
- [building](#building)
10+
- [contributing](#contributing)
811

912

10-
## installation
11-
12-
Download the library into its matching sdk folder:
13-
14-
$ curl -L -o ~/.loom/sdks/sprint34/libs/Json.loomlib \
15-
https://github.com/pixeldroid/json-ls/releases/download/v0.0.2/Json-sprint34.loomlib
16-
17-
To uninstall, simply delete the file:
18-
19-
$ rm ~/.loom/sdks/sprint34/libs/Json.loomlib
20-
21-
22-
## usage
23-
24-
0. declare a reference to the Json loomlib in your `.build` file:
25-
*
26-
```json
27-
"references": [
28-
"System",
29-
"Json"
30-
],
31-
```
32-
0. import `pixeldroid.json.Json`
33-
0. instantiate a new `pixeldroid.json.Json` and call the `fromString()` or `fromObject()` method on it
34-
0. retrieve values for key / item chains as desired
35-
0. print to formatted JSON string with JsonPrinter
36-
37-
```ls
38-
var jsonString:String = File.loadTextFile('assets/json.json');
39-
var j:Json = Json.fromString(jsonString);
40-
trace(j.keys['key_name'].items[2].value);
41-
```
42-
43-
```ls
44-
var jsonObject:Dictionary.<String, Object> = { "bool": true, "array": [1,23], "string": "one two three" };
45-
var j:Json = Json.fromObject(jsonObject);
46-
trace(JsonPrinter.print(j, JsonPrinterOptions.compact));
47-
```
48-
49-
### Json
13+
## rationale
5014

5115
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.
5216

@@ -132,14 +96,55 @@ No extra whitespace:
13296

13397
see an example of using Json here:
13498

135-
* [JsonDemo.build][JsonDemo.build]
136-
* [JsonDemo.ls][JsonDemo.ls]
99+
* [JsonDemoCLI.build][JsonDemoCLI.build]
100+
* [JsonDemoCLI.ls][JsonDemoCLI.ls]
137101

138102
you can compile and run the demo from the command line:
139103

140-
$ rake demo:gui
104+
$ rake cli
105+
106+
107+
## installation
108+
109+
Download the library into its matching sdk folder:
110+
111+
$ curl -L -o ~/.loom/sdks/sprint34/libs/Json.loomlib \
112+
https://github.com/pixeldroid/json-ls/releases/download/v0.0.3/Json-sprint34.loomlib
113+
114+
To uninstall, simply delete the file:
115+
116+
$ rm ~/.loom/sdks/sprint34/libs/Json.loomlib
117+
118+
119+
## usage
120+
121+
0. declare a reference to the Json loomlib in your `.build` file:
122+
*
123+
```json
124+
"references": [
125+
"System",
126+
"Json"
127+
],
128+
```
129+
0. import `pixeldroid.json.Json`
130+
0. instantiate a new `pixeldroid.json.Json` and call the `fromString()` or `fromObject()` method on it
131+
0. retrieve values for key / item chains as desired
132+
0. print to formatted JSON string with JsonPrinter
133+
134+
```ls
135+
var jsonString:String = File.loadTextFile('assets/json.json');
136+
var j:Json = Json.fromString(jsonString);
137+
trace(j.keys['key_name'].items[2].value);
138+
```
139+
140+
```ls
141+
var jsonObject:Dictionary.<String, Object> = { "bool": true, "array": [1,23], "string": "one two three" };
142+
var j:Json = Json.fromObject(jsonObject);
143+
trace(JsonPrinter.print(j, JsonPrinterOptions.compact));
144+
```
145+
141146

142-
## working from source
147+
## building
143148

144149
> first install [loomtasks][loomtasks]
145150
@@ -163,5 +168,5 @@ Pull requests are welcome!
163168

164169
[loomtasks]: https://github.com/pixeldroid/loomtasks "loomtasks"
165170
[loom-json]: http://docs.theengine.co/loom/1.1.4813/api/system/JSON.html "Loom JSON class"
166-
[JsonDemo.build]: ./test/src/JsonDemo.build "build file for the demo"
167-
[JsonDemo.ls]: ./test/src/JsonDemo.ls "source file for the demo"
171+
[JsonDemoCLI.build]: ./cli/src/JsonDemoCLI.build "build file for the CLI demo"
172+
[JsonDemoCLI.ls]: ./cli/src/JsonDemoCLI.ls "source file for the CLI demo"

Rakefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
21
LIB_NAME = 'Json'
32
LIB_VERSION_FILE = File.join('lib', 'src', 'pixeldroid', 'json', 'Json.ls')
43

54
begin
65
load(File.join(ENV['HOME'], '.loom', 'tasks', 'loomlib.rake'))
7-
load(File.join(ENV['HOME'], '.loom', 'tasks', 'loomlib_demo.rake'))
86
rescue LoadError
97
abort([
10-
'error: missing loomtasks',
11-
' please install loomtasks v1.1.0 or later before running this Rakefile:',
8+
'error: missing loomlib.rake',
9+
' please install loomtasks before running this Rakefile:',
1210
' https://github.com/pixeldroid/loomtasks/',
1311
].join("\n"))
1412
end
15-
16-
Rake::Task['demo:cli'].clear # no cli demo for this project

cli/loom.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"sdk_version": "sprint34"
3+
}

cli/src/JsonDemoCLI.build

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "JsonDemoCLI",
3+
"version": "1.0",
4+
"outputDir": "bin",
5+
"references": [
6+
"System",
7+
"Json"
8+
],
9+
"modules": [
10+
{
11+
"name": "JsonDemoCLI",
12+
"version": "1.0",
13+
"sourcePath": [
14+
"."
15+
]
16+
}
17+
],
18+
"executable": true
19+
}

cli/src/JsonDemoCLI.ls

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package
2+
{
3+
import system.application.ConsoleApplication;
4+
5+
import pixeldroid.json.Json;
6+
import pixeldroid.json.JsonPrinter;
7+
import pixeldroid.json.JsonPrinterOptions;
8+
9+
10+
public class JsonDemoCLI extends ConsoleApplication
11+
{
12+
override public function run():void
13+
{
14+
var jsonObject:Dictionary.<String,Object> = { "bool": true, "array": [1,23], "string": "aA bB cC" };
15+
trace('source:\n' +dictionaryToString(jsonObject));
16+
17+
var j:Json = Json.fromObject(jsonObject);
18+
trace('standard:\n' +JsonPrinter.print(j, JsonPrinterOptions.standard));
19+
trace('compact:\n' +JsonPrinter.print(j, JsonPrinterOptions.compact));
20+
trace('minified:\n' +JsonPrinter.print(j, JsonPrinterOptions.minified));
21+
}
22+
23+
private function dictionaryToString(d:Dictionary.<String,Object>):String
24+
{
25+
var s:String = '';
26+
27+
for (var k:String in d)
28+
{
29+
s += '"' +k +'": ' +d[k].toString() +'\n';
30+
}
31+
32+
return s;
33+
}
34+
}
35+
}

lib/src/Json.build

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"name": "Json",
3-
"version": "1.0",
4-
"outputDir": "./build",
5-
"references": [
6-
"System"
7-
],
8-
"modules": [
9-
{
10-
"name": "Json",
11-
"version": "1.0",
12-
"sourcePath": [
13-
"."
14-
]
15-
}
16-
]
2+
"name": "Json",
3+
"version": "0.0.3",
4+
"outputDir": "./build",
5+
"references": [
6+
"System"
7+
],
8+
"modules": [
9+
{
10+
"name": "Json",
11+
"version": "0.0.3",
12+
"sourcePath": [
13+
"."
14+
]
15+
}
16+
]
1717
}

lib/src/pixeldroid/json/Json.ls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package pixeldroid.json
66

77
public class Json
88
{
9-
public static const version:String = '0.0.2';
9+
public static const version:String = '0.0.3';
1010

1111
static public function fromString(value:String):Json
1212
{
File renamed without changes.

test/loom.config

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
{
2-
"sdk_version": "sprint34",
3-
"executable": "Main.loom",
4-
"display": {
5-
"width": 480,
6-
"height": 320,
7-
"title": "JsonTest",
8-
"stats": true,
9-
"orientation": "landscape"
10-
},
11-
"app_id": "pixeldroid.JsonTest",
12-
"app_name": "JsonTest",
13-
"app_version": "0.0.1"
14-
}
2+
"sdk_version": "sprint34"
3+
}

0 commit comments

Comments
 (0)