Hey Arndt, yeah, I've just tried to get your first suggestion working,
but I didn't manage to. It's a pity, because I think that approach
would have been very elegant! So, the API documentation for
request.static_url seems to be wrong? According to the API docs, you
can generate paths from relative URLs and not absolute URLS, but for
me it was just the other way round.

How are you supposed to specify relative URLs? When I try via:

{{ request.static_url("static/app.css") }}

the relative URL is interpreted as an asset within Jinja2 and I get
the error:

No static URL definition matching jinja2:static/app.css

Your 2nd approach would work. (haven't tried, but looks functional).
Although it blows up the code for including static files quite a
bit... finding a way with a relative asset specification would be
leaner.


On Jan 16, 5:15 pm, Arndt Droullier <a...@dvelectric.com> wrote:
> Maybe this wasn't such a good idea... Sorry.
> I've just reactived an older test version and it doesn't work. At least
> static_url() and relative paths don't work with the new pyramid
> version. ?
>
> However, additionally you can set the current static directory in the
> ini file
>
>     staticdirectory=myproject.staticbuild:
>
> and access it i the request as
>
>     request.registy.settings.staticdirectory
>
> Change your call to static_url() and add the var containing the module:
> <script
> src="{{request.static_url(request.registy.settings.staticdirectory
> +'static/js/application.js')}}"> type="text/javascript"></script>
>
> This should work now. This way you could even switch the directories at
> runtime.
>
> Arndt
>
> Am Montag, den 16.01.2012, 16:23 +0100 schrieb Arndt Droullier:
>
>
>
>
>
>
>
>
>
> > Hi,
>
> > if your application automatically finds "myproject:" in templates
> > (try {request.static_url('static/js/application.js')}) you could name
> > both directories "/static" and include them in different python
> > modules.
>
> > On startup register the one to be used (based on ini file settings or
> > whatever).
>
> > config.add_static_view('static', 'myproject.static:static',
> > cache_max_age=3600)
> >  or
> > config.add_static_view('static', 'myproject.staticbuild:static',
> > cache_max_age=3600)
>
> > In templates remove the prefix "myproject:" from static_urls:
> >   <script src="{{request.static_url('static/js/application.js')}}"
> > type="text/javascript"></script>
>
> > Maybe this approach works for you,
>
> > Arndt.
>
> > Am Montag, den 16.01.2012, 15:20 +0100 schrieb Gael Pasgrimaud:
> > > Hi!
>
> > > Not really an answer... and also a bit off topic. But are you aware of
> > > Fanstatic[1] ?
> > > I've wrote a pyramid_fanstatic package to use it as a pyramid tween[2]
> > > And a blog post about how to use lesscss with all that stuff[3]
>
> > > May be it can feet your needs...
>
> > > [1]http://www.fanstatic.org/en/0.11.2/index.html
> > > [2]http://pypi.python.org/pypi/pyramid_fanstatic
> > > [3]http://www.gawel.org/weblog/en/2011/12/Using_lesscss_with_pyramid_and...
>
> > > On Mon, Jan 16, 2012 at 3:08 PM, Marius Gedminas <mar...@gedmin.as> wrote:
> > > > On Mon, Jan 16, 2012 at 05:28:45AM -0800, Martin Stein wrote:
> > > >> For the current project at work, we are looking into using require.js
> > > >> (http://requirejs.org/) to combine, modularize and minify our
> > > >> javascript. So, basically, we need to have a server-side build step
> > > >> before serving our static files. Our plan is as follows:
>
> > > >> - have our pre-build javascript files in the usual '/static' directory
> > > >> - put the results from require's optimizer to a '/static-build'
> > > >> directory. (The require.js docs recommend a separate directory.)
>
> > > >> Depending on development or production scenario (taken from .ini-
> > > >> file), the static files should be served from one or the other
> > > >> directory. However, so far I don't see a nice approach to this. When
> > > >> we started the project, we used the normal Pyramid approach in our
> > > >> templates. In our __init__.py, we have something like:
>
> > > >> config.add_static_view('static', 'myproject:static',
> > > >> cache_max_age=3600)
>
> > > >> In the jinja-template, we created the links with
>
> > > >> <script src="{{request.static_url('myproject:static/js/
> > > >> application.js')}}" type="text/javascript"></script>
>
> > > >> But if the directory changes from 'static' to 'static-build', we would
> > > >> have to change all our static_url(..) calls. Is there a way to make
> > > >> the resource 'myproject:static' refer to a different directory,
> > > >> depending on .ini configuration?
>
> > > >> One approach would be to read the resource directory from the .ini
> > > >> file and add the static view like this:
>
> > > >> config.add_static_view('static', RESOURCE_FROM_INI,
> > > >> cache_max_age=3600)
>
> > > >> Then, you could refer to the files like this:
>
> > > >> <script src="{{ request.script_name }}/js/application.js'" type="text/
> > > >> javascript"></script>
>
> > > > I think {{ request.application_url }}/js/application.js is more
> > > > appropriate here.
>
> > > >> (note that you need the 'script_name', because on the production
> > > >> server your application might be deployed under a URL prefix). But the
> > > >> 'request.script_name' approach looks kind of hacky to me and it means
> > > >> we'd have to replace all our static_url(..)-calls. Do you see another
> > > >> way to do this elegantly?
>
> > > >> The trend for larger javascript-heavy apps seems to be going towards
> > > >> require.js, so I think a nice solution for this problem will be
> > > >> interesting for lots of people.
>
> > > > /me is listening with interest
>
> > > > Marius Gedminas
> > > > --
> > > > Colorless green ideas sleep furiously.
>
> > --
>
> > _______________________________________________________________________
>
> > DV Electric
> > Arndt Droullier
> > Mail a...@dvelectric.com
> > Fon 0221/2725782
> > Fax 0221/2725783
> > Burgmauer 20, 50667 Köln
> >http://www.dvelectric.com
> > _______________________________________________________________________
>
> --
>
> _______________________________________________________________________
>
> DV Electric
> Arndt Droullier
> Mail a...@dvelectric.com
> Fon 0221/2725782
> Fax 0221/2725783
> Burgmauer 20, 50667 Kölnhttp://www.dvelectric.com
> _______________________________________________________________________

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to