|
View:
New views
14 Messages
—
Rating Filter:
Alert me
|
|
|
Breadcrumbs pluginI've designed a breadcrumbs plugin which i'd be happy to throw into the mix, though it's got one key flaw which I'd like to address first, and perhaps I could get some suggestions of how to do this.
The approach I took for Breadcrumbs is not "this is the path you've taken" but rather "this is where you are in our site structure". So what I did was to 'define' this structure using a nesting of closures and or strings and I build an object tree from this nesting - the breadcrumbs configuration. The thing is, I wasn't sure where to put it so I slapped it into Config.groovy, but I've found this to be cumbersome and as my breadcrumbs tree grows, it really clutters up Config.groovy. So the main question and the purpose of this post is, where would a good place be to define this tree, if not in Config.groovy, given it's syntax? Some more background: With this tree in place, I use a taglib to try and match the incoming URL against the tree, and it creates a breadcrumbs path from that. Now the biggest challenge was how to deal with the dynamic nature of the content... for instance if a user were to click on a search result that took them to a node 3 levels deep into the tree, some of its parent nodes might need to know a bit more about themselves if their position contains dynamic content. So I have a 'context' map object that is passed into each closure specified in the tree as the taglib climbs up the path from the child to the root parent. And it's up to you the developer to place necessary objects into that context so that parent nodes can figure out whatever they need to about themselves. If a node has dynamic content in its url, it should also specify a context.url param which the breadcrumb tag will use as the url for that particular node. At the end of this post is a sample of the breadcrumbs tree. You'll see you can specify a label as either a static String, or you can dynamically calculate it. If a URL has parameters (as per UrlMappings syntax), those are placed into the context as 'args'. So, assuming what I said makes sense, anybody got a good suggestion of a better place to put this tree configuration? Feedback, comments and suggestions welcome. Thanks, Darryl Pentz breadcrumbs = { showHomeLink = false layout { "/profile/list" { pseudonyms = "/,/profile" label = "Profiles" "/profile/summary/$id" { label = {context -> if (context.args) { Profile profile = Profile.get(Long.valueOf(context.args[0])) context.url = "/profile/summary/${profile.id}" return profile.name } Profile profile = context.profile context.url = "/profile/summary/${profile.id}" return profile.name } "/profile/listDevices/$id" { label = { context -> Profile profile; if (context.args) { profile = Profile.get(Long.valueOf(context.args[0])) context.profile = profile context.url = "/profile/listDevices/${profile.id}" return "Devices" } profile = context.profile context.url = "/profile/listDevices/${profile.id}" return "Devices" } "/device/summary/$id" { label = {context -> Device device = Device.get(Long.valueOf(context.args[0])) context.profile = device.profile context.url = "/device/summary/${device.id}" return device.hostname } } } . . . } |
|
|
Breadcrumbs pluginD'ugh. Obviously that should have been titled "Breadcrumbs plugin" :-( Darryl Pentz wrote: > > I've designed a bookmarks plugin which i'd be happy to throw into the mix, > though it's got one key flaw which I'd like to address first, and perhaps > I could get some suggestions of how to do this. > > The approach I took for Breadcrumbs is not "this is the path you've taken" > but rather "this is where you are in our site structure". So what I did > was to 'define' this structure using a nesting of closures and or strings > and I build an object tree from this nesting - the breadcrumbs > configuration. The thing is, I wasn't sure where to put it so I slapped it > into Config.groovy, but I've found this to be cumbersome and as my > breadcrumbs tree grows, it really clutters up Config.groovy. So the main > question and the purpose of this post is, where would a good place be to > define this tree, if not in Config.groovy, given it's syntax? > > Some more background: With this tree in place, I use a taglib to try and > match the incoming URL against the tree, and it creates a breadcrumbs path > from that. Now the biggest challenge was how to deal with the dynamic > nature of the content... for instance if a user were to click on a search > result that took them to a node 3 levels deep into the tree, some of its > parent nodes might need to know a bit more about themselves if their > position contains dynamic content. So I have a 'context' map object that > is passed into each closure specified in the tree as the taglib climbs up > the path from the child to the root parent. And it's up to you the > developer to place necessary objects into that context so that parent > nodes can figure out whatever they need to about themselves. If a node has > dynamic content in its url, it should also specify a context.url param > which the breadcrumb tag will use as the url for that particular node. > > At the end of this post is a sample of the breadcrumbs tree. You'll see > you can specify a label as either a static String, or you can dynamically > calculate it. If a URL has parameters (as per UrlMappings syntax), those > are placed into the context as 'args'. > > So, assuming what I said makes sense, anybody got a good suggestion of a > better place to put this tree configuration? Feedback, comments and > suggestions welcome. > > Thanks, > Darryl Pentz > > breadcrumbs = { > showHomeLink = false > layout { > "/profile/list" { > pseudonyms = "/,/profile" > label = "Profiles" > "/profile/summary/$id" { > label = {context -> > if (context.args) { > Profile profile = > Profile.get(Long.valueOf(context.args[0])) > context.url = "/profile/summary/${profile.id}" > return profile.name > } > > Profile profile = context.profile > context.url = "/profile/summary/${profile.id}" > return profile.name > } > "/profile/listDevices/$id" { > label = { context -> > Profile profile; > if (context.args) { > profile = > Profile.get(Long.valueOf(context.args[0])) > context.profile = profile > context.url = > "/profile/listDevices/${profile.id}" > return "Devices" > } > > profile = context.profile > context.url = "/profile/listDevices/${profile.id}" > return "Devices" > } > "/device/summary/$id" { > label = {context -> > Device device = > Device.get(Long.valueOf(context.args[0])) > context.profile = device.profile > context.url = "/device/summary/${device.id}" > return device.hostname > } > } > } > . > . > . > } > -- View this message in context: http://www.nabble.com/Bookmarks-plugin-tp17017903p17017949.html Sent from the grails - user mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Breadcrumbs plugin - need adviceHi all,
Some time back I posted the comment below to which nobody responded. I'm not complaining cos i understand the nature of a forum, but I'm just asking again if anybody has any good ideas regarding my main problem indicated below - because I'm back to working on this plugin and haven't yet thought of a good solution. Particularly those of you who have done some plugin development already. Muchos gracias. - Darryl Pentz
|
|
|
Re: Breadcrumbs plugin - need adviceHi,
I'm kinda new to grails, and I would really like a breadcrumbs plugin. I have a perhaps dumb question? Isn't it easier to *somehow* plugin into the UrlMappings and decode the current user position based on the incoming request? It seems to me that you are replicating the url mapping structure by hand. Don't know if it's possible though, its just a thought... Cheers, Miguel On Thu, May 15, 2008 at 10:49 AM, Darryl Pentz <djpentz@...> wrote:
|
|
|
|
|
|
RE: Breadcrumbs plugin - need adviceSo… does that mean there is a breadcrumbs plugin? Do you have a
link for those of us who would like to check it out? Thanks, Pam From: Darryl Pentz
[mailto:djpentz@...] Hi Miguel, ----- Original Message ---- On Thu, May 15, 2008 at 10:49 AM, Darryl Pentz <djpentz@...>
wrote:
|
|
|
RE: Breadcrumbs plugin - need adviceHi Pam,
No not yet unfortunately. I just wanted to make that one configuration change before putting it up anywhere. As soon as I can figure out a more Grails-like approach. :) - Darryl
|
|
|
Re: Breadcrumbs plugin - need advice2008/5/15 Darryl Pentz <djpentz@...>:
> > Hi all, > > Some time back I posted the comment below to which nobody responded. I'm not > complaining cos i understand the nature of a forum, but I'm just asking > again if anybody has any good ideas regarding my main problem indicated > below - because I'm back to working on this plugin and haven't yet thought > of a good solution. Particularly those of you who have done some plugin > development already. A couple of other options: * Create your own artefact (like filters) - a user could then easily break the configuration up across multiple files/classes * Put the config in a different *Config.groovy file that can be included from the main Config.groovy Actually, Grails may load all files that match the pattern "grails-app/conf/*Config.groovy", but I'm not sure. I would have to check. HTH, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
|
|
|
Re: Breadcrumbs plugin - need adviceI will be needing breadcrumbs for my app...I would be interested in the code as well...
On Thu, May 15, 2008 at 10:56 AM, Peter Ledbrook <peter@...> wrote: 2008/5/15 Darryl Pentz <djpentz@...>: |
|
|