[lively-kernel] Programmatically dealing with Worlds

Robert Krahn robert.krahn at gmail.com
Thu Feb 20 04:14:57 CET 2014


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 <sean at clipperadams.com>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
> lively-kernel at hpi.uni-potsdam.de
> http://lists.hpi.uni-potsdam.de/listinfo/lively-kernel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hpi.uni-potsdam.de/archive/lively-kernel/attachments/20140219/9029f392/attachment-0001.html>


More information about the lively-kernel mailing list