Re: Where to put Velocity Macros while providing an extension

Björn Berg <[email protected]> Sun, 31 Jan 2016 19:39:41 +0100
Newsgroups gmane.comp.java.roller.user
Message-ID <[email protected]>
Hi,

sorry for the late response but I was experimenting a little bit.
There is no need for an extension of Roller’s core. Any plugin can overwrite or extend the settings of the integrated Velocity engine:

protected void extendVelocityEngine(VelocityEngine engine) {
		log.info("adding additional resource loader: github");
		engine.addProperty(VelocityEngine.RESOURCE_LOADER, "github");
		engine.addProperty("github.resource.loader.class", ClasspathResourceLoader.class.getName());
		engine.addProperty("github.resource.loader.cache", false);
		engine.addProperty("github.resource.loader.path", ".");
		engine.addProperty(Velocity.VM_LIBRARY, "github.vm");
		log.info("restarting engine");
		engine.init();
}

If you do not init the engine again, the template providing a macro can be used with #parse in any template.

The whole example can be seen here:
https://github.com/rollinhand/roller-github-plugin/blob/master/src/main/java/org/kivio/roller/plugins/github/GitHubModel.java

I do not know, if this is wanted by the Roller developers but it works for me.

Regards,
Björn


> Am 25.01.2016 um 23:56 schrieb Kohei Nozaki <[email protected]>:
> 
> Hi Björn,
> 
> Oh I see, unfortunately I think it can't be achieved with current Roller.
> 
> Could you file it as a feature request to our issue tracker?
> https://issues.apache.org/jira/browse/ROL
> 
> Thanks.
> 
> On 1/25/16 02:11, Björn Berg wrote:
>> Hi,
>> 
>> I think I was not precise enough with my question. I know how to assemble my plugin and bring it to run inside Roller.
>> 
>> For more comfort in templates I want to provide Velocity macros (http://people.apache.org/~henning/velocity/html/ch07.html) with my plugin and was looking for a way how to make them available easily.
>> 
>> It seems that roller-custom.vm inside WEB-INF/velocity is the place to put custom Velocity macros but that would mean one has to edit macros itself and the cannot be automatically provided by the plugin. Is there some Classloader magic how this can be done?
>> 
>> Björn
>> 
>> 
>>> Am 24.01.2016 um 01:36 schrieb Kohei Nozaki <[email protected]>:
>>> 
>>> Hi Björn,
>>> 
>>> You can put your JAR file which contains your extension/plugin classes, into WEB-INF/lib inside your Roller deployment.
>>> 
>>> Don't forget to list FQCN of your custom classes in "rendering.pageModels" entry of roller-custom.properties.
>>> 
>>> Also this Ant script may help you making custom Roller WAR file which contains your additional extension/plugin JARs:
>>> https://github.com/lbtc-xxx/rollersetup
>>> 
>>> Hope this helps,
>>> 
>>> Kohei
>>> 
>>> On 1/24/16 01:36, Björn Berg wrote:
>>>> Hi,
>>>> 
>>>> I am writing my first extension/plugin of a PageModel for Apache Roller. This works very well.
>>>> 
>>>> But for a better convenience in page templates I want to provide Macros for the Velocity engine in my JAR file. Where do I have to put them and make them available so they can be used in Roller?
>>>> 
>>>> Kind regards,
>>>> Björn
>>>> 
>> 
>> Björn Berg
>> Mobil:	(0163) 699 23 74
>> E-Mail: 	[email protected]
>> 
>> 
>> 
>> 

Björn Berg
Mobil:	(0163) 699 23 74
E-Mail: 	[email protected]
signature.asc (application/pgp-signature, 496 B)
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQEcBAEBCgAGBQJWrlTuAAoJEOj6oZ1j/58NH9sH+gJYu2udeFTkj9T9GEb5EAky
fN+WpE4w3xLp1Mm9qSU/Rgjuzlc91MuQwQzpN+3M2scuUegN6QziWdovUNKdFlVX
bhJz16fex5B0v1041vqn+vviE5xz//xV24Q+KaCALK0kBDuOCAbGVle0gLdX1H82
O6VXgWoDa24OY+A70jBXb4mzEA5TqUSwjALWe5S0n5QIQ6TdC+31v41z0e0Z8IYm
ulB0HmHoKFdz+PUbl9MABY1oRzwUaeyUjTy7ffN73Y5GY9HOYE003HniKbl62K8p
KN4yt1M1s5w+nh7kWhlw+MOfCFu7m5bkCdW+Bd93Mc/tfOCNyghKcYhrE1p3Igs=
=kZWe
-----END PGP SIGNATURE-----