Module: Ronin::Support::Web::HTML

Defined in:
lib/ronin/support/web/html.rb,
lib/ronin/support/web/html/mixin.rb

Overview

HTML helper methods.

Defined Under Namespace

Modules: Mixin

Class Method Summary collapse

Class Method Details

.build { ... } ⇒ Nokogiri::HTML::Builder

Creates a new Nokogiri::HTML::Builder.

Examples:

HTML.build do
  html {
    body {
      div(style: 'display:none;') {
        object(classid: 'blabla')
      }
    }
  }
end

Yields:

  • [] The block that will be used to construct the HTML document.

Returns:

  • (Nokogiri::HTML::Builder)

    The new HTML builder object.

See Also:



110
111
112
# File 'lib/ronin/support/web/html.rb', line 110

def self.build(&block)
  Nokogiri::HTML::Builder.new(&block)
end

.open(path) {|doc| ... } ⇒ Nokogiri::HTML::Document

Opens an HTML file.

Examples:

doc = HTML.open('index.html')
# => #<Nokogiri::HTML::Document:...>

Parameters:

  • path (String)

    The path to the HTML file.

Yields:

  • (doc)

    If a block is given, it will be passed the newly created document object.

Yield Parameters:

  • doc (Nokogiri::HTML::Document)

    The new HTML document object.

Returns:

  • (Nokogiri::HTML::Document)

    The parsed HTML file.

See Also:



80
81
82
83
84
# File 'lib/ronin/support/web/html.rb', line 80

def self.open(path)
  doc = Nokogiri::HTML(File.open(path))
  yield doc if block_given?
  return doc
end

.parse(html) {|doc| ... } ⇒ Nokogiri::HTML::Document

Parses the body of a document into a HTML document object.

Parameters:

  • html (String, IO)

    The HTML to parse.

Yields:

  • (doc)

    If a block is given, it will be passed the newly created document object.

Yield Parameters:

  • doc (Nokogiri::HTML::Document)

    The new HTML document object.

Returns:

  • (Nokogiri::HTML::Document)

    The new HTML document object.

See Also:



50
51
52
53
54
# File 'lib/ronin/support/web/html.rb', line 50

def self.parse(html)
  doc = Nokogiri::HTML.parse(html)
  yield doc if block_given?
  return doc
end