Module: Ronn::Utils

Included in:
Document, RoffFilter
Defined in:
lib/ronn/utils.rb

Overview

Miscellaneous utilities.

Constant Summary collapse

HTML =

All HTML 4 elements and some that are in common use.

%w[
  a abbr acronym address applet area b base basefont bdo big blockquote body
  br button caption center cite code col colgroup dd del dfn dir div dl dt
  em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i
  iframe img input ins isindex kbd label legend li link map menu meta
  noframes noscript object ol optgroup option p param pre q s samp script
  select small span strike strong style sub sup table tbody td textarea
  tfoot th thead title tr tt u ul var
].to_set
HTML_BLOCK =

Block elements.

%w[
  blockquote body colgroup dd div dl dt fieldset form frame frameset
  h1 h2 h3 h4 h5 h6 hr head html iframe li noframes noscript
  object ol optgroup option p param pre script select
  style table tbody td textarea tfoot th thead title tr tt ul
].to_set
HTML_INLINE =

Inline elements

HTML - HTML_BLOCK
HTML_EMPTY =

Elements that don’t have a closing tag.

%w[area base basefont br col hr input link meta].to_set

Instance Method Summary collapse

Instance Method Details

#block_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/ronn/utils.rb', line 32

def block_element?(name)
  HTML_BLOCK.include?(name)
end

#child_of?(node, tag) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
# File 'lib/ronn/utils.rb', line 48

def child_of?(node, tag)
  while node
    return true if node.name && node.name.downcase == tag
    return false if node.document?
    node = node.parent
  end
  false
end

#empty_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ronn/utils.rb', line 40

def empty_element?(name)
  HTML_EMPTY.include?(name)
end

#html_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ronn/utils.rb', line 44

def html_element?(name)
  HTML.include?(name)
end

#inline_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ronn/utils.rb', line 36

def inline_element?(name)
  HTML_INLINE.include?(name)
end