# Filter help

**URL:** <https://www.ruby-forum.com/t/filter-help/98303>\
**Category:** Radiant CMS\
**Created:** [July 13, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/filter-help/98303 "2006-07-13T18:52:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 13, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/filter-help/98303/1 "2006-07-13T18:52:31Z")

</div>

For my own Radiant installation I’ve extended all filters to include a  
“help” method that returns a piece of text which gets inserted into the  
relevant views to form a set of help links for filter types. They get  
listed next to the pop-up filter menu. Ajaxian people might prefer to  
have something a bit more lively, perhaps popping up only when a  
specific filter is selected; anyway, it looks like this:

- In lib/generators/filter/templates/model.rb.template:

- Therefore, in app/filters, markdown\_filter.rb and textfile\_filter.rb  
have been extended with, respectively:

- In app/views/admin/page/\_part.rhtml and  
app/views/admin/snippet/new.rhtml, the following has been added  
after the ERB select\_tag() call creating the filter menu (yes, the  
hyphen hefore “Filter help” is intentional as a hacky separator  
between the text and the selection menu):

If you don’t like forcing all filters to implement the method, you could  
do something a bit grubby in the code block such as:

|filter| filter.respond\_to?(:help) ? filter.help : ‘(None)’

Either way, the code probably ought to go into a helper method rather  
than be copied verbatim in two view files. All in all it works, but it’s  
quick and dirty so is not an immediate candidate for a patch. Does the  
idea deserve further work, though, or is it something that’s really too  
specific to my installation?

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 13, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/filter-help/98303/2 "2006-07-13T19:15:31Z")

</div>

I wrote:

> Either way, the code probably ought to go into a helper method

I seem to make a living out of replying to my own messages. Talking to  
myself can only mean one thing…

In app/helpers/application\_helper.rb:

def filter\_help\_links  
# Find all filters creating an array; run ‘help’ on each item to  
# create a new array; join the array items to form a string. Allow  
# filters that don’t have help and cope with the case where no  
# registered filters provide it.

```
@links = TextFilter.find_all.map { |filter|
           filter.respond_to?(:help) ? filter.help : nil
         }.compact.join(', ')

@links != '' ? @links : 'No help available'

```

end

That does the trick nicely. Might want to modify the “no help” return  
value for more cunning template use than just bunging the links next to  
the menu.

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 13, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/filter-help/98303/3 "2006-07-13T19:17:39Z")

</div>

Andrew H. wrote:

> Either way, the code probably ought to go into a helper method rather  
> than be copied verbatim in two view files. All in all it works, but it’s  
> quick and dirty so is not an immediate candidate for a patch. Does the  
> idea deserve further work, though, or is it something that’s really too  
> specific to my installation?

It’s a good idea. I’ve wanted to implement something similar for tags  
too. This way you could click an “Available Tags” link and it would show  
you descriptions of all available Radius tags for that page (including  
tags added by the selected behavior). See:

[http://dev.radiantcms.org/radiant/browser/trunk/images/edit-page.png](http://dev.radiantcms.org/radiant/browser/trunk/images/edit-page.png)

For filters, I’d like it to work like this:

class MyFilter \< TextFilter::Base

```
 register 'My Filter'

 description %{
   Rdoc formatted description that is displayed when you click
   the "My Filter" link.
 }

 def filter(text)
   # filter text here...
 end

```

end

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 14, 2006, 4:31am UTC](https://www.ruby-forum.com/t/filter-help/98303/4 "2006-07-14T04:31:43Z")

</div>

Oliver B. wrote:

> On 13-Jul-2006 13:15 -0400, John W. Long was heard to say:
> 
> > It’s a good idea. I’ve wanted to implement something similar for tags  
> > too. This way you could click an “Available Tags” link and it would show  
> > you descriptions of all available Radius tags for that page (including  
> > tags added by the selected behavior). See:
> 
> In some distance future and maybe some other life I envision a  
> JavaScript/AJAX-based code-completion 😉

Yah. All we need is someone to implement TextMate in javascript. 🙂

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 14, 2006, 4:25am UTC](https://www.ruby-forum.com/t/filter-help/98303/5 "2006-07-14T04:25:25Z")

</div>

On 13-Jul-2006 13:15 -0400, John W. Long was heard to say:

> It’s a good idea. I’ve wanted to implement something similar for tags  
> too. This way you could click an “Available Tags” link and it would show  
> you descriptions of all available Radius tags for that page (including  
> tags added by the selected behavior). See:

In some distance future and maybe some other life I envision a  
JavaScript/AJAX-based code-completion 😉

Oliver
