Class: PageBuilder::Document
- Inherits:
-
Nokogiri::HTML::Document
- Object
- Nokogiri::HTML::Document
- PageBuilder::Document
- Extended by:
- Forwardable
- Defined in:
- lib/pagebuilder/document.rb
Overview
Adds helper methods to the standard Nokogiri HTML document and forces an html5 doctype.
Class Method Summary collapse
Instance Method Summary collapse
- #add_script(uri, **attributes) ⇒ Object
-
#base_uri ⇒ String|nil
Returns the base uri set for the document if there is one.
-
#base_uri=(uri) ⇒ void
Sets the base uri for the document, reuses the same <base> tag if one exists.
-
#body ⇒ PageBuilder::Elements::Basic
Gets the body node for the document.
-
#head ⇒ PageBuilder::Elements::Basic
Gets the head node for the document.
- #remove_script(uri) ⇒ Object
-
#to_html(*options) ⇒ Object
Add managed nodes and then convert to html.
Class Method Details
.new ⇒ Object
18 19 20 21 22 |
# 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 |
Instance Method Details
#add_script(uri, **attributes) ⇒ Object
16 |
# File 'lib/pagebuilder/document.rb', line 16 def_delegators :script_manager, :add_script, :remove_script |
#base_uri ⇒ String|nil
Returns the base uri set for the document if there is one
26 27 28 |
# File 'lib/pagebuilder/document.rb', line 26 def base_uri @base&.attr('href') end |
#base_uri=(uri) ⇒ void
This method returns an undefined value.
Sets the base uri for the document, reuses the same <base> tag if one exists
33 34 35 36 |
# 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 ⇒ PageBuilder::Elements::Basic
Gets the body node for the document
40 41 42 |
# File 'lib/pagebuilder/document.rb', line 40 def body @body ||= head.add_next_sibling(Elements::Basic.new('body', self)) end |
#head ⇒ PageBuilder::Elements::Basic
Gets the head node for the document
46 47 48 |
# File 'lib/pagebuilder/document.rb', line 46 def head @head ||= at('/html').add_child(Elements::Basic.new('head', self)) end |
#remove_script(uri) ⇒ Object
16 |
# File 'lib/pagebuilder/document.rb', line 16 def_delegators :script_manager, :add_script, :remove_script |
#to_html(*options) ⇒ Object
Add managed nodes and then convert to html
52 53 54 55 |
# File 'lib/pagebuilder/document.rb', line 52 def to_html(*) @script_manager.(body) if @script_manager super end |