Skip to content

Commit

Permalink
supporting root element in xml rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Oct 24, 2010
1 parent e5e21db commit d4bb2f6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/restfulie/common/converter/xml/base.rb
Expand Up @@ -45,7 +45,7 @@ def to_xml(obj, options = {}, &block)
end

# Create representation and proxy
builder = Builder.new(obj)
builder = Builder.new(obj, options)

# Check recipe arity size before calling it
recipe.call(*[builder, obj, options][0,recipe.arity])
Expand Down
5 changes: 3 additions & 2 deletions lib/restfulie/common/converter/xml/builder.rb
Expand Up @@ -42,11 +42,12 @@ def link(relationship, uri, options = {})
insert_value("link", nil, options)
end

def members(a_collection = nil, &block)
def members(a_collection = nil, options = {}, &block)
collection = a_collection || @obj
raise Error::BuilderError("Members method require a collection to execute") unless collection.respond_to?(:each)
collection.each do |member|
entry = @doc.create_element(Restfulie::Common::Converter.root_element_for(member))
root = options[:root] || Restfulie::Common::Converter.root_element_for(member)
entry = @doc.create_element(root)
entry.parent = @parent
@parent = entry
block.call(self, member)
Expand Down
8 changes: 4 additions & 4 deletions lib/restfulie/common/converter/xml/helpers.rb
Expand Up @@ -3,12 +3,12 @@ module Common
module Converter
module Xml
module Helpers
def collection(obj, *args, &block)
Xml.to_xml(obj, {}, &block)
def collection(obj, opts = {}, &block)
Xml.to_xml(obj, opts, &block)
end

def member(obj, *args, &block)
Xml.to_xml(obj, {}, &block)
def member(obj, opts = {}, &block)
Xml.to_xml(obj, opts, &block)
end
end
end
Expand Down

0 comments on commit d4bb2f6

Please sign in to comment.