|
Mailing Lists
|
Home /
Groups /
Studio
A Toolbar Script To Open A Relative Path
Author: Charles Arehart
Short Link: http://www.houseoffusion.com/groups/studio/thread.cfm/threadid:3#4
Dave, that's an interesting tool. Thanks for sharing it. Just one question,
and if you don't mind I didn't read the code to find the answer: while it's
designed to handle relative paths, what will happen if it uses a
webroot-relative path, as in:
<CFLOCATION TEMPLATE="/subdirectory/my_other_template.cfm">
or indeed, what if that root is actually a mapped path as setup in the web
server (since CFLOCATION will respect those) to go to a directory other than
that named? If it is handled, then perhaps the description below could
indicate that in case anyone would wonder.
Not trying to rain on the parade, just wondering if these were facets you
had anticipated.
Indeed, I'm sure some will like to see this extended to CFINCLUDES and
CFMODULE as well (though those then have a similar challenge of how to
interpret a slash-prefixed path: is it a webroot relative path or a mapping
in the CF Administrator?)
/charlie
PS This is the first note I've gotten on this list (don't recall when I'd
joined), and the archive on the site shows it to only have one other note in
the archives. Is it that it's a brand new list? If so, Michael, what sort of
things would you like to see discussed here? I can think of all kinds of
potential subjects, but what was the intent? :-)
Hi Guys!
When I debug, I find that I'm having to open files that are referenced
relative to the template I'm looking at. Here is a toolbar script I call
"The Canopener" that does all that using the Visual Tools Object Model
Application Object general methods ExtractFilePath and OpenFile. Take a tag
like this:
<CFLOCATION TEMPLATE="../../subdirectory/my_other_template.cfm">
and select everything within the double quotes. This script will open the
my_other_template.cfm document with a "clean" path - free of double dots or
forward slashes and the ALL-CAPS style seen in some error messages.
If anybody can lead me to a better custom button image than the canopener
image I have at http://www.wscccpca.org/images/canopener.gif,
I would much
appreciate it. Here's the script:
/*
Id: /UserData/Scripts/OpenRelativePath.js, v1.0.4 10/1/2001 8:59:58 AM
dbabbitt
Description:
Select a relative path and this script will open the document with a
"clean"
path - free of double dots or forward slashes and the ALL-CAPS style seen
in some error messages.
When I debug, I find that I'm having to open files that are referenced
relative to the template I'm looking at. Here is a toolbar script I call
"The Canopener" that does all that using the Visual Tools Object Model
Application Object general methods ExtractFilePath and OpenFile.
OpenFile:
function OpenFile(const wsFile: WideString): WordBool
Opens the passed file, returning True if successful. Return True if the
file is already open. Passing an empty string to OpenFile will display the
"Open File" dialog box, enabling the user select the file(s) to open.
When using this method in JScript, you must escape backslashes inside a
string. For example, in Application.OpenFile("C:\\Documents\\MyFile.htm");
each backslash is preceded by an additional backlash.
ExtractFilePath:
function ExtractFilePath(const wsFile: WideString): WideString
Returns the path of the passed file (includes trailing `\').
*/
function Main() {
var i = 80;
/* Create the application object variable */
var app = Application;
app.SetProgress(i++);
/* Create the document object variable */
var oDocument = app.ActiveDocument;
app.SetProgress(i++);
/* Create the relative path - assume the file system is not case sensitive
*/
var basePath = app.ExtractFilePath(oDocument.Filename);
// app.MessageBox('basePath = "' + basePath + '"', 'basePath = "' +
basePath + '"', 0);
app.SetProgress(i++);
var templatePath = oDocument.SelText;
// app.MessageBox('templatePath = "' + templatePath + '"', 'templatePath =
"' + templatePath + '"', 0);
app.SetProgress(i++);
if(basePath.length>0) {
while(templatePath.indexOf("../")==0) {
/* Remove the last slash from the base path and extract its file path
again */
basePath = app.ExtractFilePath(basePath.substr(0, basePath.length - 1));
// app.MessageBox('basePath = "' + basePath + '"', 'basePath = "' +
basePath + '"', 0);
app.SetProgress(i++);
/* Pop the dot dot slashes off the front of the selected text */
templatePath = templatePath.substr(3, templatePath.length);
// app.MessageBox('templatePath = "' + templatePath + '"', 'templatePath
= "' + templatePath + '"', 0);
app.SetProgress(i++);
}
templatePath = basePath + templatePath;
app.SetProgress(i++);
}
/* If it's all upper case, why can't it be all lower case? */
if(templatePath==templatePath.toUpperCase()) {
templatePath = templatePath.toLowerCase();
app.SetProgress(i++);
}
/* Replace all the forward slashes with back slashes */
var reObj = new RegExp("/", "g");
app.SetProgress(i++);
templatePath = templatePath.replace(reObj, "\\");
app.SetProgress(i++);
/* Open the relative path */
if(app.OpenFile(templatePath)) {
app.SetProgress(100);
app.SetStatusText(templatePath + ' is now open or already open!');
}
else {
app.SetProgress(100);
app.SetStatusText(templatePath + ' not open');
}
app.SetProgress(0);
}
/*
Log: /UserData/Scripts/OpenRelativePath.js
Revision 1.0 8/10/2001 9:45:49 AM dbabbitt
Basic functionality copied from the info
header function.
*/
Archives: http://www.mail-archive.com/studio@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
|
May 25, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||