Module: DomFor

Includes:
Model, Record
Defined in:
lib/dom_for.rb,
lib/dom_for/model.rb,
lib/dom_for/record.rb,
lib/dom_for/railtie.rb,
lib/dom_for/version.rb

Defined Under Namespace

Modules: Model, Record Classes: Railtie

Constant Summary collapse

VERSION =
'1.2.0'

Instance Method Summary collapse

Instance Method Details

#dom_for(object, attrs = {}, &block) ⇒ String

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

Parameters:

  • object (ActiveRecord::Base, Class)

    Model or record of ActiveRecord

  • attrs (Hash) (defaults to: {})

    Additional attributes for the record

  • block (Proc)

    Block for a div tag

Returns:

  • (String)

    Sanitized HTML string



30
31
32
33
34
35
36
37
38
39
# File 'lib/dom_for.rb', line 30

def dom_for(object, attrs = {}, &block)
  tag   = attrs.delete(:tag) || :div
  klass = attrs.delete(:class)

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