This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 11 - Pages: 1 - Last Post: 7 Apr 22, 18:22 Last Post By: RobM
AndreWolff

Posts: 2,504
Registered: 14-Dec-2007
Problem replacing a script in a new module
Posted: 7 Apr 22, 10:55
 
  Click to reply to this thread Reply
I have in module index.htt of the PhotoSwipe skin a large script which I like to put in a separate file initGallery.js in the res directory.

Currently that piece of code in index.htt is:
<script type="module">
	var toggleUI=false;  
    <ja:if test="<%= level > 0 %>">
	import PhotoSwipeLightbox from '${resourcePath}/photoswipe-lightbox.esm.min.js'; 
etc.
This code will be replaced by
<script src="${resourcePath}/initGallery.js" type="module"></script> 
with a new initGallery.htt template file.

So I added to init.bsh at around line 691
 File initGalleryTemplate = new File(skinDirectory, "initGallery.htt"); 
  if (initGalleryTemplate.exists())
  { 
    initGallery = "initGallery.js";
    engine.processTemplateFile(initGalleryTemplate, new File(resDirectory,initGallery));
  }
and made a initGallery.htt file which started with
<%
  //   file initGallery.htt  for PhotoSwipe 2022-04-07
  %>
	var toggleUI=false;  
    <ja:if test="<%= level > 0 %>">
	import PhotoSwipeLightbox from './photoswipe-lightbox.esm.min.js'; 
If I try to make an album I get immediately this crash:
Stack trace for jAlbum 27.0.4 using skin PhotoSwipeNew 5.2.1:
 
se.datadosen.util.ScriptException: javax.script.ScriptException: Sourced file: inline evaluation of: `` level > 0 ;'' : illegal use of undefined variable, class, or 'void' literal : at Line: 1 : in file: inline evaluation of: `` level > 0 ;'' : ; 
 in init.bsh at line number 691
	at se.datadosen.util.ScriptException.of(ScriptException.java:59)
 
Caused by: javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``/*   * init.bsh last change: 2022-04-07   * Executed only once before the creati . . . '' : Method Invocation engine.processTemplateFile : at Line: 691 : in file: inline evaluation of: ``/*   * init.bsh last change: 2022-04-07   * Executed only once before the creati . . . '' : engine .processTemplateFile ( initGalleryTemplate , new File ( resDirectory , initGallery ) ) 

Target exception: se.datadosen.util.ScriptException: javax.script.ScriptException: Sourced file: inline evaluation of: `` level > 0 ;'' : illegal use of undefined variable, class, or 'void' literal : at Line: 1 : in file: inline evaluation of: `` level > 0 ;'' : ; 
 in initGallery.htt at line number 6
 in inline evaluation of: ``/*   * init.bsh last change: 2022-04-07   * Executed only once before the creati . . . '' at line number 691
	at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:90)

I have no idea what I am doing wrongly, so your help is appreciated.

In case you like to test it, the jaskin file is enclosed.
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 11:08   in response to: AndreWolff in response to: AndreWolff
Helpful
  Click to reply to this thread Reply
Search the forum using Level && init
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 11:17   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
Search the forum using Level && init
And try reading the Variables wiki page carefully, especially the section header for Template file variables
AndreWolff

Posts: 2,504
Registered: 14-Dec-2007
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 12:28   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
Search the forum using Level && init
Thanks Rob for the hint.

I removed variable level because it is now no longer needed in the new module if it is in the res directory.
Problem solved!
AndreWolff

Posts: 2,504
Registered: 14-Dec-2007
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 12:38   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
And try reading the Variables wiki page carefully, especially the section header for Template file variables
Well I am not sure which page you mean, I visited https://jalbum.net/help/en/Variables
and there it is saild that variable level can be used as template variable!

So is that an error in the Wiki?
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 12:46   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
RobM wrote:
And try reading the Variables wiki page carefully, especially the section header for Template file variables
Well I am not sure which page you mean, I visited https://jalbum.net/help/en/Variables
and there it is saild that variable level can be used as template variable!

So is that an error in the Wiki?

No error, init.bsh is not a template.
AndreWolff

Posts: 2,504
Registered: 14-Dec-2007
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 12:55   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
No error, init.bsh is not a template.
It is not used in init.bsh, but in initGallery.htt
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 13:10   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
RobM wrote:
No error, init.bsh is not a template.
It is not used in init.bsh, but in initGallery.htt
From the error message you posted, undefined variable in init.bsh:
ScriptException: Sourced file: inline evaluation of: `` level > 0 ;'' : 
illegal use of undefined variable, class, or 'void' literal : 
at Line: 1 : in file: inline evaluation of: `` level > 0 ;'' : ; 
in init.bsh at line number 691
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 13:14   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
To clarify for you, the template initGallery.htt is being processed from init.bsh, not from index.htt or slide.htt
AndreWolff

Posts: 2,504
Registered: 14-Dec-2007
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 14:53   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
To clarify for you, the template initGallery.htt is being processed from init.bsh, not from index.htt or slide.htt
I think you should describe this difference in the description of the template file variable level in the WIKI.

Are there more variables which cannot be used in this case?
JeffTucker

Posts: 8,462
Registered: 31-Jan-2006
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 15:15   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
You've been down this road before:

https://jalbum.net/forum/thread.jspa?messageID=345129&#345129

When init.bsh is being executed, there is no level. There is no current folder. There is no current album object. The core has not started to parse the project tree. It doesn't have any idea what objects are in the project. So it can't access any variable that refers to any of those object-specific things.
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Problem replacing a script in a new module
Posted: 7 Apr 22, 18:22   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
You've been down this road before:

https://jalbum.net/forum/thread.jspa?messageID=345129&#345129

When init.bsh is being executed, there is no level. There is no current folder. There is no current album object. The core has not started to parse the project tree. It doesn't have any idea what objects are in the project. So it can't access any variable that refers to any of those object-specific things.

Yes, the hint of searching the forum I gave above gives that thread as the first result. Andre should call a method requiring template variables from index.htt, within an execute once function script block if appropriate.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums