Using Markdown as a Grails View

We are writing a grails project (Grails 2.1.1), where for some of our views we want to use markdown instead of gsp files.

At the moment, we can do this using the markdown plugin in a special layout. This allows us to display markup in this way:

render(layout: 'docs', view: 'markdown')

However, this requires that the markdown page have the extension .gsp, when for practical reasons we need to have the extension .md.

Does anyone know how best to use markdown as a kind of grails? It would be great if we could avoid using the .gsp extension.

+7
source share
2 answers

Short answer

You cannot without any major modifications. The distributed GrailsViewResolver is tightly bound to the .gsp and .jsp extensions.

See grails-core on github for a check.

Long answer

You might be able to create your own Ant task to connect it to the Compile loop of your Grails application, to at least compile your * .md files through GroovyPageCompiler.

This process may look like this (although not quite so, since I rely on the taglib plugin to render in this case, for simplicity).

But this does not solve all your problems. You will also need to register a new permission resolver, and for this you would inevitably go the way of rewriting the GrailsDispatcherServlet .

It looks like your decision to store files in the conf directory might be your best (albeit messy) one. It may take some time for someone to configure GSP file extensions in the future, and this may solve your problem along the way.

I hope you find some useful information.

+2
source

I did almost the same, but with a different approach today. I wanted to serve the readme file of the project, so I could not move it. I ended up with soft binding it from readme.md to grails-app/views/readme/readme.gsp . I posted about all this.

And yes - soft binding works if you and all your employees are on * -nix - so this is not a safe way for the platform.

0
source

All Articles