The Grails Jade plugin allows you to replace or use in conjunction jade files with Grails views. This plugin is a wrapper for jade4j and spring-jade4j. There are several working examples in the plugin source in version control that will help you get started.
The plugin allows customization on how the jade is rendered via a few different configuration options. Below is the default configuration that is bundled. To change the configuration simple add the block below to your Config.grooy and change the values. You only need to add the values you with to replace as the default config will be merged with yours.
grails {
plugin {
jade {
/* Format the HTML or compress the output by removing unecessary whitespace. */
prettyPrint = true
/* Store the parsed template or reparse for every request. set true when production */
caching = false
/* Render exceptions in view or fail silently. */
renderExceptions = true
/* Additional filters for embedding different content types in a template, such as markdown, coffeescript */
filters = [:]
/* Default objects available to all templates. */
sharedVariables = [:]
}
}
}
To add filtering for coffeescript you would need to add coffeescript-jade-filter and jcoffeescript to your path via lib or maven and add the following to your application.
repositories {
mavenRepo "https://raw.github.com/neuland/jade4j/master/releases/"
mavenRepo "https://raw.github.com/neuland/spring-jade4j/master/releases/"
mavenRepo "https://raw.github.com/neuland/jade4j-coffeescript-filter/master/releases/"
}
dependencies {
compile('de.neuland:jade4j-coffeescript-filter:0.2.0', 'com.google.code.maven-play-plugin.com.github.yeungda.jcoffeescript:jcoffeescript:1.0')
...
}
import de.neuland.jade4j.filter.CoffeeScriptFilter
grails {
plugin {
jade {
/* Additional filters for embedding different content types in a template, such as markdown, coffeescript */
filters = ['coffeescript': new CoffeeScriptFilter()]
}
}
}
You can then use coffeescript in your jade.
block content
#bodytext Empty
:coffeescript
updateContent = -> document.getElementById('bodytext').innerHTML = 'Not Empty'
do updateContent
doctype html
html
head
meta(http-equiv='http-equiv', content-type='Content-type', content='text/html; charset=utf-8')
${asset.stylesheet(src: 'style.css')}
title Mobile Mind
block title
:coffeescript
do_context = ->
window.ContextPath = '${request.contextPath}'
window.ContextAssets = '${request.contextPath}/assets'
do do_context
To add filtering for markdown you would need to add markdownj to your path via lib or maven and add the following to your application.
dependencies {
compile('org.markdownj:markdownj:0.3.0-1.0.2b4')
...
}
import de.neuland.jade4j.filter.MarkdownFilter
grails {
plugin {
jade {
/* Additional filters for embedding different content types in a template, such as markdown, coffeescript */
filters = ['markdown': new MarkdownFilter()]
}
}
}
block content
#bodytext
:markdown
### Hello World ###
You can have multiple filters by simply adding them to the filter definition map.
import de.neuland.jade4j.filter.CoffeeScriptFilter
import de.neuland.jade4j.filter.MarkdownFilter
grails {
plugin {
jade {
/* Additional filters for embedding different content types in a template, such as markdown, coffeescript */
filters = ['coffeescript': new CoffeeScriptFilter(), 'markdown': new MarkdownFilter()]
}
}
}