Skip to content

Commit

Permalink
Check whether last arg is a Hash instead of duck-typing against []
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Nov 8, 2008
1 parent aaa2abf commit 07fe337
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions actionpack/lib/action_view/helpers/atom_feed_helper.rb
@@ -1,3 +1,5 @@
require 'set'

# Adds easy defaults to writing Atom feeds with the Builder template engine (this does not work on ERb or any other
# template languages).
module ActionView
Expand Down Expand Up @@ -121,6 +123,8 @@ def atom_feed(options = {}, &block)
end

class AtomBuilder
XHTML_TAG_NAMES = %w(content rights title subtitle summary).to_set

def initialize(xml)
@xml = xml
end
Expand All @@ -140,14 +144,15 @@ def method_missing(method, *arguments, &block)
@xml.__send__(method, *arguments, &block)
end
end

# True if the method name matches one of the five elements defined
# in the Atom spec as potentially containing XHTML content and
# if :type => 'xhtml' is, in fact, specified.
def xhtml_block?(method, arguments)
%w( content rights title subtitle summary ).include?(method.to_s) &&
arguments.last.respond_to?(:[]) &&
arguments.last[:type].to_s == 'xhtml'
if XHTML_TAG_NAMES.include?(method.to_s)
last = arguments.last
last.is_a?(Hash) && last[:type].to_s == 'xhtml'
end
end
end

Expand Down

0 comments on commit 07fe337

Please sign in to comment.