Skip to content

Commit

Permalink
Move the t alias to its own extension file
Browse files Browse the repository at this point in the history
  • Loading branch information
heliocola committed Apr 18, 2024
1 parent fb6d315 commit 93b34b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
11 changes: 2 additions & 9 deletions lib/redcloth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions lib/redcloth/erb_alias_extension.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions lib/redcloth/erb_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def textilize( s )
end
end

alias t textilize
module_function :t
module_function :textilize

end
Expand Down
1 change: 1 addition & 0 deletions spec/erb_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 93b34b5

Please sign in to comment.