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

Stop extending into ERB the t and textilize #19

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
7 changes: 0 additions & 7 deletions lib/redcloth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,3 @@ def self.include(*args)
end

end

begin
require 'erb'
require 'redcloth/erb_extension'
include ERB::Util

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This like also includes ERB::Util in the Object class. Even that t method is not removed I think this line should be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it removed in the commit?

rescue LoadError
end
5 changes: 0 additions & 5 deletions lib/redcloth/erb_extension.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class ERB
module Util

#
# A utility method for transforming Textile in _s_ to HTML.
#
Expand All @@ -18,10 +17,6 @@ def textilize( s )
RedCloth.new( s.to_s ).to_html
end
end

alias t textilize
module_function :t
module_function :textilize

end
end
15 changes: 12 additions & 3 deletions spec/erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
require File.dirname(__FILE__) + '/spec_helper'
require 'redcloth/erb_extension'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requiring this here requires it globally. Not just for this test. Better would be to create a test class and include it in there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea how to do that? To preserve the same functionality (auto-inclustion to the ERB helpers), I believe it's impossible to do. This could be changed to use another module, include it into a ERB::Utils and then remove module later when test unit is completed. Let me know your thoughts.


describe "ERB helper" do
it "should add a textile tag to ERB" do
template = %{<%=t "This new ERB tag makes is so _easy_ to use *RedCloth*" %>}
erb_class = Class.new do
include ERB::Util

def main
input = %{<%= textilize "This new ERB tag makes is so _easy_ to use *RedCloth*" %>}
ERB.new(input).result(binding)
end
end

expected = %{<p>This new <span class="caps">ERB</span> tag makes is so <em>easy</em> to use <strong>RedCloth</strong></p>}

ERB.new(template).result.should == expected
erb_class.new.main.should == expected
end
end
end