Project

General

Profile

index/show.api.rsb templates are all wet... err, not DRY

Added by Alex Shulgin about 12 years ago

Hello,

I've been sent this pull request to a plugin of mine: https://github.com/commandprompt/redmine_pastebin/pull/10

In this commit, the two files index.api.rsb and show.api.rsb are added: https://github.com/florentsolt/redmine_pastebin/commit/dbf41bec9684e7542264b268acf225f6072cf637

What catches my attention is that the index template repeats nearly exactly the same code as found in the show action template... Don't see how's this relevant to Redmine in general, huh? Read on.

What I've found is that all of Redmine's rsb templates do exactly the same thing: they are duplicating the code of show template in the index template. Isn't there any way out?

With ERB we'd just render a partial, but what about RSB? I can see it's defined in lib/redmine/views/api_template_handler.rb like this:

    class ApiTemplateHandler < ActionView::TemplateHandler
      include ActionView::TemplateHandlers::Compilable

      def compile(template)
        "Redmine::Views::Builders.for(params[:format]) do |api|; #{template.source}; self.output_buffer = api.output; end" 
      end
    end

Ideas?

--
Alex


Replies (1)

RE: index/show.api.rsb templates are all wet... err, not DRY - Added by Alex Shulgin about 12 years ago

Hm... I'm inclined towards filing a bug against this code quality deficiency.

    (1-1/1)