<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Grails Rocks &#187; plugin</title>
	<atom:link href="http://www.anyware.co.uk/2005/tag/plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anyware.co.uk/2005</link>
	<description>Grails, Apple, usability and world stuff</description>
	<lastBuildDate>Fri, 27 Jan 2012 13:52:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Resources 1.1(.1) plugin released</title>
		<link>http://www.anyware.co.uk/2005/2011/10/21/resources-1-1-1-plugin-released/</link>
		<comments>http://www.anyware.co.uk/2005/2011/10/21/resources-1-1-1-plugin-released/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 00:31:07 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugin release]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=1094</guid>
		<description><![CDATA[After a frantic 12 hours or so of coding and debugging, I managed to release version 1.1.1 of the Resources plugin for Grails today. It was meant to be 1.1 but there was a bug that needed fixing immediately after releasing so 1.1.1 is where we&#8217;re at. This version is tested with Grails 1.3.7 and [...]]]></description>
			<content:encoded><![CDATA[<p>After a frantic 12 hours or so of coding and debugging, I managed to release version 1.1.1 of the <a href="http://grails.org/plugin/resources">Resources plugin</a> for <a href="http://grails.org">Grails</a> today.</p>
<p>It was meant to be 1.1 but there was a bug that needed fixing immediately after releasing so 1.1.1 is where we&#8217;re at. This version is tested with Grails 1.3.7 and Grails 2.0 RC1 which is set to drop this weekend.</p>
<p>What&#8217;s new in this release of Resources?</p>
<p>Well aside from some useful bug fixes there&#8217;s a few interesting changes:</p>
<ol>
<li>If you forget to include r:layoutResources tags, you will get an error in the console. The error may or may not display in the browser currently depending on whether you used site mesh layouts or not. We may be able to improve this in future. This means that people who wondered where their JS code was disappearing to after installing Resources into a 2.0 app will now get an error telling them that they need to add r:layoutResources.</li>
<li>There is now support for laying out arbitrary dispositions by passing a &#8220;disposition&#8221; to the r:layoutResources tag. This means you can position sets of resources wherever you like in the output, using multiple dispositions. Currently this is only relevant for JavaScript but in future we should be able to support images so that you can e.g. have a bunch of &#8220;preloaded&#8221; images that are hidden in the page somewhere.</li>
<li>The integration with Grails 2.0 has been &#8220;finalized&#8221; now. The ResourceService has changed to a &#8220;grailsResourceProcessor&#8221; bean, and all g:javascript invocations result in called to r:require or r:script as necessary. The default layouts in 2.0 now use layoutResources and a default &#8220;application&#8221; module exists in new projects.</li>
</ol>
<p>There are still some outstanding important bugs that I will endeavour to fix soon, as well as improving the error reporting on all fronts.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2011/10/21/resources-1-1-1-plugin-released/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Optimising your Application with Grails Resources Plugin</title>
		<link>http://www.anyware.co.uk/2005/2011/09/12/optimising-your-application-with-grails-resources-plugin/</link>
		<comments>http://www.anyware.co.uk/2005/2011/09/12/optimising-your-application-with-grails-resources-plugin/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 20:16:04 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=906</guid>
		<description><![CDATA[It&#8217;s been nearly a year since we first announced the Resources framework for Grails. It&#8217;s about time we looked at some of the more advanced features that it provides so that you can make the most of this very powerful plugin. The start of this article will go over some of the basics again, as [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been nearly a year since we first announced the <a href="http://grails.org/plugin/resources">Resources framework</a> for <a href="http://grails.org">Grails</a>. It&#8217;s about time we looked at some of the more advanced features that it provides so that you can make the most of this very powerful plugin.</p>
<p><span id="more-906"></span>The start of this article will go over some of the basics again, as they are a prerequisite for understanding the more advance topics covered later in the piece.</p>
<h2>Recap: What is Resources framework for?</h2>
<p style="text-align: center;"><a class="lightbox" href="http://www.anyware.co.uk/2005/wp-content/uploads/2011/09/Resources-article-diagram.png?9d7bd4"><img class="size-full wp-image-968 aligncenter" title="Resources article diagram" src="http://www.anyware.co.uk/2005/wp-content/uploads/2011/09/Resources-article-diagram.png?9d7bd4" alt="" width="464" height="216" /></a></p>
<p>It solves the growing problems around application and plugin static resources. Your CSS, JS and other files have dependencies on each other, and must load in the correct order. You also want to optimize these so that your application loads quickly and caches well for your users.</p>
<p>It provides a way to declare your resources, their dependencies, and a processing chain to modify the resources and response headers to perform all manner of tasks such as bundling multiple resource files into one file, zipping the response, applying long-term client-side caching, or compiling Less or Sass files to regular CSS on the fly.</p>
<h2>Where do I start?</h2>
<p>First you install the &#8220;<a href="http://grails.org/plugin/resources">resources</a>&#8221; plugin. To actually see some magic happening you probably want to also install the <a href="http://grails.org/plugin/cached-resources">cached-resources</a> and/or <a href="http://grails.org/plugin/zipped-resources">zipped-resources</a> plugins also, but this is not a requirement.</p>
<p>Then you declare some resources in your app, or pull some in from a plugin that supports Resources. Let&#8217;s start by declaring a resource that exists in your application, say main.css. To do this you create a file in <strong>grails-app/conf/</strong> with a name that ends in &#8220;<strong>Resources.groovy</strong>&#8220;. So we might create <strong>AppResources.groovy</strong> and use the DSL to declare the resource:</p>
<script src="https://gist.github.com/1211514.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211514">Gist</a>.</p></noscript>
<p>This is a module declaration. For full details see the <a href="http://grails-plugins.github.com/grails-resources">Resources documentation</a>, but in essence this declares a resource module called &#8220;common&#8221; and it has one CSS resource in it, the file supplied by your application in <strong>web-app/css/main.css</strong>, and on JS file.</p>
<p>So far, so good. Now you need to pull this resource into a page. To do this requires using some Resources tags.</p>
<h2>Using resources in your pages</h2>
<p>There are two main tags involved in using resources, with some others that provide extra features. The main two are <strong>r:require</strong> and <strong>r:layoutResources</strong>.</p>
<p>The <strong>r:require</strong> tag tells the framework which resource modules the current GSP requires. The framework will make sure that all the resources declared in those modules are pulled in in the correct order.</p>
<p>To achieve this, you need to include <strong>r:layoutResources</strong> tags in your &lt;head&gt; and &lt;body&gt; sections. Typically you do this in your SiteMesh layout. You use two calls because one will render the resources that you need to link to in the &lt;head&gt; section of your page (all your CSS, and some of your JavaScript, maybe some favico or iPhone icons). The other goes at the end of the &lt;body&gt; of your page, to render any &#8220;deferred&#8221; resources, which is usually just your JavaScript code.</p>
<p>So here&#8217;s an example of a Grails Sitemesh layout using these tags:</p>
<script src="https://gist.github.com/1211550.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211550">Gist</a>.</p></noscript>
<p>Here you see that you still use the normal Grails sitemesh tags to layout the head and body. These provide the route for you GSP page to actually affect the output, including the output of the Resources plugin&#8217;s <strong>r:layoutResources</strong> tags. That&#8217;s because your GSP will call <strong>r:require</strong> and <strong>r:script</strong> tags something like this:</p>
<script src="https://gist.github.com/1211555.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211555">Gist</a>.</p></noscript>
<p>This GSP is set to use a Sitemesh layout like the example one given earlier. It uses the <strong>r:require</strong> tag to say that this page needs the &#8220;app&#8221; resource module. Using this information, the <strong>r:layoutResources</strong> tags will render links to all the CSS, JS and other resources of that &#8220;common&#8221; module, in the correct places.</p>
<p>This means that some may end up in head, and some may end up in body. Remember that we invoked <strong>r:layoutResources</strong> twice, once in each location? Well, that&#8217;s why.</p>
<h2>What is this &#8220;disposition&#8221; stuff?</h2>
<p>The disposition of a resource tells the framework which part of the page it belongs &#8211; its a form of arbitrary grouping. The default dispositions supported are &#8220;head&#8221; and &#8220;defer&#8221; but in fact resources can define any disposition they like &#8211; and this can be useful for declaring resources that are not rendered by the normal layoutResources calls (more about this later).</p>
<p>The framework applies a default disposition based on the type of the resource &#8211; so CSS always defaults to &#8220;head&#8221; but JavaScript always defaults to &#8220;defer&#8221;, so that it runs only when the rest of the page has loaded. Images and icons are also supported to represent favicon and iPhone icons, which render in &#8220;head&#8221;.</p>
<p>Resource modules usually contain multiple resources and the main reason to specify a disposition when declaring a resource is to force JavaScript to load in the &lt;head&gt; section of the page. To achieve that you just update your resource declaration to include a &#8220;disposition&#8221; attribute:</p>
<script src="https://gist.github.com/1211561.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211561">Gist</a>.</p></noscript>
<p>Now your page will load with jQuery in the head section, with no code changes to your layout or GSP!</p>
<h2>Dependencies</h2>
<p>So far, so good but how do we control the order of resources when they are pulled into the page? How can I make sure that my application JS or CSS code always loads after the JS and CSS from a plugin that I&#8217;m using?</p>
<p>This is where Resources dependencies come in. There are two simple rules</p>
<ol>
<li>Resources from a given module are loaded in the order they are defined in the module</li>
<li>Resources from modules are loaded in module dependency order</li>
</ol>
<p>The first rule ensures that when you declare resources you can intuitively see which CSS or JS loads before another.</p>
<p>The second rule uses the &#8220;dependsOn&#8221; method in module declarations to list the names of other resource modules on which the module depends. Those will always be loaded before the module that depends on them. Here&#8217;s an example declaration that alters our specimen module to depend on the jQuery plugin&#8217;s query module instead, and jQuery UI:</p>
<script src="https://gist.github.com/1211581.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211581">Gist</a>.</p></noscript>
<p>Notice that we have specified both jQuery UI and jQuery in the dependsOn. We don&#8217;t need to. However notice that they are also declared in the &#8220;wrong&#8221; order. This is to illustrate that the order you use here is not important &#8211; the &#8216;jquery-ui&#8217; module declared by the Grails jQueryUI plugin depends on on &#8216;jquery&#8217; (provided by the Grails jQuery plugin) as well &#8211; so it will always make sure that is loaded first.</p>
<p>As your application does not define those two modules, you would need to install the Grails jQuery-UI plugin &#8211; or define them yourself. Including the jQuery-UI plugin automatically pulls in the jQuery plugin for you, because of Grails&#8217; transitive plugin dependencies. TheResources framework was designed to work hand in hand with the other Grails dependency mechanisms.</p>
<p>So now you have done this, you still have no changes to make to your GSP! It still just requires the &#8220;common&#8221; module. Notice how this has decoupled your GSPs and layouts from the details of the resources that they need. This is an important feature that gives you great scope to modularise your resources, and even have page-specific modules if you like that contain nothing other than dependencies themselves:</p>
<script src="https://gist.github.com/1211564.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211564">Gist</a>.</p></noscript>
<p>With this, an edit.gsp could just <strong>r:require</strong> the &#8220;editPage&#8221; module and never care about the explicit details of what is required.</p>
<h2>Dealing with your ugly inline Javascript</h2>
<p>You already know that inline Javascript is pretty horrendous, but some things are just plain shameful and yet we can&#8217;t help ourselves. Frequently you want to write a Grails taglib that simplifies using a JS library and to do that it must render some code inline when the tag is invoked.</p>
<p>With Resources you can trivially throw this JS code around to wherever you like. You can have the code render in &lt;head&gt; or at the end of the body, and it will automatically do so after loading the resources that the page depends on. To do this you just use the &lt;<strong>r:script</strong>&gt; tag instead of a normal &lt;script&gt; or &lt;g:javascript&gt; tag:</p>
<script src="https://gist.github.com/1211607.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211607">Gist</a>.</p></noscript>
<p>In this example the script code specified in &lt;head&gt; <em>does not run immediately</em>. The <strong>r:script</strong> tag also uses &#8220;disposition&#8221; and the default is &#8220;defer&#8221; so you will find that the alert only pops up once the rest of the page has loaded, and the HTML source will show the &lt;script&gt; tag at the end of the body, after all other deferred JS code has been pulled in.</p>
<p>All such fragments in the same disposition are concatenated together, so you don&#8217;t get a long list of &lt;script&gt; tags.</p>
<p>To force a fragment of inline JS to execute in &lt;head&gt;, just add <strong>disposition=&#8221;head&#8221;</strong> to the <strong>r:script</strong> tag invocation.</p>
<p>To write your own taglibs that generate code in this way, you just output the result of calling the <strong>r.script(attrs, Closure)</strong> tag from your tag.</p>
<h2>Linking to images</h2>
<p>Images often need to be optimised or set for long-term caching. However you don&#8217;t normally need to declare them in modules. To render images correctly you should use the <strong>&lt;r:img&gt;</strong> tag anywhere in your pages as you would and HTML &lt;img&gt; tag. All you do differently is supply a uri or dir/file attribute to tell it where to load from. Other attributes are passed through:</p>
<script src="https://gist.github.com/1211623.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211623">Gist</a>.</p></noscript>
<p>That&#8217;s all there is to it.</p>
<p>There are however some extra tricks you can pull. Any tag attributes specified in a module resource declaration are honoured when rendering the link. As such this means that you can specify your width &amp; height values if you declare your image &#8211; and never have to specify them when rendering links:</p>
<script src="https://gist.github.com/1211626.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211626">Gist</a>.</p></noscript>
<p>Now any <strong>r:img</strong> links to that logo will automatically include those attributes in the output. Notice that we had to include the disposition &#8220;image&#8221; which is not a predefined disposition &#8211; it is just anything other than &#8220;head&#8221; or &#8220;defer&#8221; to prevent the image being rendered by the <strong>r:layoutResources</strong> tags.</p>
<h2>Bundling: combining files to reduce the number of requests</h2>
<p>Page load time is a combination of many factors. Those that you can control from your application itself include how many requests are needed to load your page and whether you load resource before or after your HTML content.</p>
<p>To reduce the number of requests made, you need to combine one or more resources into a single file. This is called bundling and what you do is tell Resource which files can be bundled together. This is usually dependent on how your application uses the code, and inevitably requires some compromise.</p>
<p>For example you <em>could</em> bundle all your resources into one file across your entire app &#8211; resulting in just one CSS and one JS file for the entire site. With aggressive browser caching this could yield good results, but if you have a few hundred KB of code in these files it could mean it takes a long time for people to see your site the first time they visit or empty their cache.</p>
<p>To specify the bundle that a file belongs to, just add the &#8220;bundle&#8221; attribute to resource declarations. The Resources framework will not bundle together resources that are incompatible: different content types, or those with differing &#8220;attrs&#8221;. For example CSS with <strong>media=&#8217;print&#8217;</strong> will not be bundled with screen media.</p>
<p>It does however allow you to bundle resources <em>across module boundaries</em>. This is important as you will see shortly. It also automatically bundles using the module name by default, and maintains separate bundled files for head and defer dispositions automatically.</p>
<p>That is a lot to take in, but it basically means you don&#8217;t need to worry about anything.</p>
<p>Just set the bundle attribute:</p>
<script src="https://gist.github.com/1211629.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211629">Gist</a>.</p></noscript>
<p>Here the <strong>main.css</strong>, which previously might have auto-bundled into bundle &#8220;common&#8221; if there was more than one resource in the module, will now be bundled into bundle &#8220;core&#8221;.</p>
<p>The difference has no effect for now, but what you can do is override the module declarations that came from the jQuery plugins and make them go into the same bundle. To do this we use the &#8220;overrides&#8221; mechanism to change the properties of the resource modules supplied by the plugins. We can call the <strong>defaultBundle</strong> method to change the default used by them:</p>
<script src="https://gist.github.com/1211633.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211633">Gist</a>.</p></noscript>
<p>Now all the modules will throw their resources together, and you will find your page (again with zero GSP changes) is now pulling in just three files: bundle_core_head.js, bundle_core_head.css and bundle_core_defer.js</p>
<p><span class="Apple-style-span" style="font-size: 20px; font-weight: bold;">Changing how links to resources are rendered</span></p>
<p>Under the hood, the <strong>r:layoutResources</strong> tag uses the <strong>r:external</strong> tag to render links. The <strong>r:external</strong> tag is a smart tag that writes out the &#8220;right kind&#8221; of link for a resource. So for JS files it renders &lt;script src=&#8230;&gt; tags, for CSS it renders &lt;link href=&#8230;&gt;, and so on for favicons and a few other types.</p>
<p>The key thing is that you can pass any other attributes to <strong>r:external</strong> and they will pass through to the output. It so happens that <strong>r:layoutResources</strong> pass the &#8220;attrs&#8221; Map defined in your resource declaration when calling <strong>r:external</strong> for that resource. This means you can pass any extra attributes you like to the declaration and they make it to the output.</p>
<p>A typical usage for this is to specify media:&#8217;print&#8217; on a CSS resource, because the default for this is &#8220;screen, projection&#8221;:</p>
<script src="https://gist.github.com/1211639.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211639">Gist</a>.</p></noscript>
<p>Note that if you specify these extra properties, those files will not be bundled with others, as by definition this isn&#8217;t going to work out well for you.</p>
<h2>Wrapping the link in some other code. AKA MS IE workarounds</h2>
<p>The resource declaration can also supply some wrapper markup that is used to render the link, with the generated link being passed in as a string. You normally use this to wrap a resource such that it is commented out for all browsers except MS IE:</p>
<script src="https://gist.github.com/1211648.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211648">Gist</a>.</p></noscript>
<p>The wrapper Closure is passed the link text as an argument. You are then free to pre/post-fix it with anything you like.</p>
<h2>Linking to specific resources without using the dependency mechanisms</h2>
<p>On occasion you may need to link directly to a resource that is handled by the framework, without using <strong>r:layoutResources</strong> or <strong>r:require</strong>.</p>
<p>To do this you can use <strong>r:resource</strong> to get the URL of a resource, or <strong>r:external</strong> to create a link to it. You can use these to generate absolute links to those resources, for example in an HTML email.</p>
<p>These tags accept the regular uri, url or plugin/file/dir attributes. The <strong>r:external</strong> tag also supports a &#8220;type&#8221; attribute to give it a clue what kind of link to render if it is not obvious from the file extension.</p>
<h2>Overriding resources from plugins</h2>
<p>Plugins that expose modules normally do the right thing, but sometimes you might need to supply different content for a given file, or change some of the tag attributes or the bundle used. To do this you use the overrides mechanism shown earlier in the <strong>defaultBundle</strong> example.</p>
<p>The &#8220;overrides&#8221; closure lets you specify new values for some of the module defaults for a given module, but also lets you tweak individual resources if they can be addressed uniquely. Developers must add an &#8220;id&#8221; attribute to the resource when it is declared for this to work:</p>
<script src="https://gist.github.com/1211650.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211650">Gist</a>.</p></noscript>
<p>This changes the bundle on just the resources with id &#8220;js&#8221; in the original jquery module. There might be one or more resources with that id in the module. Resources in other modules are unaffected.</p>
<p>For full details of what you can override, please see the <a href="http://grails-plugins.github.com/grails-resources">Resources plugin documentation</a>.</p>
<h2>Using r:require in GSP fragments</h2>
<p>Using g:render to render GSP templates to build up your pages is a powerful technique. What you may not have realised is that you can completely modularise these templates now because the enclosing GSP no longer needs to know what libraries they need.</p>
<p>Yes, you can call <strong>r:require</strong> at any time in GSP rendering &#8211; including inside nested GSP templates &#8211; and the dependencies of your code will be stored along with your request and the resources all tallied up when the <strong>r:layoutResources</strong> called in your Sitemesh layout execute.</p>
<p>The only pre-requisite is that your <strong>r:require</strong> must be invoked before the corresponding <strong>r:layoutResources</strong> that you&#8217;d like to use to render it.</p>
<p>Picture how easy it is now to create portlet-like user interfaces where only the resources needed by UI elements displayed to the user will be loaded, and when they are they will be optimised. The portlets they have not installed or disabled will not load their resources if you do not render their GSP template.</p>
<h2>Dynamic requirements</h2>
<p>It is important to realise that the <strong>r:require</strong> tag can support normal GSP EL values in the modules list attribute. This brings great power because you can change the code pulled in by a page at runtime. For example you can make yourself a trivial per-user theme-switching system by storing the name of the theme they want to use in the session, and using a tag like this:</p>
<script src="https://gist.github.com/1211652.js"></script><noscript><p>View the code on <a href="https://gist.github.com/1211652">Gist</a>.</p></noscript>
<p>This will locate the theme module and all its dependencies with no further coding.</p>
<p>You could even switch the entire JS library and supporting code used by your plugin&#8217;s UI so that, for example, the user could choose between jQuery UI or YUI, or their own implementation.</p>
<h2>Including common resources in your layout</h2>
<p>Most likely you have some resources that are used in all pages using your Sitemesh layout. This is no problem because you can call <strong>r:require</strong> inside your Sitemesh layout, with the same proviso as &#8220;Using <strong>r:require</strong> in GSP fragments&#8221; &#8211; they must be invoked before the <strong>r:layoutResources</strong> call that would render them.</p>
<p>This means that in practice your individual GSP pages are likely to have only one or two module requirements as the rest is handled by the Sitemesh layout.</p>
<h2>Patterns for plugin authors</h2>
<p>Here are a few emerging patterns for plugin developers to heed when supporting the resources plugin.</p>
<ul>
<li>Specify id attributes on your resources when declaring them, to maximise the user&#8217;s opportunity to override specific details</li>
<li>Avoid monolithic modules, opting were possible to separate out functional areas such as the jQuery UI theme being separate from the jQuery UI code. This gives developers more flexibility. Obviously you must maintain correct dependencies between these</li>
<li>Put &#8220;development&#8221; un-minified versions of resources in &#8220;&lt;yourmodulename&gt;-dev&#8221; modules, so the user can pull in un-minified versions on demand, per-environment if they wish</li>
<li>Do not specify the bundling of your modules &#8211; at most use defaultBundle. No per-resource bundle attributes. Let the developer control this easily by overriding your defaultBundle settings in each module.</li>
<li>Use module names prefixed with the name of your plugin followed by a hyphen i.e. &#8220;jquery-main&#8221;, &#8220;myplugin-theme&#8221;, &#8220;acmeplugin-ui-styling&#8221;</li>
</ul>
<h2>Summing up</h2>
<p>All the things we&#8217;ve tackled here are core <a href="http://grails.org/plugin/resources">Resources</a> framework features &#8211; no extra plugins are required. The resource mapper that performs bundling is even built into the framework.</p>
<p>The real fun starts when you install some of the other mapper plugins &#8211; they may be renamed, re-encoded or even compiled from one form into another. It all happens at startup for declared resources, and at runtime for ad-hoc resources. Once it&#8217;s been done it is stored on disk on the server in that state and no more processing is done.</p>
<p>I hope you have fun with the Resources framework!</p>
<p>There are some nice refinements and maybe some new features coming in point releases at the time of writing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2011/09/12/optimising-your-application-with-grails-resources-plugin/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>How we use Weceem CMS at NoticeLocal</title>
		<link>http://www.anyware.co.uk/2005/2011/02/15/how-we-use-weceem-cms-at-noticelocal/</link>
		<comments>http://www.anyware.co.uk/2005/2011/02/15/how-we-use-weceem-cms-at-noticelocal/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 21:24:01 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[noticelocal]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[startup]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=782</guid>
		<description><![CDATA[We have an online notice boards startup called NoticeLocal that we&#8217;ve written with Grails. In my experience over the years it became obvious that one of the major pain-points of using Java to deploy web apps is the hassle of updating a bit of content here or there, replacing an image &#8211; those kinds of [...]]]></description>
			<content:encoded><![CDATA[<p>We have an <a href="http://noticelocal.com">online notice boards startup called NoticeLocal</a> that we&#8217;ve written with <a href="http://grails.org">Grails</a>.</p>
<p>In my experience over the years it became obvious that one of the major pain-points of using Java to deploy web apps is the hassle of updating a bit of content here or there, replacing an image &#8211; those kinds of things that should be simple but aren&#8217;t. Also a lot of the time this stuff is not subject to the same strict versioning processes that we are using for our code.</p>
<p>As you may know I am paid to work on the <a href="http://weceem.org">Weceem CMS plugin</a> and application, that is also Grails based.</p>
<p>For NoticeLocal I decided that it would suit us well to use an instance of Weceem CMS running on one Tomcat, to supply the marketing/PR site for the service, as well as the multi-language content for UI elements in the main application.</p>
<p>It turned out this was really easy to do, even though Weceem currently has no API to speak of.</p>
<p>To do this we:</p>
<ol>
<li>Have a vanilla WeceemApp WAR running in one Tomcat instance</li>
<li>Have our NoticeLocal application WAR running in another Tomcat instance</li>
<li>Wrote a trivial taglib in the NoticeLocal application to retrieve content nodes from the CMS instance using vanilla HTTP requests to URLs with a predefined prefix, and stores the text them in a local ehcache.</li>
</ol>
<p>So, in Weceem we have a bunch of HTML content nodes that represent different elements of the main NoticeLocal app&#8217;s UI &#8211; we have several different Weceem templates that these different nodes use &#8211; e.g. one for side panels, one for full page content (but laid out inside the main NoticeLocal app sitemesh layout, and one for inline UI messages such as those shown on demand when the user performs some action.</p>
<p>So in our NoticeLocal application we use our taglib to render a &#8220;remote CMS message&#8221; in our pages using the not-so-well-known Grails/SiteMesh g:applyLayout tag that, just like Grails layouts, will parse out the body of the content that we&#8217;ve cached, and render it in situ.</p>
<p>Oh, and for bonus points we use a simple regex replace to give us GSP-like variable expansion when rendering the content from the local cache, so we can perform variable substitutions like ${userName} &#8211; so you can write that in a HTML node in Weceem, and by the time the NoticeLocal app renders it, it has your name in it.</p>
<p>At any point we can log into the CMS, update some UI message, and when the cache expires the users see the new updated stuff. No app redeploys.</p>
<p>Oh, and because its in a CMS we solve the hard problem &#8211; i18n translations of rich content with styling, images etc.</p>
<p>In a nutshell, it&#8217;s great!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2011/02/15/how-we-use-weceem-cms-at-noticelocal/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Bean-Fields plugin 0.6 released</title>
		<link>http://www.anyware.co.uk/2005/2010/03/13/bean-fields-plugin-0-6-released/</link>
		<comments>http://www.anyware.co.uk/2005/2010/03/13/bean-fields-plugin-0-6-released/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 19:40:20 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugin release]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=701</guid>
		<description><![CDATA[I have released Bean-Fields plugin 0.6. This extremely handy plugin for Grails applications makes your data form GSPs DRY by centralizing the rendering and styling of your fields, handling &#60;label&#62; rendering, rendering appropriate HTML field based on property type, application of HTML max length constraints, rendering &#8220;required field&#8221; indicators, and rendering per-field errors. Rendering a [...]]]></description>
			<content:encoded><![CDATA[<p>I have released <a href="http://grails.org/plugin/bean-fields">Bean-Fields plugin</a> 0.6. This extremely handy plugin for <a href="http://grails.org">Grails</a> applications makes your data form GSPs DRY by centralizing the rendering and styling of your fields, handling &lt;label&gt; rendering, rendering appropriate HTML field based on property type, application of HTML max length constraints, rendering &#8220;required field&#8221; indicators, and rendering per-field errors. Rendering a whole bean&#8217;s worth of fields can be as simple as:</p>
<pre lang="jsp">&lt;bean:form beanName="book" properties="title, primaryAuthor.name, isbn"/&gt;</pre>
<p>Version 0.6 fixes a bunch of bugs related to rendering fields for nested property paths e.g. propertyName=&#8221;book.author.firstName&#8221; and introduces support for list / array properties eg &#8220;book.authors[3].firstName&#8221; (This was really quite painful to implement!). Radio groups are working properly now, and test coverage much improved &#8211; thanks to contribs from Antony Stubbs.</p>
<p>It also adds a user-definable threshold for whether a radio group or select list should be used for a field with an inList constraint.</p>
<p><a href="http://jira.codehaus.org/secure/IssueNavigator.jspa?reset=true&amp;jqlQuery=project+%3D+GRAILSPLUGINS+AND+fixVersion+%3D+%22Grails-BeanFields-0.6%22+ORDER+BY+updated+DESC%2C+priority+DESC%2C+created+ASC&amp;mode=hide">Full list of resolved issues is here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2010/03/13/bean-fields-plugin-0-6-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Weceem 0.8 Released &#8211; Highlights and background</title>
		<link>http://www.anyware.co.uk/2005/2010/01/12/weceem-0-8-released-highlights-and-background/</link>
		<comments>http://www.anyware.co.uk/2005/2010/01/12/weceem-0-8-released-highlights-and-background/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 14:01:02 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[weceem]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=670</guid>
		<description><![CDATA[I&#8217;ve just managed to push out version 0.8 of the Weceem CMS for Grails. This is a pretty cool if slightly unglamourous release because it has focussed on some performance and security stuff &#8211; oh and compatibility with the latest and greatest Grails 1.2.0 release. Let me first apologise for the ropey typography on weceem.org [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just managed to push out version <a href="http://weceem.org">0.8 of the Weceem CMS</a> for Grails.</p>
<p>This is a pretty cool if slightly unglamourous release because it has focussed on some performance and security stuff &#8211; oh and compatibility with the <a href="http://grails.org">latest and greatest Grails 1.2.0 release</a>.</p>
<p>Let me first apologise for the ropey typography on weceem.org &#8211; we haven&#8217;t yet had the time/resources to fix up the CSS styles so things are a little ugly in places. We will fix it as soon as we get time!</p>
<p>Anyway, we added a security policy. This is a groovy script (currently only loaded once at startup) that lets you define what different users can do. This uses a DSL that lets you declare roles and then say what they can do in different spaces, including whether they can admin the space, edit/view/delete/create content, and even do this by URI requested. (<a href="http://www.weceem.org/weceem/Documentation/Reference-manual/Security-Authorisation">see more info and example here</a>)</p>
<p>Because we believe strongly that Weceem should not force you to use a particular authentication library, we had to decouple the policy mechanism from authentication. As a result these roles are completely uninterpreted by Weceem. To integrate and authentication system all you have to be able to do is provide the name, email, login and list of roles for the currently logged-in user. (<a href="http://www.weceem.org/weceem/Documentation/Reference-manual/Security-Custom-Authentication">an example here</a>)</p>
<p>This has enabled some cool stuff in <a href="http://fisheye.codehaus.org/browse/grails-plugins/grails-weceem/tags/RELEASE_0_8/grails-app/services/org/weceem/services/WeceemSecurityService.groovy?r=HEAD">WeceemSecurityService</a> which relies on the security policy. The service has utility methods for implementing our security logic, e.g. isUserAllowedToViewContent(Content c). For example in previous versions of Weceem you could not preview content if it was not in a publicContent status (eg not Published).</p>
<p>Thankfully from version 0.8, anybody who has the EDIT permission can view non-published content. the default security policy ensures that the default administrator account has EDIT permission, so you can preview away as much as you like. We plan future updates to this to allow the security policy to control who can manipulate different types of content, which will be really powerful for people using custom content types.</p>
<p>On the performance front, it became obvious that something needed to be done because the default &#8220;index&#8221; page installed by <a href="http://weceem.org">Weceem</a> into new spaces was resulting in huge amounts of SQL queries for a single page.</p>
<p>This is because the page is made up like this:</p>
<ul>
<li>It pulls in a Template node for the styling</li>
<li>It pulls in three Widgets for reusable HEAD section tags and header and footer</li>
<li>The header widget iterates over all root content nodes and their children to render the menu with the wcm:menu tag</li>
<li>The page itself links to various StyleSheet and JavaScript nodes to pull in styling and scripts &#8211; these are processed on separate requests but still add to the overall burden of the page</li>
</ul>
<p>This can result in a lot of SQL chatter because we have (rightly so) made no effort to optimize this until now.</p>
<p>There are a couple of areas here that would make a big difference to the SQL traffic.</p>
<p>It is very important to realise that turning on the 2nd level cache in your Grails app&#8217;s GORM configuration does not magically give you major performance improvements. My understanding of this rather complex area (which frankly I found very disappointing) is:</p>
<ul>
<li>The 2nd level cache is only used for retrieval by object id. This is very important</li>
<li>The query caches are used to cache the ids of objects returned for a given query</li>
<li>Query caches are invalidated frequently by Hibernate if your model is not primarily read-only (<a href="http://tech.puredanger.com/2009/07/10/hibernate-query-cache/">and can cause some threading contention</a>)</li>
</ul>
<p>Luckily a CMS is pretty read-only in terms of number of requests that actually read vs update content, so the 2nd level cache is a good candidate for us here.</p>
<p>One of the major SQL hits for Weceem is resolving a URI to the ultimate content node to render. Due to the model we need to query for each part of the URI, so a request for /a/b/c results in three selects. So that&#8217;s an easy one &#8211; we added URI path -&gt; content id caching (and some other smarts) into the ContentRepositoryService. So once content has been hit, it will always be retrieved by id in future, via the 2nd level cache.</p>
<p>Another issue is iterating over child nodes. This is less trivial. We are using some query caching but I have noticed that some of the criteria were not hitting the caches despite this &#8211; it needs further investigation. I think that due to the polymorphic nature of the content model and query cache invalidation issues, we may stop using these in future (think blog comments being submitted and invalidating ALL your caches).</p>
<p>Next up: Template and Widget nodes are GSP pages that we compile and evaluate. It turned out that due to issues in Grails GSP handling (that persist in 1.2 to my knowledge), there is no internal caching of compiled GSP classes built from non-Resource content e.g. strings. This results in a leak of PermGen space which ultimately results in VM collapse. So we now have a simple cache of compiled Template and Widget GSP pages, which is automatically invalidated as necessary when templates and widgets are edited, so it is transparent to the end user that there is a cache.</p>
<p>Finally with regard to performance, we introduced a nice simple <a href="http://www.weceem.org/weceem/Documentation/Reference-manual/tag-reference/cache">wcm:cache</a> tag. This lets you cache fragments of a Template/Widget and hence get major performance improvements. The cache is currently fixed at 1 hour, but its great for anything that pulls in remote content or for any expensive node iteration tags you might be using. More enhancements will come in future.</p>
<p>A couple of nice little things we squeezed in:</p>
<ol>
<li>The Cancel button is back on the content editor screen, in the &#8220;right&#8221; place for Windows users (meh) and browsers (who made return always select the first button argh!)</li>
<li>The wcm:link tag now passes through any unused attributes eg class=&#8221;whatever&#8221;</li>
<li>We added a JS syntax highlighting script to the default space that you can use to render code snippets in your content easily</li>
</ol>
<p>Anyway, please enjoy this release. Soon time to get started on 0.9 which should see the Blog functionality completed and other refinements.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2010/01/12/weceem-0-8-released-highlights-and-background/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Announcing the &#8220;Navigation&#8221; Plugin for Grails</title>
		<link>http://www.anyware.co.uk/2005/2009/01/27/announcing-the-navigation-plugin-for-grails/</link>
		<comments>http://www.anyware.co.uk/2005/2009/01/27/announcing-the-navigation-plugin-for-grails/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 15:16:27 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=422</guid>
		<description><![CDATA[Another plugin release&#8230; this time thanks to help from Andreas Arledal on the CSS front. The Navigation Plugin gives you site navigation menus by convention. You just define a property in your controllers to determine what actions are shown and in what groups. Full docs here There is even a default styling of neutral &#8220;silver&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Another plugin release&#8230; this time thanks to help from Andreas Arledal on the CSS front.</p>
<p>The Navigation Plugin gives you site navigation menus by convention. You just define a property in your controllers to determine what actions are shown and in what groups.</p>
<p><a href="http://www.anyware.co.uk/2005/wp-content/uploads/2009/01/nav-plugin.png?9d7bd4"><img class="alignnone size-full wp-image-424" title="nav-plugin" src="http://www.anyware.co.uk/2005/wp-content/uploads/2009/01/nav-plugin.png?9d7bd4" alt="" width="500" height="53" /></a></p>
<p><a href="http://www.grails.org/Navigation+Plugin">Full docs here</a></p>
<p>There is even a default styling of neutral &#8220;silver&#8221; buttons that you can use, or override the CSS easily, or use tags to render the items any way you like.</p>
<p>Part of the motivation for this is that if we can establish a &#8220;de facto&#8221; convention for navigation info, then plugins will be able to use it, to have functionality that just automatically &#8220;pops up&#8221; in your existing application.</p>
<p>Anyway now when you are prototyping your apps you can just add &#8220;static navigation = true&#8221; to your controllers, and add &lt;nav:render/&gt; to your GSP layout&#8230; and away you go!</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2009/01/27/announcing-the-navigation-plugin-for-grails/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Functional testing in Grails just got a bit sexier</title>
		<link>http://www.anyware.co.uk/2005/2009/01/08/functional-testing-in-grails-just-got-a-bit-sexier/</link>
		<comments>http://www.anyware.co.uk/2005/2009/01/08/functional-testing-in-grails-just-got-a-bit-sexier/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 23:32:15 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=381</guid>
		<description><![CDATA[Ok so here&#8217;s the 1.0 release in the spirit of &#8220;don&#8217;t worry be crappy&#8221; (can&#8217;t use that phrase enough these days) of a new functional testing plugin for Grails. Actually its far from crappy already. I have developed this partly as part of my work for my generous client Historic Futures Ltd. who agreed to [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so here&#8217;s the 1.0 release in the spirit of &#8220;don&#8217;t worry be crappy&#8221; (can&#8217;t use that phrase enough these days) of a new functional testing plugin for <a href="http://grails.org">Grails</a>.</p>
<p>Actually its far from crappy already.</p>
<p>I have developed this partly as part of my work for my generous client <a href="http://www.historicfutures.com">Historic Futures Ltd.</a> who agreed to open source this.</p>
<p>I plan to continue improving and maintaining it personally. It&#8217;s surely a bit rough around the edges but the benefits should be pretty obvious to those who use it.</p>
<p>So what are you waiting for? Run:</p>
<pre lang="shell">grails install-plugin functional-test</pre>
<p><a href="http://www.grails.org/Grails+Functional+Testing">See the documentation</a></p>
<p>&#8230;but in a nutshell it is HTTP testing with HtmlUnit under the hood but the rest is pure groovy smarts, leveraging standard JUnit.</p>
<p>Example:</p>
<pre lang="groovy">import functionaltestplugin.*
class TwitterTests extends FunctionalTestCase {
  void testSearch() {
    get('http://www.twitter.com')

    click "Search"

    assertStatus 200
    assertContentContains "search"

    form('searchForm') {
      q = "#grails"
      click "Search"
    }

    assertStatus 200
    assertContentContains "#grails"
  }
}</pre>
<p>What&#8217;s special about this?</p>
<ol>
<li>Simplicity and &#8220;elasticity&#8221; by default = less fragile functional tests as a result</li>
<li>Simple compact DSL/methods to learn &#8211; it tries to &#8220;do the right thing&#8221;. Let&#8217;s face it writing tests is really boring.</li>
<li>Ability to get/post directly without browsing to a page first. eg REST testing</li>
<li>No .properties configs</li>
</ol>
<p>&#8230;and one more thing URL stacktrace. When a test fails the report includes a stack of the URLs at the point of failure. The xxx-out.txt file contains request parameters+headers, content received etc. This feature will be expanded in future to allow a proper request/response chain autopsy.</p>
<p>Caveats &#8211; things I definitely want to sort out pronto:</p>
<ul>
<li>currently test output is a bit ropey, I would like to do much nicer stuff with custom output xml and rendering</li>
<li>no simple way to set post body</li>
<li>no simple way to parse out json/xml responses yet</li>
</ul>
<p>All this and more will come, with your support! Contribs also welcome!</p>
<p>ENJOY!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2009/01/08/functional-testing-in-grails-just-got-a-bit-sexier/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Grails mail plugin 0.4 released, as well as the first &#8220;Grails Rocks&#8221; screencast</title>
		<link>http://www.anyware.co.uk/2005/2008/09/25/grails-mail-plugin-04-released-as-well-as-the-first-grails-rocks-screencast/</link>
		<comments>http://www.anyware.co.uk/2005/2008/09/25/grails-mail-plugin-04-released-as-well-as-the-first-grails-rocks-screencast/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 09:24:23 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[screencast]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=241</guid>
		<description><![CDATA[I released version 0.4 of the grails-mail plugin in the Grails plugin repo the other day, but have not posted about it as I&#8217;ve been busy working on-site. I&#8217;ve also been putting together a screencast that shows how to use the plugin in the most basic scenario and also render content from GSPs from within [...]]]></description>
			<content:encoded><![CDATA[<p>I released version 0.4 of the <a href="http://grails.org/Mail+Plugin">grails-mail plugin</a> in the <a href="http://grails.org">Grails</a> plugin repo the other day, but have not posted about it as I&#8217;ve been busy working on-site. I&#8217;ve also been putting together a screencast that shows how to use the plugin in the most basic scenario and also render content from GSPs from within services.</p>
<p>To install the plugin, which adds support for rendering the mail body from a GSP from within a controller, service or job, run: grails install-plugin mail</p>
<p>Full <a href="http://grails.org/Mail+Plugin">docs for the mail plugin are here</a>.</p>
<p><a href="http://s3.amazonaws.com/AnyWare/Blog/Screencasts/Grails%20Rocks%20Screencast%20%231%20-%20Grails%20Mail.mov"><img class="alignnone size-full wp-image-229" title="Grails Rocks Screencast 1 Thumbnail" src="http://www.anyware.co.uk/2005/wp-content/uploads/2008/09/grails-rocks-screencast-1-thumb.png?9d7bd4" alt="" width="200" height="125" /></a></p>
<p>To view the <a href="http://s3.amazonaws.com/AnyWare/Blog/Screencasts/Grails%20Rocks%20Screencast%20%231%20-%20Grails%20Mail.mov">&#8220;Using the Grails mail plugin&#8221; screencast</a>, click on the thumbnail or go to the fledgling &#8220;<a href="http://www.grailsrocks.com">Grails Rocks</a>&#8221; page.</p>
<p>This is the first Grails Rocks screencast, but I hope to do many more. The next one is already planned, for the forthcoming release of the Email Confirmation plugin &#8211; which was dependent on this mail plugin 0.4 release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2008/09/25/grails-mail-plugin-04-released-as-well-as-the-first-grails-rocks-screencast/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Latest Grails-mail plugin SVN commits fix GSP view rendering</title>
		<link>http://www.anyware.co.uk/2005/2008/09/11/latest-grails-mail-plugin-svn-commits-fix-gsp-view-rendering/</link>
		<comments>http://www.anyware.co.uk/2005/2008/09/11/latest-grails-mail-plugin-svn-commits-fix-gsp-view-rendering/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 14:31:42 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
				<category><![CDATA[Groovy and Grails]]></category>
		<category><![CDATA[Programming links]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/?p=205</guid>
		<description><![CDATA[The other day I committed some further improvements to the experimental email body rendering from GSP views. There is no release of grails-mail with this code in, you need to manually svn checkout and build it from the grails-plugins SVN repo. Anyway, the fixes allow you to render email body GSPs where the GSP may [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I committed some further improvements to the experimental email body rendering from GSP views. There is no release of grails-mail with this code in, you need to manually svn checkout and build it from the grails-plugins SVN repo.</p>
<p>Anyway, the fixes allow you to render email body GSPs where the GSP may live in a plugin, or be overriden by your app. To do this, you have to specify the plugin name when rendering the body of the mail &#8211; this is required because there&#8217;s currently no way Grails can know where the view might be as the contents of plugin view trees are not merged with the app view tree. I can see scope for a future improvement in Grails core, to add all plugin view paths to the resource search paths during development, and shipping a single merged views/ tree within .WAR files built by Grails.</p>
<p>So here&#8217;s how you render a mail body from a view in a controller with grails-mail installed:</p>
<pre lang="groovy">sendMail {
   to "test@somewhere.com"
   subject "Hello"
   body(view:'/something/mailbody1.gsp',
      plugin:'my-great-plugin')
}</pre>
<p>This will try to locate the view in:</p>
<p>&lt;app&gt;/grails-app/views/something/mailbody1.gsp</p>
<p>but if it can&#8217;t find it, will try:</p>
<p>&lt;app&gt;/plugins/my-great-plugin-&lt;vernum&gt;/grails-app/views/something/mailbody1.gsp</p>
<p>Also these commits fix GSP taglibs in email bodies. Previously they&#8217;d appear in the HTML response of the controller ooops&#8230; now they appear in the body of the mail as expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2008/09/11/latest-grails-mail-plugin-svn-commits-fix-gsp-view-rendering/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 11/18 queries in 0.080 seconds using disk: basic

Served from: www.anyware.co.uk @ 2012-02-05 03:43:13 -->
