module Facebooker
  module Xiaonei
    module Rails
      module Helpers
        def self.included(base)
          base.instance_methods.grep(/^fb_/).each do |fb_method|
            base.send(:define_method,"#{fb_method}_with_xiaonei") do |*args|
              fb_method_without_xiaonei = send("#{fb_method}_without_xiaonei",*args)
              fb_method_without_xiaonei.gsub!(/^<fb:([\w\-_])+?/,"<xn:\\1")
              fb_method_without_xiaonei.gsub(/<\/fb:([\w\-_])+?>$/,"</xn:\\1>")
            end
            base.alias_method_chain fb_method,:xiaonei
          end
        end
      end
    end
  end
end

Facebooker::Rails::Helpers.send(:include,Facebooker::Xiaonei::Rails::Helpers)
