Trying to alter TW from server-side script

3 views
Skip to first unread message

AlexG

unread,
Jan 5, 2008, 3:21:15 AM1/5/08
to TiddlyWikiDev
Hi!

I'm new at this, but I'm trying to write a TW plugin that allows the
wiki to be updated over the phone through Jott (www.jott.com). I need
to find a way for my server scripts to alter the TW, hopefully using
the built-in javascript functions instead of directly writing to the
TW's html file.

I was thinking of adding a javascript include somewhere in the file
and having the server script write to the included .js file. When the
TW is started by the user, the included .js file will create (through
document.write() ) a systemConfig tiddler that makes the changes
ordered by the user over the phone. Do you think there is a better way
to do this?

Even if this is the best way, I'm not sure how to place the <script
src=external.js...> tag. I could just open up the TW source code and
put the tag somewhere in the body, but for this to be a plugin usable
by others, it would have do all source edits from within the plugin
tiddler. I'd appreciate any help on this!



Oh, and if you guys haven't heard of Jott, it's the neat (and free)
phone service that makes a recording of your voice and sends anyone
the transcript as an email. They also have an api that will send the
transcript as a POST to any webpage, which is what i'm hoping to take
advantage of.

Thanks,
--Alex.

FND

unread,
Jan 5, 2008, 4:36:22 AM1/5/08
to Tiddly...@googlegroups.com
> I need to find a way for my server scripts to alter the TW

One way would be to use the r4tw Ruby classes:
http://randomibis.com/r4tw/
That's probably cleaner than the JS-based solution.

> hopefully using the built-in javascript functions

Those would only take effect when the TiddlyWiki file is opened/rendered
by a user/client (unless you're using server-side JavaScript, maybe, but
I know nothing about that) - but you seem to be aware that already.

> I was thinking of adding a javascript include somewhere in the file
> and having the server script write to the included .js file.

There's recently been a discussion on something very similar:
http://tinyurl.com/2ockfq
(http://groups.google.com/group/TiddlyWiki/browse_thread/thread/b602aa688c9fc2fa/)
For your purposes, loadExternal sounds like it does what you want. I'm
currently developing an enhanced version:
http://fnd.lewcid.org/svn/TiddlyWiki/plugins/TiddlyMasterPlugin/

> When the TW is started by the user, the included .js file will create
> (through document.write() ) a systemConfig tiddler

Using document.write() is not a good idea.
Take a look at the TiddlyMasterPlugin's importFiles() function; it
should give you an idea of how it works.
This function just creates new tiddlers from files; modifying existing
tiddlers would look something like this:
var tiddler = store.getTiddler(title);
if(tiddler) {
tiddler.text = "lorem ipsum dolor sit amet";
store.saveTiddler(currentTitle, newTitle, text, modifier,
modified, tags, fields, clearChangeCount, created);
}

> Even if this is the best way, I'm not sure how to place the <script
> src=external.js...> tag.

That's what the following shadow tiddlers are there for:
MarkupPostBody
MarkupPostHead
MarkupPreBody
MarkupPreHead
For an example of how this works, take a look at the "slave.html" sample
from the TiddlyMasterPlugin SVN repo.

HTH.


-- F.

Reply all
Reply to author
Forward
0 new messages