jgarber / redcloth

RedCloth is a Ruby library for converting Textile into HTML.
Other
443 stars 113 forks source link

Prevent redcloth from mapping `t` to `textilize` in erb views #49

Open letronje opened 6 years ago

letronje commented 6 years ago

We use both active admin and redcloth. Redcloth maps t helper to textlize and that breaks active admin views which expect t to mean translate . Is there a way to opt out of Redcloth's monkey patch for Erb::Util ?

https://github.com/jgarber/redcloth/blob/f1c3076d0409a4ec0ead51190085f82ab97cf923/lib/redcloth/erb_extension.rb#L16-L24 https://github.com/jgarber/redcloth/blob/f1c3076d0409a4ec0ead51190085f82ab97cf923/lib/redcloth.rb#L40-L45

We had the following Monkey Patch that worked in ruby 2.2.4 but stops working in 2.3.6 with the error uninitialized constant I18n::Config::Backend (NameError) [ probably due to some change in the sequence in which things are getting loaded in 2.3.6 ]

require "redcloth"
class ERB
  module Util
    def translate(s)
      if s && s.respond_to?(:to_s)
        ::I18n.t(s)
      end
    end

    alias t translate
    module_function :t
  end
end
heliocola commented 5 months ago

@letronje : I started working on this as I run into a similar issue that you reported here. Long term, I want to deprecate the t alias all together.

If a t method is really important maybe RedCloth.t I'd be ok with. We were discussing having a configuration that will allow you to indicate you still want the old behavior, but not sure if that will be useful to anybody.

So I will start a 5.x version without the alias by default, and if needed I can try to maintain both 4.x and 5.x.