a groovy breadcrumbs for grails
Groovy Java
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
grails-app
src/groovy/breadcrumbs
test
web-app
.gitattributes
.gitignore
GroovyBreadcrumbsPluginGrailsPlugin.groovy
README.md
application.properties

README.md

groovy-breadcrumbs-plugin

This plugin gives you an Breadcrumb based on a definition of the navigation structure (implementation of a "menuDefinitionService" service). A simple breadcrumb editable and robust. the construction of the breadcrumb is based on the couple action / controller. An annotation allows you to change the breadcrumb. Very flexible and easy to implement.

Install

compile ":groovy-breadcrumbs-plugin:1.0.2"

Using

The breadcrumbs plugin is based on a MenuDefinitionService is provided by the application. So let's go create the service

Run create-service MenuDefinitionService

In MenuDefinitionService create a method called loadMenuDefinition

example

class MenuDefinitionService  {

	static transactional = false

	static scope = "session"

	static proxy = true


	def loadMenuDefinition() {
		def menus = []
	
	    menus << new MenuItem(name : "page-one", message:"page.one.demo", controller: "BreadCrumbsDemo", action: "pageOne")
	    MenuItem menuThreeTwo = new MenuItem(name : "page-two-", message:"page.two.demo", controller: "BreadCrumbsDemo", action:"pageThreeTwo")
	  	menuThreeTwo << new MenuItem(name : "page-two.one", message:"page.two.one.demo", controller: "BreadCrumbsDemo", action:"pageThreeTwoOne")
	  	menuThreeTwo << new MenuItem(name : "page-two.two", message:"pagetwo.two.demo", controller: "BreadCrumbsDemo", action:"pageThreeTwoTwo")
	 	menus << menuThreeTwo
	  
	 	menus
	}
}

You can define as many levels that you want !!!

Just define the message in messages.properties

like page.two.demo=pageTwo

Declare Service MenuDefinitionService as proxy in resources.groovy

beans = {
	...
	menuDefinitionServiceProxy(org.springframework.aop.scope.ScopedProxyFactoryBean) {
		targetBeanName = 'menuDefinitionService'
		proxyTargetClass = true
	}
	...
}

Now the end, for define the divider of breadcrumbs

add grails configuration in config.groovy

breadcrumbs.divider = "&gt;"

You can define all > < / - ... divider that you want

You can also define html character like &gt; or &lt; or &yen; if you want :)

Adding the taglib in your layout

<crumbs:breadcrumbs />

Using BreadCrumbs Annotation

To redefine breadcrumb use @BreadCrumbs

The breadcrumb can be reset by three ways

  • static
  • session
  • request

Example with static scope

@BreadCrumbs (scope = BreadCrumbsScopeEnum.STATIC, actionName = "actionName", ControllerName = "ControllerName")
def controllerMethod() {
  ....
}

Example with request scope

@BreadCrumbs (scope = BreadCrumbsScopeEnum.REQUEST, actionName = "actionName", ControllerName = "ControllerName")
def controllerMethod() {
  ....
}

Example with session scope

@BreadCrumbs (scope = BreadCrumbsScopeEnum.SESSION)
def controllerMethod() {

	breadCrumbsService.pushActionInSession ("actionName")
	and / or
	breadCrumbsService.pushControllerInSession ("controllerName")
 	 ....
}

activate clickable Mode

breadcrumbs.enable.clickable=true

Configure Home Item

breadcrumbs.enable.home=true

Two mode are possible

mode image

breadcrumbs.home.type="image"

mode text

breadcrumbs.home.type="message"

Add a getHomeItem() in MenuDefinitionService

Example for image mode

def getHomeItem(){
	def message = "breadcrumbs/menu_home.png"
	def home  = new MenuItem(name:"page-home", message: message);
	home
}

Or for message mode

def getHomeItem(){
	def home  = new MenuItem(name:"page-home", message: "message key");
	home
}

for style

define a css for

.breadcrumb

for

.breadcrumb > li

and for active item

.breadcrumb > li > .active

Thank to

laurent guerin