Module: Wedge::HTML

Includes:
Methods
Defined in:
lib/wedge/html.rb

Defined Under Namespace

Classes: DSL

Constant Summary collapse

INDENT =
'  '
TAGS =
%w{a button abbr acronym address applet area article aside audio b base basefont bdi
bdo big blockquote body br canvas caption center cite code col colgroup command
datalist dd del details dfn dialog dir div dl dt em embed fieldset figcaption
figure font footer form frame frameset h1 head header hgroup hr html i iframe
img input ins kbd keygen label legend li link map mark menu meta meter nav noframes
noscript object ol optgroup option output p param pre progress q rp rt ruby s samp
script section select small source span strike strong style sub summary sup table tbody
td textarea tfoot th thead time title tr track tt u ul var video wbr}

Class Method Summary collapse

Methods included from Methods

#client?, included, #server?

Class Method Details

.[](raw_html) ⇒ Object

Parse HTML into a Nokogiri object

Parameters:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wedge/html.rb', line 11

def [](raw_html)
  return unless server?

  # remove all the starting and trailing whitespace
  raw_html = raw_html.strip

  if raw_html[/\A<!DOCTYPE/] || raw_html[/\A<html/]
    Nokogiri::HTML(raw_html)
  else
    parsed_html = Nokogiri::HTML.fragment(raw_html)

    if parsed_html.children.length >= 1
      parsed_html.children.first
    else
      parsed_html
    end
  end
end