Class: JsDuck::Format::HtmlStack
- Inherits:
-
Object
- Object
- JsDuck::Format::HtmlStack
- Defined in:
- lib/jsduck/format/html_stack.rb
Overview
Tracks opening and closing of HTML tags, with the purpose of closing down the unfinished tags.
See Format::Doc#replace for the use of this class.
Instance Method Summary collapse
-
#close(s) ⇒ Object
Scans a closing tag in HTML using the passed in StringScanner.
-
#initialize(ignore_html = {}, doc_context = {}) ⇒ HtmlStack
constructor
Initializes the stack with two optional parameters:.
-
#open(s) ⇒ Object
Scans an opening tag in HTML using the passed in StringScanner.
-
#open?(tag) ⇒ Boolean
True when the tag is currently open.
-
#push_tag(tag) ⇒ Object
Registers opening of a tag.
Constructor Details
#initialize(ignore_html = {}, doc_context = {}) ⇒ HtmlStack
Initializes the stack with two optional parameters:
16 17 18 19 20 |
# File 'lib/jsduck/format/html_stack.rb', line 16 def initialize(ignore_html={}, doc_context={}) @ignore_html = ignore_html @doc_context = doc_context @open_tags = [] end |
Instance Method Details
#close(s) ⇒ Object
Scans a closing tag in HTML using the passed in StringScanner.
28 29 30 31 32 33 34 |
# File 'lib/jsduck/format/html_stack.rb', line 28 def close(s) s.scan(/<\//) tag = s.scan(/\w+/) s.scan(/>/) (tag).map {|t| "</#{t}>" }.join end |
#open(s) ⇒ Object
Scans an opening tag in HTML using the passed in StringScanner.
23 24 25 |
# File 'lib/jsduck/format/html_stack.rb', line 23 def open(s) s.scan(/</) + push_tag(s.scan(/\w+/)) + s.scan_until(/>|\Z/) end |
#open?(tag) ⇒ Boolean
True when the tag is currently open.
43 44 45 |
# File 'lib/jsduck/format/html_stack.rb', line 43 def open?(tag) @open_tags.include?(tag) end |
#push_tag(tag) ⇒ Object
Registers opening of a tag. Returns the tag.
37 38 39 40 |
# File 'lib/jsduck/format/html_stack.rb', line 37 def push_tag(tag) @open_tags.push(tag) unless void?(tag) tag end |