[TW5] New Plugin - Json Mangler!

356 views
Skip to first unread message

Joshua Fontany

unread,
Sep 7, 2017, 2:14:54 AM9/7/17
to tiddl...@googlegroups.com
Hi all,

I'd like to introduce a cool message-catcher widget and related UI tiddlers that I created to make working with Json Tiddler's a bit easier. Let me know what you all think! :)

= Thanks to all the folks that post here, it was interesting researching this problem to get to this working code. Mahalo - Thanks! =


$jsonmangler

This is a json mangler plugin for TiddlyWiki (http://tiddlywiki.com) by Joshua Fontany.

It contains a widget module $jsonmangler, which catches the following messages sent by the ActionSendMessage widget (within Button widgets, etc).

tm-json-refresh - Refreshes the json tiddler's formatting.

tm-json-flatten - Flattens the json's keys (flattens nested objects, etc) to one layer deep. Values are assigned to an index that is the dot-notation version of the path to the original value.

tm-json-unflatten - Unflattens the json's keys (re-nesting objects, etc) from a flat tiddler. Path Keys are read and objects are re-created.

tm-json-restore - Restores data from the json's archive. The Refresh, Flatten, and Unflatten operations store a copy of the old text field in an archive tiddler: $:/archive/json/jsonTiddlerTitle

tm-json-push / tm-json-pull - Flat jsons with titles that end in ".json" only. Pushes or pulls the json's keys (& optionally values) to or from the json's "parent". The parent is a tiddler with the exact same title without the ".json" extension.

This functionality is currently implemented in an Edit Template shown for all tildders of type 'application/json'. When creating new Json Tiddlers, set a 'flat' field to either "true" or "false" (depending on how the tiddler is created) and save the tiddler, then re-open the tiddler in edit mode to ensure all mangler functions are performed correctly.

See the example wiki for more information: https://joshuafontany.github.io/TW5-JsonManglerPlugin/

PMario

unread,
Sep 7, 2017, 4:38:17 AM9/7/17
to TiddlyWiki
Hi Joshua,

Very interesting. Thanks for sharing. ... but  :)

- There is no exaple tiddler, where you can play with the new commands. IMO it would be easier to use them, if we just need to copy paste :)

- please enable the "issues tab" at your github repo. So we can open issues. (github disables it, if you fork a repo)

thx
mario

Joshua Fontany

unread,
Sep 7, 2017, 11:34:19 AM9/7/17
to TiddlyWiki
Hi, thanks for the tip on "Issues", I've activated that for my repo.

The widget is fully implemented in the Edit template of any tiddler with "type" = "application/json" once the plugin is installed.

For example, edit any of the Json Tiddlers linked to at the bottom of my example Wiki's "Hello There" tiddler. You will see the new buttons in the Edit template that use the new messages.
https://joshuafontany.github.io/TW5-JsonManglerPlugin/

Best,
Joshua Fontany

Joshua Fontany

unread,
Sep 7, 2017, 11:50:02 AM9/7/17
to tiddl...@googlegroups.com
Oh, did you mean examples of how I send the messages? Right now they are setup to be used in an EditTemplate (as mentioned).

That can be found in the Plugin's shadow tiddler:

$:/plugins/telarus/jsonmangler/editTemplate/Json

Here is an example of some of the buttons from there (cut out a few buttons for the sake of the example). 
The <<fa-icon>> macro is just an easy way of transcluding FontAwesome icons (code also included with the plugin).

<$list filter="[is[current]type[application/json]]">

<div class="json-tools">

<$jsonmangler title=<<currentTiddler>> >

<!-- /* Refresh Json */ -->
<$button tooltip="Refresh Json Formatting" class="nottc-btn-invisible tc-tiddlylink" style="float: left; margin-right: 1em; padding: 4px;">
<$action-sendmessage $message="tm-json-refresh" />
<<fa-icon "retweet" "fa-lg fa-fw">> ''Refresh''
</$button>

