how about doing something like this logic
scan your content looking for "{" store everything until your next "}" into a string variable # now string = "test foo:foo bar bar:bar foo" split your string by spaces into an array # now array = ["test", "foo:foo", "bar", "bar:bar", "foo"]
loop through your array new_array = index = 0 array.each do |a| if a does not contain ":" index = index + 1 partial = a args = {} new_array[index] = [partial, args] else args = new_array[index][2] # should be a hash name, value = a.split(/:/) args[name.to_sym] = value # add new args to hash new_array[index][2] = args # store hash back into the array end end
# now new_array = [["foo", {foo => "foo"}], ["bar", {bar => "bar"}], ["foo", {}]] loop through this and render partials new_array.each do |a| partial = a[1] arguments = a[2] output << render(:partial => "drops/#{partial}", :locals => arguments) end
i am sure there are errors and bugs but i think the basic logic should work. it will probably turn out to be fairly clean and readable if refactored into a few methods.