Hi all,
I am writing a plugin with some view helpers. The helper method uses a
class internally to define the behaviour, but I can''t use content_tag
with a block inside that class.
This is the following code:
module Microformat
module ViewHelpers
# User will type:
# <% geo_for location, "Location:", :geo_tag => :div,
:internal_tag
=> :span do |g| %>
# <% g.latitude "Latitude: #{location.latitude}, " %>
# <% g.longitude "Longitude: #{location.longitude}" %>
# <% end %>
# Output
# <div class="geo">GEO:
# <span class="latitude">342.386013</span>,
# <span class="longitude">-90.082932</span>
# </div>
def geo_for(object, text, options = {}, &proc)
raise ArgumentError, "Missing block" unless block_given?
containing_tag = options.delete(:tag) || :div
internal_tag = options.delete(:internal_tag) || :span
concat(tag(containing_tag, { :class => "geo" }, true),
proc.binding)
concat(text, proc.binding)
yield MicroformatCreator::GeoInternal.new(internal_tag, object)
concat("</#{containing_tag}>", proc.binding)
end
end
module MicroformatCreator
class InvalidMicroformatField < StandardError
end
class Microformat
include ActionView::Helpers::TagHelper
def initialize(tag, object)
@internal_tag, @object = tag, object
end
def method_missing(name, *args)
raise InvalidMicroformatField, "The field #{name} does not
exist" unless
@object.attribute_names.include?(name.to_s)
text = args.pop
content_tag @internal_tag, :class => name do
text unless text.nil?
end
end
end
class GeoInternal < Microformat
end
end
end
The error happens with the content_tag of method_missing of the
Microformat class, the exact message is ''The field capture does not
exist'' and the module Microformat::ViewHelpers its included to
ActionView::Base when the plugin loads. content_tag as I''ve said works
if it is not passed a block.
Any ideas on how to get working content_tag in this situation would be
great!
Thanks,
Alan
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---