Jump to content

External JS file?


esmith

Recommended Posts

My manager would like to see the JS code used in FP templates incorporated into github to track revisions and manage changes between users. Is there a way to move the JavaScript rules to a single external file which could be referenced by FP Desktop, FP Direct and FP Server (assuming all are on a common network)?

 

Ideally I would like the single file to do double duty by also serving as the master branch on a "FusionPro repository" on github.

Link to comment
Share on other sites

In order to avoid having users modify the installed .js files, we added the ability for users to create their own .js files in the Plug-ins folder. The idea here is that the reusable logical components are not so much entire rules, but functions that other rules can be built upon.

In other words, Building Blocks.

However, using the Plug-ins folder also has the disadvantage that the customizations only affect jobs on that one machine. That's why we came up with the JavaScript Globals dialog, so that reusable JavaScript logic, that is, functions that are called from multiple rules (or even multiple times within the same rule), could be kept with the job. And we added the Load function so that reusable logic could be shared between jobs, even on different machines.

Now, the rule templates are not so much reusable code as starting points, so simply having the rule templates on only one machine doesn't mean that you can't create rules based on those templates and still run your job with those rules on another machine without the original templates, but this could cause confusion if you are instructing your users to use a specific template, and they don't have it on their machine because a new version of FusionPro was installed but you forgot to update the RuleTemplates.English.js file with your custom version.

Or if they are running under a different language and therefore loading a different RuleTemplates file.

That's why I now recommend using the JavaScript Globals. You can simply copy-and-paste functions from one job's globals to another's, and the logic will always be kept with your job, that is, with the PDF file.

The one drawback of this approach, as opposed to adding .js files in the Plug-ins folder, is that the functions will not appear in the Building Blocks dialog.

Also, if you need a utility function only in one particular rule, you can go ahead and declare it right in the Rule Editor for that rule, at the top before the code that calls it. It will not be global to other rules, but you can call it within the rule you are editing.

Alternately, you can use the Load function to process external .js files. If the .js file is in the same folder as your template PDF, this makes it easy to keep the job portable, although one caveat is that using the Collect feature from the FusionPro menu will not collect .js files, so you will have to manually copy the .js file along with the PDF template.

Also, you can use the Load function with a UNC path to access a common .js file within your Windows network domain. This can be handy if you have any kind of company-wide logic that might change over time, like a seasonal logo. You can also do this on Mac by referencing a shared volume, but you need to mount the remote server manually before invoking the Load function, as there is no UNC-type auto-mounting available under the CFM Carbon/HFS architecture. (Although in the future, you may be able to use a BSD-style mount command with POSIX paths, if we can keep up with changes in the Mac runtime architecture.)

Obviously, there is a lot of information here, and there are a lot of ways to share JavaScript logic between jobs. I hope I haven't confused anyone. Some of this has evolved over time, and some of it may need to be re-thought out for future versions. We are always looking for ways to improve our JavaScript interface, so please continue to let us know what you are doing, and what does and doesn't work.

Link to comment
Share on other sites

Also, you can use the Load function with a UNC path to access a common .js file within your Windows network domain. This can be handy if you have any kind of company-wide logic that might change over time, like a seasonal logo. You can also do this on Mac by referencing a shared volume, but you need to mount the remote server manually before invoking the Load function, as there is no UNC-type auto-mounting available under the CFM Carbon/HFS architecture. (Although in the future, you may be able to use a BSD-style mount command with POSIX paths, if we can keep up with changes in the Mac runtime architecture.)

This option might work in our scenario. Could you give me an example of the Load syntax?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...