<!-- /* Flatten/Unflatten */ -->
<$reveal type="nomatch" state="!!flat" text="true">
<$button tooltip="Flatten This Json" class="nottc-btn-invisible tc-tiddlylink" style="float: left; margin-right: 1em; padding: 4px;">
<$action-sendmessage $message="tm-json-flatten" />
<<fa-icon "list-ul" "fa-lg fa-fw">> ''Flatten''
</$button>
</$reveal>

<$reveal type="match" state="!!flat" text="true">
<$button tooltip="Unflatten This Json" class="nottc-btn-invisible tc-tiddlylink" style="float: left; margin-right: 1em; padding: 4px;">
<$action-sendmessage $message="tm-json-unflatten"/>
<<fa-icon "share-alt" "fa-lg fa-fw">> ''Unflatten''
</$button>
</$reveal>

</$jsonmangler>

</div>

<div class="clear" style="clear: both;"></div>

</$list>


--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/OMaRZ1mOZ2w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/4ffda938-b9bf-4139-ac64-6f7578ecde70%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

PMario

unread,
Sep 7, 2017, 1:09:29 PM9/7/17
to TiddlyWiki
On Thursday, September 7, 2017 at 5:34:19 PM UTC+2, Joshua Fontany wrote:
Hi, thanks for the tip on "Issues", I've activated that for my repo.

The widget is fully implemented in the Edit template of any tiddler with "type" = "application/json" once the plugin is installed.

Ah. OK. ... I should have opened one :)

-m

PMario

unread,
Sep 7, 2017, 1:25:25 PM9/7/17
to TiddlyWiki
On Thursday, September 7, 2017 at 5:50:02 PM UTC+2, Joshua Fontany wrote:
Oh, did you mean examples of how I send the messages? Right now they are setup to be used in an EditTemplate (as mentioned).

... OK
 
That can be found in the Plugin's shadow tiddler:

$:/plugins/telarus/jsonmangler/editTemplate/Json

Here is an example of some of the buttons from there (cut out a few buttons for the sake of the example). 
The <<fa-icon>> macro is just an easy way of transcluding FontAwesome icons (code also included with the plugin).

IMO you shoulkd try to remove this dependency. ... It's only 5 new icons needed.

For me the first 3 make sense ... 

For the next 2 I'd use other icons.

 - key .... push / pull   ... ... may be fa-arrows ... don't have a link.
 - bullet list / share ... archive .... fa-archive

The archive button imo is redundant. ... It stores the "opposit" strcture in a tiddler prefixed: $:/archive/json/
So may be the flatten / unflatten button can do this in a consistent way. So the users actually know what to expect in the prefixed tiddler.

... just some thoughts.

-m

Joshua Fontany

unread,
Sep 8, 2017, 8:09:18 PM9/8/17
to TiddlyWiki
Thanks for the creative criticism PMario. I've updated the repository and cleaned up the file-structure a bit (made the FontAwesome macros into their own plugin).

I will be using this to design "Models" and "Views" for an RPG Campaign Wiki, so that sub-types of Character, Items, Etc, can have individualized templates for their "statistics" and "stat sheets" to view them through. Look for that coming up pretty soon. :D

Mahalo!

codacoder...@outlook.com

unread,
Sep 15, 2017, 9:59:11 AM9/15/17
to TiddlyWiki
Hi Joshua

I think there's a problem... I did as suggested "Edit one of the existing Json Tiddlers to get started" and after clicking "Push Fields", I get this...



Win7, Firefox 55 and 57 (Nightly)
Auto Generated Inline Image 1

Joshua Fontany

unread,
Sep 15, 2017, 2:12:09 PM9/15/17
to TiddlyWiki
Thank you for the bug report. I will look into this. :)

Joshua Fontany

unread,
Sep 16, 2017, 9:39:19 PM9/16/17
to TiddlyWiki
This issue should be all fixed now. Test-wiki and source updated:

https://joshuafontany.github.io/TW5-JsonManglerPlugin/

Best,
Joshua Fontany
Reply all
Reply to author
Forward
0 new messages