Sha256: 02d599aa64733fc223a250b540e3e0430a32ac27847e7ea159a79b6e1b47c64d

Contents?: true

Size: 948 Bytes

Versions: 1

Compression:

Stored size: 948 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::Helpers.send(:include, DomFor)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dom_for-1.0.0 lib/dom_for.rb