Class: Agio::HTMLElementDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/agio/html_element_description.rb

Overview

Agio::HTMLElementDescription is a wrapper around Nokogiri::HTML::ElementDescription to work around a bug with LibXML2 prior to 2.7.7. In HTMLParser.c, the #define of INLINE didn’t have commas, meaning that strings were concatenated instead of forming an array (e.g., what should have been [ "small", "em" ] ended up being [ "smallem" ]). This was fixed in libxml2 commit 4b41f15d… on 20 January 2010 by Eugene Pimenov.

Nokogiri includes a DefaultDescription hash that contains the same basic information, so we will use that (with appropriate wrappers) if the version of LibXML2 is not sufficient to have this bug fixed.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(desc) ⇒ HTMLElementDescription

Returns a new instance of HTMLElementDescription.



55
56
57
58
59
# File 'lib/agio/html_element_description.rb', line 55

def initialize(desc)
  @d = desc
  @name = name.downcase
  @d = Nokogiri::HTML::ElementDescription::DefaultDescriptions[@name]
end

Class Method Details

.[](name) ⇒ Object



26
27
28
# File 'lib/agio/html_element_description.rb', line 26

def self.[](name)
  Nokogiri::HTML::ElementDescription[name]
end

Instance Method Details

#block?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/agio/html_element_description.rb', line 77

def block?
  !inline?
end

#default_sub_elementObject



109
110
111
# File 'lib/agio/html_element_description.rb', line 109

def default_sub_element
  @d ? @d.defaultsubelt : nil
end

#deprecated?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/agio/html_element_description.rb', line 101

def deprecated?
  @d ? @d.depr : nil
end

#deprecated_attributesObject



117
118
119
# File 'lib/agio/html_element_description.rb', line 117

def deprecated_attributes
  @d ? @d.attrs_depr : []
end

#descriptionObject



105
106
107
# File 'lib/agio/html_element_description.rb', line 105

def description
  @d ? @d.desc : nil
end

#empty?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/agio/html_element_description.rb', line 85

def empty?
  @d ? @d.empty : nil
end

#implied_end_tag?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/agio/html_element_description.rb', line 93

def implied_end_tag?
  @d ? @d.endTag : nil
end

#implied_start_tag?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/agio/html_element_description.rb', line 89

def implied_start_tag?
  @d ? @d.startTag : nil
end

#inline?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/agio/html_element_description.rb', line 81

def inline?
  @d ? @d.isinline : nil
end

#inspectObject



69
70
71
# File 'lib/agio/html_element_description.rb', line 69

def inspect
  "#<#{self.class.name}: #{name} #{description}>"
end

#nameObject



61
62
63
# File 'lib/agio/html_element_description.rb', line 61

def name
  @d ? @d.name : @name
end

#optional_attributesObject



113
114
115
# File 'lib/agio/html_element_description.rb', line 113

def optional_attributes
  @d ? @d.attrs_opt : []
end

#required_attributesObject



121
122
123
# File 'lib/agio/html_element_description.rb', line 121

def required_attributes
  @d ? @d.attrs_req : []
end

#save_end_tag?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/agio/html_element_description.rb', line 97

def save_end_tag?
  @d ? @d.saveEndTag : nil
end

#sub_elementsObject



73
74
75
# File 'lib/agio/html_element_description.rb', line 73

def sub_elements
  @d ? @d.subelts : []
end

#to_sObject



65
66
67
# File 'lib/agio/html_element_description.rb', line 65

def to_s
  "#{name}: #{description}"
end