Redmine wikiの機能拡張 pluginのバグが判った!

最新版のソース → https://gist.github.com/1129980

前回プラグインで挙動がおかしかった原因が判りました。
わかってみると簡単な事で、書き換える対象のクラス/モジュールを require してなかったのが原因でした。

# RedmineColorPre
require 'redcloth'
require 'coderay'
require 'redmine/wiki_formatting'

module Redmine
  module WikiFormatting

  private
    class TextileFormatter < RedCloth
      alias :smooth_offtags_orgin :smooth_offtags
      private
      def smooth_offtags( text )
        unless @pre_list.empty?
          ## replace <pre> content
          text.gsub!(/<redpre#(\d+)>/) do
            content = @pre_list[$1.to_i]
            if content.match(/<code\s+class="(color)">\s?(.+)/m)
              content = "<code>" + $2.gsub('##(', '<span style="color:#F00">').gsub(')##', '</span>')
            elsif content.match(/<code\s+class="(\w+)">\s?(.+)/m)
              content = "<code class=\"#{$1} CodeRay\">" + 
                CodeRay.scan($2, $1.downcase).html(:escape => false, :line_numbers => :inline)
            end
            content
          end
        end
      end
    end
  end
end

このプラグインは既存のTextileFormatterクラスのsmooth_offtagsメソッドを置き換えているパッチみたいなものなので、プラグインが読み込まれた時点で確実に元のクラスが読み込まれていないと正しく動作しないですね。