Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
letronje opened this issue Feb 25, 2018 · 1 comment
Open

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

letronje opened this issue Feb 25, 2018 · 1 comment

Comments

@letronje
Copy link

letronje commented Feb 25, 2018

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 ?

def textilize( s )
if s && s.respond_to?(:to_s)
RedCloth.new( s.to_s ).to_html
end
end
alias t textilize
module_function :t
module_function :textilize

redcloth/lib/redcloth.rb

Lines 40 to 45 in f1c3076

begin
require 'erb'
require 'redcloth/erb_extension'
include ERB::Util
rescue LoadError
end

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
@letronje letronje changed the title Prevent redcloth from mapping t to textilize Prevent redcloth from mapping t to textilize in erb views Feb 25, 2018
@heliocola
Copy link
Collaborator

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants