mobilemindtec / grails-jade

Grails plugin for rendering Jade templates with the spring-jade4j library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

GRAILS JADE PLUGIN

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.

CONFIGURATION

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.

JadeDefaultConfig.groovy
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 = [:]
		}
	}
}

Coffeescript Filter

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.

BuildConfig.groovy
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')
    ...
}
Config.groovy
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.

somefile.jade
block content
    #bodytext Empty

    :coffeescript
        updateContent = -> document.getElementById('bodytext').innerHTML = 'Not Empty'

        do updateContent
grails template tags
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      

Markdown Filter

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.

BuildConfig.groovy
dependencies {
    compile('org.markdownj:markdownj:0.3.0-1.0.2b4')
    ...
}
Config.groovy
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()]
        }
    }
}
somefile.jade
block content

    #bodytext
        :markdown
            ### Hello World ###

Multiple Filters

You can have multiple filters by simply adding them to the filter definition map.

Config.groovy
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()]
        }
    }
}

About

Grails plugin for rendering Jade templates with the spring-jade4j library


Languages

Language:Groovy 76.1%Language:Java 23.9%