On Tue, Apr 24, 2012 at 11:45 AM, Jonathan Ballet <j...@multani.info> wrote:
> Hi,
>
> I'm using amCharts (a chart library written in Javascript, cf.
> http://www.amcharts.com/) in my application. I created a Fanstatic
package with the Javascript file, a CSS file and a few images.
I didn't know amcharts, looks very useful. Please consider sharing
your efforts by putting your package in pypi:
http://www.fanstatic.org/en/0.11.2/development.html#pre-packaged-libraries
> When I setup the Javascript library, I need to specify the path where
> the library will find the images such as:
>
> chart = new AmCharts.AmSerialChart();
> chart.pathToImages = "/images/amcharts";
>
> but this path obviously depends on how Fanstatic is configured. I'm
> currently passing quite a few values from Python to Javascript, so if I
> can find the value I should set here in Python, I can pass it back to
> the library, but I have no idea how to do that (if it ever possible?)
>
> Fanstatic is serving the images well if I enter the URL by myself (which
> is something like
> "/resources/amstock/:version:2012-04-24T15:26:05/images/" today.
> How can I find this path?
For every request, fanstatic creates a `NeededResources` object, which
contains the publication configuration options[1].
In your view code, you can access the `NeededResources` object using
fanstatic.get_needed():
>>> needed = fanstatic.get_needed()
In the `Injector`, the URLs are computed [2]. You can do the same
computation [3] in order to find the URL of a library in your view
code:
>>> # in case of js.jquery
>>> from js.jquery import library
>>> needed.library_url(library)
'/fanstatic/jquery/:version:1.6.1'
> Cheers,
>
> Jonathan
Cheers,
JJ
1) http://www.fanstatic.org/en/0.11.2/configuration.html
2) https://bitbucket.org/fanstatic/fanstatic/src/636ee4170bc3/fanstatic/injector.py#cl-44
3) https://bitbucket.org/fanstatic/fanstatic/src/636ee4170bc3/fanstatic/core.py#cl-817