Class: PointBlank::DOM::DOMObject
- Inherits:
 - 
      Object
      
        
- Object
 - PointBlank::DOM::DOMObject
 
 
- Includes:
 - Enumerable
 
- Defined in:
 - lib/mmmd/blankshell.rb
 
Overview
DOM Object
Direct Known Subclasses
Block, HorizontalRule, InlineAutolink, InlineBreak, InlineFormattable, InlinePre, InlineRoot, LeafBlock, OLBlock, Paragraph, TempText, Text, ULBlock
Class Attribute Summary collapse
- 
  
    
      .parser  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute parser.
 - 
  
    
      .scanner  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute scanner.
 - 
  
    
      .unsorted_children  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute unsorted_children.
 - 
  
    
      .unsorted_overlays  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute unsorted_overlays.
 
Instance Attribute Summary collapse
- 
  
    
      #content  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute content.
 - 
  
    
      #parent  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute parent.
 - 
  
    
      #parser  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute parser.
 - 
  
    
      #position  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute position.
 - 
  
    
      #properties  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute properties.
 - 
  
    
      #temp_children  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute temp_children.
 
Class Method Summary collapse
- 
  
    
      .define_child(child, priority = 9999)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Define valid child for this DOMObject class.
 - 
  
    
      .define_overlay(overlay, priority = 9999)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Define an overlay - a parsing strategy that occurs once a block is closed.
 - 
  
    
      .define_parser(parser)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Define self parser for this DOMObject class.
 - 
  
    
      .define_scanner(scanner)  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Define child element scanner for this DOMObject class.
 - 
  
    
      .inherited(subclass)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Make subclasses inherit scanner and valid children.
 - 
  
    
      .parse(doc)  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Parse a document.
 - 
  
    
      .sort_children  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Sort children by priority.
 - 
  
    
      .sort_overlays  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Sort overlays by priority.
 - 
  
    
      .upsource  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Source parameters from parent (fixes recursive dependency).
 - 
  
    
      .valid_children  ⇒ Array<Class> 
    
    
  
  
  
  
  
  
  
  
  
    
Get array of valid children sorted by priority.
 - 
  
    
      .valid_overlays  ⇒ Array<::PointBlank::Parsing::NullOverlay> 
    
    
  
  
  
  
  
  
  
  
  
    
Get array of valid overlays sorted by priority.
 
Instance Method Summary collapse
- 
  
    
      #[](index)  ⇒ DOMObject 
    
    
  
  
  
  
  
  
  
  
  
    
Get element at position.
 - 
  
    
      #[]=(index, element)  ⇒ DOMObject 
    
    
  
  
  
  
  
  
  
  
  
    
Set element at position.
 - 
  
    
      #append_child(child)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Append child.
 - 
  
    
      #append_temp_child(child)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Append temp child.
 - 
  
    
      #children  ⇒ Array<DOMObject> 
    
    
  
  
  
  
  
  
  
  
  
    
Return an array duplicate of all children.
 - 
  
    
      #each(&block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Iterate over each child of DOMObject.
 - 
  
    
      #initialize  ⇒ DOMObject 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of DOMObject.
 - 
  
    
      #root  ⇒ ::PointBlank::DOM::DOMObject 
    
    
  
  
  
  
  
  
  
  
  
    
Get root element containing this child.
 
Constructor Details
#initialize ⇒ DOMObject
Returns a new instance of DOMObject.
      1590 1591 1592 1593 1594 1595  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1590 def initialize @children = [] @temp_children = [] @properties = {} @content = "" end  | 
  
Class Attribute Details
.parser ⇒ Object
Returns the value of attribute parser.
      1583 1584 1585  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1583 def parser @parser end  | 
  
.scanner ⇒ Object
Returns the value of attribute scanner.
      1583 1584 1585  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1583 def scanner @scanner end  | 
  
.unsorted_children ⇒ Object
Returns the value of attribute unsorted_children.
      1583 1584 1585  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1583 def unsorted_children @unsorted_children end  | 
  
.unsorted_overlays ⇒ Object
Returns the value of attribute unsorted_overlays.
      1583 1584 1585  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1583 def @unsorted_overlays end  | 
  
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
      1654 1655 1656  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1654 def content @content end  | 
  
#parent ⇒ Object
Returns the value of attribute parent.
      1654 1655 1656  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1654 def parent @parent end  | 
  
#parser ⇒ Object
Returns the value of attribute parser.
      1654 1655 1656  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1654 def parser @parser end  | 
  
#position ⇒ Object
Returns the value of attribute position.
      1654 1655 1656  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1654 def position @position end  | 
  
#properties ⇒ Object
Returns the value of attribute properties.
      1654 1655 1656  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1654 def properties @properties end  | 
  
