Sha256: 77327e366f5df03cf45ad42b85e248fea89dd6f83096b0c2b32b36414ce52f54

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/string/inflections'

require_relative 'dom_for/model'
require_relative 'dom_for/record'

module DomFor
  include Model
  include Record
  #
  # 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
  #
  # Creates a html tag with the attributes for the model or record of ActiveRecord
  #
  # @param object [ActiveRecord::Base, Class] Model or record of ActiveRecord
  # @param attrs [Hash] Additional attributes for the record
  # @param block [Proc] Block for a div tag
  #
  # @return [String] Sanitized HTML string
  #
  def dom_for(object, attrs = {}, &block)
    tag = attrs.delete(:tag) || :div

    if object.instance_of? Class
      _dom_for_model(object, tag, attrs, &block)
    else
      _dom_for_record(object, tag, attrs, &block)
    end
  end
end

require_relative 'dom_for/railtie' if defined? ::Rails

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dom_for-1.1.0 lib/dom_for.rb