revlet and path
Devin Asay
devin_asay at byu.edu
Thu Aug 6 11:06:16 EDT 2009
Hi Tereza,
On Aug 6, 2009, at 7:29 AM, Tereza Snyder wrote:
>
> It sounds like this means that I can't reliably reference files—like
> external stacks or configuration files—'next to' my revlet on the
> server. Is this true? How about the value of 'the directory' or
> 'default folder'? How about referenced images?
>
> I routinely store application resources in a folder, 'resources', next
> to my apps that contain all kinds of stuff. I compute paths at startup
> depending on the effective filename. Do I have to change my
> architecture?
This is no different than stacks launched from a web server using a
desktop-based launcher app. The launched stack resides only in RAM so
it has no filename value, as it was not launched from a stackfile in
the local filesystem. If there is a defaultFolder, it's on the desktop
file system. When you work in this environment, you just have to
change your thinking a little bit. You can still have prefs and
resource files in a folder next to your stack, but instead of looking
in a relative filepath, you have to remember the URL to the stack
(obviously you know it or you couldn't launch the stack.) Remove the
stackname from the URL and you're left with the web URL ("filepath",
if you will) to the folder containing the stack. Just build a new URL
by appending the folder and file name of the resources/prefs file and
call it that way.
For example, let's say my revlet is at:
http://devin.com/revlets/mystackpage.html
It should be fairly simple to either derive the URL within the revlet
stack or to pass the URL as a parameter when launching the revlet. (I
haven't tried this myself yet, but I've seen others describe here how
to pass params.) Once your revlet stack has that information, just
have it do:
set the itemdelimiter to "/"
put item 1 to -2 of tURLreceivedAsParam & "/resources/myprefs.txt"
into tPrefsURL
put URL tPrefsURL into tMyPrefs
-- now do whatever you want with the prefs.
Like I said, I use a model similar to this all the time with stacks
launched from a web server, and it works great. I haven't explicitly
tried it with a revlet, but I see no reason why it wouldn't work. Of
course, one of the problems with this approach is that you can't write
to that web-based resource file. Welcome to the Web!
You have to use other strategies, such as using a database server like
MySQL or PostgreSQL, cookies, or an on-rev CGI that can write to the
server file.
So it's definitely doable, you just have to adapt to the new, more
restrictive Web environment.
Regards,
Devin
Devin Asay
Humanities Technology and Research Support Center
Brigham Young University
More information about the use-livecode
mailing list