Sha256: 142540b01148bea96e27c4cea1479eaab1611f3f45b84b02254849b0f9b4c3ac
Contents?: true
Size: 1 KB
Versions: 1
Compression:
Stored size: 1 KB
Contents
module AutoHtmlFor # default options that can be overridden on the global level @@auto_html_for_options = { :htmlized_attribute_suffix => '_html' } mattr_reader :auto_html_for_options def self.included(base) base.extend(ClassMethods) end module ClassMethods def auto_html_for(raw_attrs, &proc) include AutoHtmlFor::InstanceMethods suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix] ([raw_attrs].flatten.map { |a| "#{a}#{suffix}" } - self.column_names).each do |missing_cache_column| attr_accessor missing_cache_column end [raw_attrs].flatten.each do |raw_attr| define_method("#{raw_attr}=") do |val| self[raw_attr] = val result = auto_html(val, &proc) if result.respond_to?(:html_safe) result = result.html_safe end self.send("#{raw_attr}#{suffix}=", result) val end end end end module InstanceMethods include AutoHtml end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
auto_html-1.5.2 | lib/auto_html/auto_html_for.rb |