Filter help

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:

    def self.help
    # insert appropriate link below
    <%= filter_name %>
    end

  • Therefore, in app/filters, markdown_filter.rb and textfile_filter.rb
    have been extended with, respectively:

    def self.help
    Markdown
    end

    def self.help
    Textile
    end

    Producing the whole link rather than, say, just returning the URL,
    is done so that help() methods could insert more advanced links if
    they so wish. This includes JavaScript which could tailor the size
    of the pop-up window; useful, for example, for the Textile quick
    help page which restricts its help text within a narrow table.

  • 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):

    • Filter help:
      <%= TextFilter.find_all.map { |filter| filter.help } .join(’, ') %>

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?

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.

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

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

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 :wink:

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


John L.
http://wiseheartdesign.com

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 :wink:

Oliver

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs