Help putting this code into plugin


#1

Hi,

I have the following code that allows me to call before_validation
:acts_as_tagless in my models.

I would like to put this into aplugin so I can do somthing like
acts_as_tagless :fieldName, :fieldName, :etc

any suggestions on where to start?

Thanks,
Scot

#
#removes html tags
def acts_as_tagless

    string_attributes = {}
    self.attributes.each do |each_name, each_attribute|
        if each_attribute.kind_of? String
          string_attributes[each_name] = strip_tags(each_attribute)
        end
    end
    self.attributes = string_attributes

end

#strip_tags function taken from ActionView
def self.strip_tags(html)
    if html.index("<")
        text = ""
        tokenizer = HTML::Tokenizer.new(html)

        while token = tokenizer.next
            node = HTML::Node.parse(nil, 0, 0, token, false)
            # result is only the content of any Text nodes
            text << node.to_s if node.class == HTML::Text
        end
            # strip any comments, and if they have a newline at the

end (ie. line with
# only a comment) strip that too
text.gsub(/[\n]?/m, “”)
else
html # already plain text
end
end