Sha256: 5fa48313f85a07e7042784af8247b898e45b8af378bb496b506d6361bfdf7eba

Contents?: true

Size: 945 Bytes

Versions: 2

Compression:

Stored size: 945 Bytes

Contents

require 'active_support/dependencies/autoload'

module DomFor
  #
  # dom_for Project do
  #
  #   dom_for Task do
  #     dom_for task, attribute: 'yes'
  #
  #   dom_for User do
  #     dom_for user, admin: false
  #
  #   dom_for Comment do
  #     dom_for comment, private: true
  #
  extend ActiveSupport::Autoload

  autoload :Model
  autoload :Record

  include Model
  include Record

  #
  # Creates a div tag with the attributes for the model or record of ActiveRecord
  #
  # @param [ActiveRecord::Base, Class] object Model or record of ActiveRecord
  # @param [Hash] attrs Additional attributes for the record
  # @param [Proc] block Block for a div tag
  #
  # @return [String] Sanitized HTML string
  #
  def dom_for(object, attrs={}, &block)
    if object.instance_of? Class
      dom_for_model(object, attrs, &block)
    else
      dom_for_record(object, attrs, &block)
    end
  end

end

ActionView::Base.send(:include, DomFor)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dom_for-1.0.2 lib/dom_for.rb
dom_for-1.0.1 lib/dom_for.rb