Module: HtmlTerminator::ClassMethods

Defined in:
lib/html_terminator.rb

Instance Method Summary collapse

Instance Method Details

#fieldsObject



21
22
23
24
25
26
27
28
29
# File 'lib/html_terminator.rb', line 21

def fields
  self.columns.inject([]) do |list, col|
    if col.type == :string or col.type == :text
      list << col.name.to_sym
    end

    list
  end
end

#terminate_html(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/html_terminator.rb', line 31

def terminate_html(*args)
  # object key/value of field => options
  unless method_defined?(:html_terminator_fields)
    class_attribute :html_terminator_fields
    self.html_terminator_fields = {}
  end

  options = args.extract_options!
  options = SANITIZE_OPTIONS.clone.merge(options)

  args.each do |field|
    self.html_terminator_fields[field] = options.deep_dup
  end

  unless self.html_terminator_fields.empty?
    before_validation :terminate_html

    # sanitize reads
    args.each do |attr|
      define_method(attr) do |*rargs|
        # sanitize it
        HtmlTerminator.sanitize super(*rargs), options
      end
    end
  end
end