[web2py] Re: dependencies inside 'static' folder

2018-06-28 Thread pbreit
Anthony, et al,

with this question and the other similar one in regards to Vue it seems 
like we need a solid, standard way to implement client-side JavaScript 
libraries.

Are the options pretty much: 1) routes.py and 2) relative URLs? And then 
where to store the library (ie, in /static or use a CDN)? How every thing 
works together with NPM package management?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: dependencies inside 'static' folder

2018-06-27 Thread Jon Subscripted
Thanks for your response Anthony, I'll try what you suggest.

On Sun, Jun 24, 2018 at 5:20 AM, Anthony  wrote:

> On Saturday, June 23, 2018 at 11:05:35 PM UTC-4, Jonsubs wrote:
>>
>> Hi everyone,
>> I'm a web2py newbie and I'm trying to use a third party JS library
>> (chessboard.js from http://www.chessboardjs.com/). The library is used
>> to show a chessboard in the webpage. It does use some images to show the
>> chess pieces, the javascript has a relative path in the code:
>>
>> cfg.pieceTheme = 'img/chesspieces/wikipedia/{piece}.png';
>>
>
> This is relative to the path of the current file (which is the JS file
> itself), so you should put the /img folder inside the /static/js folder.
>
>
>> b) cfg.pieceTheme = URL('static','img/chesspieces/wikipedia/{piece}.png');
>> //and it fails also
>>
>
> Note, URL() is a Python function that works only on the server in the
> web2py environment -- you cannot insert it into a static JS file, which is
> executed entirely within the browser.
>
>
>> The only way I found, so far, to display images is to use the absolute
>> path, see below, which looks like a really bad work around.
>>
>> cfg.pieceTheme = 'http://127.0.0.1:8000/tablero/static/img/chesspieces/
>> wikipedia/{piece}.png';
>>
>
> If you want to keep the file in /static/img, you can still use a relative
> URL:
>
> cfg.pieceTheme = '../img/chesspieces/wikipedia/{piece}.png
> 
> ';
>
> The ../ will traverse from the /js folder up one level to the /static
> folder.
>
> Anthony
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: dependencies inside 'static' folder

2018-06-23 Thread Anthony
On Saturday, June 23, 2018 at 11:05:35 PM UTC-4, Jonsubs wrote:
>
> Hi everyone,
> I'm a web2py newbie and I'm trying to use a third party JS library 
> (chessboard.js from http://www.chessboardjs.com/). The library is used to 
> show a chessboard in the webpage. It does use some images to show the chess 
> pieces, the javascript has a relative path in the code:
>
> cfg.pieceTheme = 'img/chesspieces/wikipedia/{piece}.png';
>

This is relative to the path of the current file (which is the JS file 
itself), so you should put the /img folder inside the /static/js folder.
 

> b) cfg.pieceTheme = URL('static','img/chesspieces/wikipedia/{piece}.png'); 
> //and it fails also
>

Note, URL() is a Python function that works only on the server in the 
web2py environment -- you cannot insert it into a static JS file, which is 
executed entirely within the browser.
 

> The only way I found, so far, to display images is to use the absolute 
> path, see below, which looks like a really bad work around.
>
> cfg.pieceTheme = '
> http://127.0.0.1:8000/tablero/static/img/chesspieces/wikipedia/{piece}.png
> ';
>

If you want to keep the file in /static/img, you can still use a relative 
URL:

cfg.pieceTheme = '../img/chesspieces/wikipedia/{piece}.png 

';

The ../ will traverse from the /js folder up one level to the /static 
folder.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.