From 0360df83cbd66092ad829d9346bedcaf16bfe7da Mon Sep 17 00:00:00 2001 From: Helio Cola Date: Thu, 18 Apr 2024 05:18:54 -0400 Subject: [PATCH] Move the t alias to its own extension file Co-Authored-By: Dmitry Polushkin <5091+dmitry@users.noreply.github.com> --- lib/redcloth.rb | 11 ++--------- lib/redcloth/erb_alias_extension.rb | 15 +++++++++++++++ lib/redcloth/erb_extension.rb | 2 -- spec/erb_spec.rb | 1 + 4 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 lib/redcloth/erb_alias_extension.rb diff --git a/lib/redcloth.rb b/lib/redcloth.rb index 376d022e..9f92cf95 100644 --- a/lib/redcloth.rb +++ b/lib/redcloth.rb @@ -28,23 +28,16 @@ require 'redcloth/formatters/latex' module RedCloth - + # A convenience method for creating a new TextileDoc. See # RedCloth::TextileDoc. def self.new( *args, &block ) RedCloth::TextileDoc.new( *args, &block ) end - + # Include extension modules (if any) in TextileDoc. def self.include(*args) RedCloth::TextileDoc.send(:include, *args) end - -end -begin - require 'erb' - require 'redcloth/erb_extension' - include ERB::Util -rescue LoadError end diff --git a/lib/redcloth/erb_alias_extension.rb b/lib/redcloth/erb_alias_extension.rb new file mode 100644 index 00000000..8c8006f7 --- /dev/null +++ b/lib/redcloth/erb_alias_extension.rb @@ -0,0 +1,15 @@ + +require 'erb' +require 'redcloth/erb_extension' + +class ERB + module Util + alias t textilize + module_function :t + end +end + +begin + include ERB::Util +rescue LoadError +end diff --git a/lib/redcloth/erb_extension.rb b/lib/redcloth/erb_extension.rb index a30486ec..edc17ab6 100644 --- a/lib/redcloth/erb_extension.rb +++ b/lib/redcloth/erb_extension.rb @@ -19,8 +19,6 @@ def textilize( s ) end end - alias t textilize - module_function :t module_function :textilize end diff --git a/spec/erb_spec.rb b/spec/erb_spec.rb index 71c11b65..97c222bd 100644 --- a/spec/erb_spec.rb +++ b/spec/erb_spec.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + '/spec_helper' +require 'redcloth/erb_alias_extension' describe "ERB helper" do it "should add a textile tag to ERB" do