class PageBuilder::Document

Adds helper methods to the standard Nokogiri HTML document and forces an html5 doctype.

Public Class Methods

new() click to toggle source
# File lib/pagebuilder/document.rb, line 18
def self.new
  # This is the only way I've found so far to force the html5 doctype
  # It unfortunately also makes it so the initializer doesn't get called for JRuby
  parse('<!DOCTYPE html><html></html>')
end

Public Instance Methods

base_uri() click to toggle source

Returns the base uri set for the document if there is one @return [String|nil]

# File lib/pagebuilder/document.rb, line 26
def base_uri
  @base&.attr('href')
end
base_uri=(uri) click to toggle source

Sets the base uri for the document, reuses the same <base> tag if one exists @param uri [String] @return [void]

# File lib/pagebuilder/document.rb, line 33
def base_uri=(uri)
  @base ||= head.add_child(Elements::Basic.new('base', self))
  @base['href'] = uri
end
body() click to toggle source

Gets the body node for the document @return [PageBuilder::Elements::Basic]

# File lib/pagebuilder/document.rb, line 40
def body
  @body ||= head.add_next_sibling(Elements::Basic.new('body', self))
end
head() click to toggle source

Gets the head node for the document @return [PageBuilder::Elements::Basic]

# File lib/pagebuilder/document.rb, line 46
def head
  @head ||= at('/html').add_child(Elements::Basic.new('head', self))
end
to_html(*options) click to toggle source

Add managed nodes and then convert to html @see Nokogiri::HTML::Document#to_html

Calls superclass method
# File lib/pagebuilder/document.rb, line 52
def to_html(*options)
  @script_manager.append_tags(body) if @script_manager
  super
end

Private Instance Methods

script_manager() click to toggle source
# File lib/pagebuilder/document.rb, line 59
def script_manager
  @script_manager ||= ScriptManager.new
end