Skip to content

Commit

Permalink
Removed grouping for html_options in link filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dejan committed Feb 12, 2009
1 parent 8c0a723 commit 45d6879
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -7,7 +7,7 @@ Rails plugin for easy converting URL's to appropriate HTML blocks for links, ima
class BlogPost < ActiveRecord::Base
auto_html_for(:body) do
html_escape
link(:html_options => {:rel => "nofollow"})
link(:rel => "nofollow")
simple_format
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/filter.rb
Expand Up @@ -3,7 +3,7 @@ module AutoHtml
class Filter
def initialize(block)
@block = block
@options = {}
@options = nil
end

def with(options, &block)
Expand All @@ -12,11 +12,11 @@ def with(options, &block)
end

def apply(text, options = {})
_options = @options.merge(options)
if _options.empty?
@block.call(text.dup)
else
_options = @options && @options.merge(options)
if _options
@block.call(text.dup, _options)
else
@block.call(text.dup)
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/filters/link.rb
Expand Up @@ -2,7 +2,7 @@
# ActionView::Helpers::TagHelper and
# ActionView::Helpers::TextHelper
#
AutoHtml.add_filter(:link).with(:html_options => {}) do |text, options|
AutoHtml.add_filter(:link).with({}) do |text, options|

def tag_options(options)
unless options.blank?
Expand Down Expand Up @@ -35,8 +35,7 @@ def auto_link_re
}x
end

html_options = options[:html_options]
extra_options = tag_options(html_options.stringify_keys) || ""
extra_options = tag_options(options.stringify_keys) || ""
text.gsub(auto_link_re) do
all, a, b, c, d = $&, $1, $2, $3, $4
if a =~ /<a\s/i # don't replace URL's that are already linked
Expand Down
2 changes: 1 addition & 1 deletion spec/filters/link_spec.rb
Expand Up @@ -8,7 +8,7 @@

it 'should transform URL to HTML links with html options' do
auto_html("http://vukajlija.com") do |auto|
auto.link :html_options => {:rel => "nofollow", :target => "_blank"}
auto.link :rel => "nofollow", :target => "_blank"
end.
should == '<a href="http://vukajlija.com" rel="nofollow" target="_blank">http://vukajlija.com</a>'
end
Expand Down

0 comments on commit 45d6879

Please sign in to comment.