Programmatically dealing with Worlds

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Programmatically dealing with Worlds

Sean P. DeNigris
Administrator
Can I do e.g. a batch rename to move my worlds from [username]/[newSubDirectory]/[worldName].html to  [username]/[worldName].html
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Programmatically dealing with Worlds

Robert Krahn-4
Apologies, this kind of stuff should be directly supported. For now you can use the snippet below.

Note, rename/copying a world is actually very straightforward, the only issue that you have to pay attention to is to properly link the bootstrap script since this is link is relative and needs to change when you change the location of the world.


Snippet:

function copyWorld(from, to) {
    // usage like:
    //   copyWorld('users/robertkrahn/foo/world.html', 'users/robertkrahn/world.html');
    var toURL = URL.root.withFilename(to),
        htmlSource = URL.source.asWebResource().get().content,
        html = $($.parseHTML(htmlSource, document, true/*keep scripts*/)),
        bootstrapModuleURL = new URL(module("lively.bootstrap").uri()),
        bootstrapFile = bootstrapModuleURL.relativePathFrom(toURL);
    html.filter('script[src]').attr('src', bootstrapFile);
    var newHTML = html.toArray().map(function(ea) { return Exporter.stringify(ea); }).join('\n');
    toURL.asWebResource().put(newHTML);
}



On Wed, Feb 19, 2014 at 4:11 AM, Sean P. DeNigris <[hidden email]> wrote:
Can I do e.g. a batch rename to move my worlds from
[username]/[newSubDirectory]/[worldName].html to
[username]/[worldName].html



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Programmatically-dealing-with-Worlds-tp4744819.html
Sent from the Lively Kernel mailing list archive at Nabble.com.
_______________________________________________
lively-kernel mailing list
[hidden email]
http://lists.hpi.uni-potsdam.de/listinfo/lively-kernel


_______________________________________________
lively-kernel mailing list
[hidden email]
http://lists.hpi.uni-potsdam.de/listinfo/lively-kernel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Programmatically dealing with Worlds

Sean P. DeNigris
Administrator
Robert Krahn-4 wrote
Apologies, this kind of stuff should be directly supported. For now you can
use the snippet below.
NP, thanks!
Cheers,
Sean
Loading...