Class: Arbre::HTML::Tag

Inherits:
Element show all
Defined in:
lib/active_admin/arbre/tag.rb

Direct Known Subclasses

Document, P, Table

Constant Summary

Constants included from Arbre::HTML

AUTO_BUILD_ELEMENTS, HTML5_ELEMENTS

Instance Attribute Summary collapse

Attributes inherited from Element

#children, #parent

Instance Method Summary collapse

Methods inherited from Element

#+, #<<, #add_child, #assigns, builder_method, #content, #content=, #document, #each, #get_elements_by_tag_name, #helpers, #html_safe, #indent_level, #parent?, #remove_child, #tag_name, #to_ary, #to_s, #to_str

Methods included from BuilderMethods

#build_tag, #current_dom_context, #insert_tag, #insert_text_node_if_string, #with_current_dom_context

Methods included from Arbre::HTML

#current_dom_context, #helpers, #method_missing

Constructor Details

#initializeTag

Returns a new instance of Tag.



9
10
11
12
# File 'lib/active_admin/arbre/tag.rb', line 9

def initialize(*)
  super
  @attributes = Attributes.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Arbre::HTML

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/active_admin/arbre/tag.rb', line 7

def attributes
  @attributes
end

Instance Method Details

#add_class(class_names) ⇒ Object



58
59
60
# File 'lib/active_admin/arbre/tag.rb', line 58

def add_class(class_names)
  class_list.add class_names
end

#build(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_admin/arbre/tag.rb', line 14

def build(*args)
  super
  attributes = args.extract_options!
  self.content = args.first if args.first

  set_for_attribute(attributes.delete(:for))

  attributes.each do |key, value|
    set_attribute(key, value)
  end
end

#class_listObject



71
72
73
# File 'lib/active_admin/arbre/tag.rb', line 71

def class_list
  get_attribute(:class) || set_attribute(:class, ClassList.new)
end

#class_namesObject

Returns a string of classes



67
68
69
# File 'lib/active_admin/arbre/tag.rb', line 67

def class_names
  class_list.to_html
end

#get_attribute(name) ⇒ Object Also known as: attr



30
31
32
# File 'lib/active_admin/arbre/tag.rb', line 30

def get_attribute(name)
  @attributes[name.to_sym]
end

#has_attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/active_admin/arbre/tag.rb', line 35

def has_attribute?(name)
  @attributes.has_key?(name.to_sym)
end

#idObject



43
44
45
# File 'lib/active_admin/arbre/tag.rb', line 43

def id
  get_attribute(:id)
end

#id!Object

Generates and id for the object if it doesn’t exist already



48
49
50
51
52
# File 'lib/active_admin/arbre/tag.rb', line 48

def id!
  return id if id
  self.id = object_id.to_s
  id
end

#id=(id) ⇒ Object



54
55
56
# File 'lib/active_admin/arbre/tag.rb', line 54

def id=(id)
  set_attribute(:id, id)
end

#remove_attribute(name) ⇒ Object



39
40
41
# File 'lib/active_admin/arbre/tag.rb', line 39

def remove_attribute(name)
  @attributes.delete(name.to_sym)
end

#remove_class(class_names) ⇒ Object



62
63
64
# File 'lib/active_admin/arbre/tag.rb', line 62

def remove_class(class_names)
  class_list.delete(class_names)
end

#set_attribute(name, value) ⇒ Object



26
27
28
# File 'lib/active_admin/arbre/tag.rb', line 26

def set_attribute(name, value)
  @attributes[name.to_sym] = value
end

#to_htmlObject



75
76
77
# File 'lib/active_admin/arbre/tag.rb', line 75

def to_html
  indent("<#{tag_name}#{attributes_html}>", content, "</#{tag_name}>").html_safe
end