#temp_children ⇒ Object (readonly)
Returns the value of attribute temp_children.
      1655 1656 1657  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1655 def temp_children @temp_children end  | 
  
Class Method Details
.define_child(child, priority = 9999) ⇒ void
This method returns an undefined value.
Define valid child for this DOMObject class
      1512 1513 1514 1515  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1512 def define_child(child, priority = 9999) @unsorted_children ||= [] @unsorted_children.append([child, priority]) end  | 
  
.define_overlay(overlay, priority = 9999) ⇒ void
This method returns an undefined value.
Define an overlay - a parsing strategy that occurs once a block is closed. May transform block if #process method of the overlay class returns a class.
      1537 1538 1539 1540  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1537 def (, priority = 9999) @unsorted_overlays ||= [] @unsorted_overlays.append([, priority]) end  | 
  
.define_parser(parser) ⇒ void
This method returns an undefined value.
Define self parser for this DOMObject class
      1527 1528 1529 1530  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1527 def define_parser(parser) parser.parser_for = self @parser = parser end  | 
  
.define_scanner(scanner) ⇒ void
This method returns an undefined value.
Define child element scanner for this DOMObject class
      1520 1521 1522  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1520 def define_scanner(scanner) @scanner = scanner end  | 
  
.inherited(subclass) ⇒ Object
Make subclasses inherit scanner and valid children
      1495 1496 1497 1498 1499 1500  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1495 def inherited(subclass) subclass.parser ||= @parser subclass.scanner ||= @scanner subclass.unsorted_children ||= @unsorted_children.dup || [] super(subclass) end  | 
  
.parse(doc) ⇒ self
Parse a document
      1551 1552 1553 1554 1555 1556  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1551 def parse(doc) newdoc = new newdoc.parser = parser.new scan = @scanner.new(doc, newdoc) scan.scan end  | 
  
.sort_children ⇒ void
This method returns an undefined value.
Sort children by priority
      1504 1505 1506 1507  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1504 def sort_children @valid_children = @unsorted_children&.sort_by(&:last)&.map(&:first) || [] end  | 
  
.sort_overlays ⇒ void
This method returns an undefined value.
Sort overlays by priority
      1544 1545 1546 1547  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1544 def @valid_overlays = @unsorted_overlays&.sort_by(&:last)&.map(&:first) || [] end  | 
  
.upsource ⇒ Object
Source parameters from parent (fixes recursive dependency)
      1559 1560 1561 1562 1563 1564 1565 1566 1567  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1559 def upsource superclass&.tap do |sc| @scanner = sc.scanner @parser = sc.parser @unsorted_children = sc.unsorted_children.dup @unsorted_overlays = sc..dup end sort_children end  | 
  
.valid_children ⇒ Array<Class>
Get array of valid children sorted by priority
      1578 1579 1580 1581  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1578 def valid_children sort_children unless @valid_children @valid_children end  | 
  
.valid_overlays ⇒ Array<::PointBlank::Parsing::NullOverlay>
Get array of valid overlays sorted by priority
      1571 1572 1573 1574  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1571 def unless @valid_overlays @valid_overlays end  | 
  
Instance Method Details
#[](index) ⇒ DOMObject
Get element at position
      1612 1613 1614  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1612 def [](index) @children[index] end  | 
  
#[]=(index, element) ⇒ DOMObject
Set element at position
      1601 1602 1603 1604 1605 1606 1607  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1601 def []=(index, element) unless element.is_a? ::PointBlank::DOM::DOMObject raise DOMError, "invalid DOM class #{element.class}" end @children[index] = element end  | 
  
#append_child(child) ⇒ Object
Append child
      1638 1639 1640 1641 1642 1643 1644 1645 1646  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1638 def append_child(child) unless child.is_a? ::PointBlank::DOM::DOMObject raise DOMError, "invalid DOM class #{child.class}" end child.parent = self child.position = @children.length @children.append(child) end  | 
  
#append_temp_child(child) ⇒ Object
Append temp child
      1650 1651 1652  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1650 def append_temp_child(child) @temp_children.append(child) end  | 
  
#children ⇒ Array<DOMObject>
Return an array duplicate of all children
      1624 1625 1626  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1624 def children @children.dup end  | 
  
#each(&block) ⇒ Object
Iterate over each child of DOMObject
      1618 1619 1620  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1618 def each(&block) @children.each(&block) end  | 
  
#root ⇒ ::PointBlank::DOM::DOMObject
Get root element containing this child
      1630 1631 1632 1633 1634  | 
    
      # File 'lib/mmmd/blankshell.rb', line 1630 def root current_root = self current_root = current_root.parent while current_root.parent current_root end  |