Module: ActiveModel::Typograf

Included in:
ActiveRecord::Base
Defined in:
lib/active_model/typograf.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#typograf(column_name, options) ⇒ Object #typograf(column1, column2, ..., options) ⇒ Object #typograf(columns_with_options) ⇒ Object

Specify columns to typograf

Overloads:

  • #typograf(column_name, options) ⇒ Object

    Typograf only specified column with specified or default options

    Examples:

    typograf column with default options

    typograf :content # will typograf +content+ with default AlsTypograf options

    typograf column with custom options

    typograf :title, :use_br => false # will typograf +title+ without replacing +\n+ with <br />

    Parameters:

    • column_name (String, Symbol)

      name of the column to typograf

    • options (Hash)

      custom options to AlsTypograf#process method

  • #typograf(column1, column2, ..., options) ⇒ Object

    Typograf every specified columns with default options

    Examples:

    typograf columns with common custom options

    typograf :skills, :achievements, :description, :encoding => 'CP1251'

    Parameters:

    • column1 (String, Symbol)

      first column name

    • column2 (String, Symbol)

      next column name

    • ... (String, Symbol)

      specify all columns, you need

    • options (Hash)

      options to AlsTypograf#process method for all specified fields

  • #typograf(columns_with_options) ⇒ Object

    Typograf specified columns with specified options

    Examples:

    typograf specified columns with specified options

    typograf :foo => {:use_br => false}, :bar => {:use_p => false}

    Parameters:

    • columns_with_options (Hash)

      column names with correspond options to AlsTypograf#process method



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_model/typograf.rb', line 39

def typograf(*columns)
  unless respond_to?(:typograf_fields)
    cattr_accessor :typograf_fields
    self.typograf_fields = {}
    before_validation :typograf_current_fields
    include InstanceMethods
  end

  common_options = columns.extract_options!
  if columns == [] # There was an columns_with_options variant
    common_options.each do |column, custom_options|
      typograf_fields[column.to_sym] = custom_options
    end
  else
    columns.each do |column|
      typograf_fields[column.to_sym] = common_options
    end
  end
end