module RedCloth::ActiveModelDecorator

Public Class Methods

define_proper_methods_on(name) click to toggle source

nodoc

# File lib/redcloth_on.rb, line 29
def self.define_proper_methods_on(name)

  solve_value = (name.to_s + "_attribute").to_sym

  define_method(name) do
    RedCloth.new(self.send(solve_value)).to_html
  end

  define_method(solve_value) do
    qt = attributes[name.to_s]
    qt.nil? ? "" : qt
  end

  define_method("old_" + name.to_s) do
    attributes[name.to_s]
  end

end
included(base) click to toggle source
# File lib/redcloth_on.rb, line 4
def self.included(base)

  base.class_eval do

    #
    # USAGE:
    #
    # class Person
    #   redcloth_on [:name, :last_name]
    # end
    #
    # and those attributes will be decorated by RedCloth
    #


    def self.redcloth_on(attributes_array=[])
      attributes_array.each{|a| define_proper_methods_on(a) }
    end

    private

    #
    # nodoc
    #

    def self.define_proper_methods_on(name)

      solve_value = (name.to_s + "_attribute").to_sym

      define_method(name) do
        RedCloth.new(self.send(solve_value)).to_html
      end

      define_method(solve_value) do
        qt = attributes[name.to_s]
        qt.nil? ? "" : qt
      end

      define_method("old_" + name.to_s) do
        attributes[name.to_s]
      end

    end
  end
end
redcloth_on(attributes_array=[]) click to toggle source

USAGE:

class Person

redcloth_on [:name, :last_name]

end

and those attributes will be decorated by RedCloth

# File lib/redcloth_on.rb, line 19
def self.redcloth_on(attributes_array=[])
  attributes_array.each{|a| define_proper_methods_on(a) }
end