forrest-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ross Gardler <rgard...@apache.org>
Subject Re: custom location for *.js
Date Sun, 11 Jun 2006 23:17:17 GMT
Dmitriy Kargapolov wrote:
> Hi,
> I'm trying to use some javascript in the forrest site, not for style 
> customizing but for some on-line demo.
> Using forrest 0.8 dev I found that per sitemap.xmap all "**.js" are 
> handled by resources.xmap, and resources.xmap has two cases:
> 1) all "**skin/**.js" are read from "{lm:skin.js.{2}}"
> 2) all "**.js" are taken from "resources/scripts/{1}.js"
> (It seems to be ${FORREST_HOME}/main/webapp/resources/scripts/ in real 
> life)

2) is an oversight in our move to locationmap resolution of resources (a 
0.8-dev feature). It should be resolved via the locationmap like all 
other resources. However, I notice that this match is marked as 
deprecated. I confess to having no idea what has replaced this 
deprecated item - that's a topic for the dev list if it worries you.

> I'd like to customize default location for non-skin javascript files.
> But I couldn't figure out source notation syntax used in map:read/@src 
> attributes. I couldn't fine any description on it.
> For example I'd like to set **.js location to
> src/documentation/content/xdocs/scripts in my doc site.
> What would be correct map:match and map:read syntax in that case?

For completelness I'll tell you what it is in 0.7, but then read on to 
see how to do it in the locationmap (since you are using 0.8-dev)

src/documentation/cpntent/xdocs = {project:content.xdocs}

So you would add the following match to your project sitemap:

<map:match pattern="**.js">
   <map:select type="resource-exists">
     <map:when test="{project:content.xdocs}/scripts/{1}.js">
       <map:read src="{project:content.xdocs}/scripts/{1}.js" 
mime-type="application/x-javascript" />
     </map:when>
     <map:otherwise>
       <map:read src="resources/scripts/{1}.js" 
mime-type="application/x-javascript" />
     </map:otherwise>
   </map:select>
</map:match>

Note, you need the resource-exists selector to ensure other scripts 
still work.

So that is 0.7 out of the way, but you say you are using 0.8-dev. So you 
have the wonderful locationmap at your disposal.

FIrst we need to change the resources.xmap to use the locationmap to 
resolve this resource (I've done this in SVN, so do "svn up", I copied 
the changes here so you can see what I did):

In the "**.js" match:

<map:read src="resources/scripts/{1}.js" 
mime-type="application/x-javascript" />

becomes:

<map:read src="{lm:project.js.{1}}" mime-type="application/x-javascript" />

Then I added the location to locationmap.xml:

<match pattern="project.js.**">
   <location src="resources/scripts/{1}.js" />
</match>

Now you need to provide an alternative location for the javascript. So 
create a locationmap.xml file in your project [1]. In your locationmap 
you provide the alternative location:

<match pattern="project.js.**">
   <select>
     <location src="{project:content.xdocs}scripts/{1}.js" />
   </select>
</match>

Note, because you have the <select> element it will fall back to the 
Forrest defined location if your JS is not found in the location you 
define. You can add as many possible locations as you need, and they 
need not be local to your other sources, see [1] for more.

Ross

[1] http://forrest.apache.org/docs_0_80/locationmap.html



Mime
View raw message