Home Download Buy Blog Forum Support

PlistJsonConverter

Re: PlistJsonConverter

Postby quodlibet on Sun Apr 01, 2012 8:33 pm

facelessuser wrote:I personally like the toggle, because I can just toggle it to json, make changes, and toggle back and save.


Ah. This had not even crossed my mind. I toyed around with this workflow for a few minutes and it seems tenable, but I think that losing the comments might be a deal breaker here. As I said, I am learning regexp amid all this, to say nothing of the intricacies of .tmLanguage files.

Edit:
facelessuser wrote:Build systems are better for feeding an external executable that does some compile stuff with project variables.


I generally use build systems on a per-file level. Not being a programmer myself, I forget what you guys *actually* use them for :)
quodlibet
 
Posts: 561
Joined: Sat Jun 18, 2011 5:53 pm

Re: PlistJsonConverter

Postby facelessuser on Sun Apr 01, 2012 8:49 pm

I will add something in to save to a new file.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: PlistJsonConverter

Postby facelessuser on Mon Apr 02, 2012 4:52 am

I should have an acceptable solution for automatically creating the converted file or just creating the conversion in a new buffer. I need to do a little testing tomorrow first before I push it out.

You should be able to define what plist extension will map to which json extension. I will give more info when I push it out.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: PlistJsonConverter

Postby facelessuser on Mon Apr 02, 2012 4:03 pm

Version 0.2.0
- Add commands to save converted file with specified extension
- For buffer conversion, add setting to open in new buffer
- Allow the turning off of save commands and/or buffer commands

This should satisfy everyone's desires hopefully.

I have added commands to save the converted content directly with the extension of your choice. I have added an option to open conversions in their own new view buffer if not using the "save to file" commands. You can turn off the commands you don't want ("save to file" or "show in buffer"). So now you can set the preference you like, and hide commands you don't like.

This is flexible enough to be applied to any plist or json extension you want, and you can map the converted info to any extension you want. So this, will work with tmTheme, tmLanguages, tmPreferences, and anything else you want to add.

Settings:
Code: Select all
{
    "json_language": "Packages/Javascript/JSON.tmLanguage",
    "plist_language": "Packages/XML/XML.tmLanguage",

    // When converting buffer open conversion in new buffer
    "open_in_new_buffer": true,

    // Enable show conversion in a view buffer
    "enable_show_in_buffer_commands": true,

    // Enable creation of new file based on extension map containing the coverted data
    // If the current file to convert does not exist on disk, the converted file will default
    // To being shown in a view buffer only, and will not be automatcially saved to disk.
    "enable_save_to_file_commands": true,

    // When saving converted data to a file, or when opening
    // conversion in new buffer use these extension maps for file name.
    // Extensions will be evaluated in the order listed below.
    // If the file does not match any of the extensions, the current
    // extension will be replaced with either "plist" or "json" accordingly.
    "conversion_ext": [
        {"plist": "tmLanguage", "json": "tmLanguage.JSON"},
        {"plist": "tmPreferences", "json": "tmPreferences.JSON"},
        {"plist": "tmTheme", "json": "tmTheme.JSON"}
    ]
}


Let me know if you find any bugs or have any suggestions. I will make the request to add this to Package Control sometime soon.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: PlistJsonConverter

Postby facelessuser on Mon Apr 02, 2012 6:57 pm

Oh, I just wanted to mention, if a build system option is still desired, just let me know; it will take me only a couple of minutes to add. I am really just waiting to see if the new current method is sufficient or not.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: PlistJsonConverter

Postby quodlibet on Tue Apr 03, 2012 7:04 am

The convert & save command is perfect for my purposes.

I've encountered an error, which is probably related to my setup. I haven't worked out what the problem is. I'd be grateful for a pointer.

When trying to convert Markdown.tmLanguage from PLIST to JSON, I get the following in the console:
Code: Select all
error: Could not read view buffer as PLIST!
Please see console for more info.
Plist Json Converter Exception:
No module named pyexpat
quodlibet
 
Posts: 561
Joined: Sat Jun 18, 2011 5:53 pm

Re: PlistJsonConverter

Postby facelessuser on Tue Apr 03, 2012 1:17 pm

quodlibet wrote:The convert & save command is perfect for my purposes.

I've encountered an error, which is probably related to my setup. I haven't worked out what the problem is. I'd be grateful for a pointer.

When trying to convert Markdown.tmLanguage from PLIST to JSON, I get the following in the console:
Code: Select all
error: Could not read view buffer as PLIST!
Please see console for more info.
Plist Json Converter Exception:
No module named pyexpat


I am assuming conversion of any tmLanguage does not work for you. Are you on Linux (the one system I did not test)? Doing a quick search on the forums shows that the Linux version of ST2 does not use Linux's installed Python, but includes its own Python version (an incomplete version that does not have pyexpat).

If you are using Linux, are you using Ubuntu? I will have to fire this up in Ubuntu and see what I can I do. I think I can possibly just try to include Ubuntu's pyexpat from its installation. I think they include 2.6 and 2.7 Python. I will get back to you maybe tonight on that if I have time.

I do hope in the future ST2 would include pyexpat like it does on Windows. Hopefully pointed ST2 to a valid 2.6 pyexpat will work, or I will have to come up with some workaround plist conversion on LInux (which will take time).
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: PlistJsonConverter

Postby facelessuser on Tue Apr 03, 2012 3:42 pm

I actually found the solution not to bad and had a little time to fix it this morning.

Version 0.3.0
- Fix for Linux pyexpat errors
- Fix default JSON.tmLanguage path

Please read the readme.md file for more info. The fix by default is for Ubuntu, and you might have to make sure you have a full install of Python2.6 on Linux box instead of the default minimal install Ubuntu provides. I provided a setting to help with adapting this to other distros hopefully as well.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: PlistJsonConverter

Postby quodlibet on Tue Apr 03, 2012 7:47 pm

Yes, I'm on Ubuntu. Version 0.3.0 along with the full python 2.6 works perfectly. Thanks for the super quick fix!

Sorry, it took a while to reply.

Alex
quodlibet
 
Posts: 561
Joined: Sat Jun 18, 2011 5:53 pm

Re: PlistJsonConverter

Postby facelessuser on Tue Apr 03, 2012 9:18 pm

quodlibet wrote:Yes, I'm on Ubuntu. Version 0.3.0 along with the full python 2.6 works perfectly. Thanks for the super quick fix!

Sorry, it took a while to reply.

Alex


No biggie. As soon as you described the issue, I knew I had seen it mentioned before. Being one of those issues that have already been solved by others, I was pretty confident in the solution. I did fire it up in my Ubuntu VM to make sure though.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: Exabot [Bot] and 6 guests