Skip to content

Commit

Permalink
ADDED: json_dtd_to_asciio
Browse files Browse the repository at this point in the history
  • Loading branch information
nkh committed Nov 29, 2023
1 parent 3ee6020 commit 9e2efa5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ my $build = $class->new

pm_files => \%all_modules,

script_files => [qw(script/asciio script/tasciio script/asciio_to_text script/A script/T script/stdin_to_asciio_web) ],
script_files => [qw(script/asciio script/tasciio script/asciio_to_text script/A script/T script/stdin_to_asciio_web, script_dtd_to_asciio) ],
dist_author => 'Khemir Nadim ibn Hamouda. <[email protected]>',
dist_abstract => 'App::Asciio - ASCII diagramming',
);
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ script/T
script/asciio_to_text
script/startup_script.pl
script/stdin_to_asciio_web
script/json_dtd_to_asciio

setup/setup.ini

Expand Down
16 changes: 16 additions & 0 deletions documentation/mdbook_asciio/src/for_developers/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@

[**Executing your scripts**](scripting_execute.md)

## transform JSON, via Data::TreeDumper, to Asciio script

The *json_dtd_to_asciio' script is installed with Asciio. It will read a JSON stream from stdin.

It takes the following arguments:
- title
- x position
- y position
- 'box', if you want the data to be boxed
- start_level, 0/1: 0 meanss no start tree grlyph


```
<coordinates_json ./script/json_dtd_to_asciio '' 10 10 box 0 | stdin_to_asciio_web
```

## Simplified scripting interface

The simplified scripting interface is an API which hides some of the scripting details for you.
Expand Down
23 changes: 23 additions & 0 deletions script/json_dtd_to_asciio
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/env perl

use strict ; use warnings ;
use JSON ;
use Data::TreeDumper ;

my $title = $ARGV[0] // '' ;
my $x = $ARGV[1] // 0 ;
my $y = $ARGV[2] // 0 ;
my $box = $ARGV[3] // '' ;
my $start_level = $ARGV[4] // 1 ;

undef $/ ;
my $json = <STDIN> ;
my $data = from_json $json ;
my $dtd = DumpTree $data, $title, DISPLAY_ADDRESS => 0, START_LEVEL => $start_level ;

my $type = $box eq 'box' ? 'new_box' : 'new_text' ;

print "use App::Asciio::Scripting ;\n" ;
print "add '%s', $type(TEXT_ONLY =>'$dtd'), $x, $y ;"

#vim: set ft=perl :

0 comments on commit 9e2efa5

Please sign in to comment.