Skip to content

Instantly share code, notes, and snippets.

@gregopet
Last active December 16, 2015 02:19
Show Gist options
  • Select an option

  • Save gregopet/5361848 to your computer and use it in GitHub Desktop.

Select an option

Save gregopet/5361848 to your computer and use it in GitHub Desktop.
An idea for a Grails plugin

Lately I've been using the excellent Middleman static site generator for a few projects, but having a certain distaste for Ruby, I've been giving some thought to building a Grails plugin for this task. A quick search didn't yield any existing plugins that could do this, so I may just give it a go.

The way this would work is to create a normal Grails application and somehow fill it with data (e.g. with the Fixtures plugin or from an actual database) and then call a script provided by this new plugin. This script would start the Grails application and crawl it as defined by a set of conventions and rules, saving the resulting HTML pages in a folder.

My first dilemma is over the best way of defining these rules. One would be to simply use the UrlMappings.groovy file, e.g.

"/book/list"(controller: 'book', action: 'list')
"/book/$book"(controller: 'book', action: 'show')

...would result in single HTML file for the list action and one HTML for each Book instance as returned by Book.list() - where the name of the Book class would be inferred either from the parameter name book or from the controller name. Properties of the domain class could be used to build more complex structures, e.g. "/book/$book/$chapter" would traverse all members of a book's chapter collection.

The other option is to create a DSL which would offer more flexibility (you could for instance build several static sites from a single Grails application, maybe even have the static part communicate with some dynamic API controllers in the running Grails app, and have more control in general) but this requires some extra work by the developer as you'd have to write both the URL mappings as well as the DSL (then again perhaps not if the simple default URL mappings are enough for you - then a developer could focus on the DSL and not have to craft URL mappings the plugin would recognize).

Then again, perhaps one could automate things even further by using the artifact API available to plugins?

Anyway, I'd appreciate any feedback both over this dilemma as well as any general suggestions and even opinions if such a plugin is required at all (after all, one could simply create a Grails app and wget it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment