Class: JsDuck::HtmlStack
- Inherits:
-
Object
- Object
- JsDuck::HtmlStack
- Defined in:
- lib/jsduck/html_stack.rb
Overview
Tracks opening and closing of HTML tags, with the purpose of closing down the unfinished tags.
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:
13 14 15 16 17 |
# File 'lib/jsduck/html_stack.rb', line 13 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.
25 26 27 28 29 30 31 |
# File 'lib/jsduck/html_stack.rb', line 25 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.
20 21 22 |
# File 'lib/jsduck/html_stack.rb', line 20 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.
40 41 42 |
# File 'lib/jsduck/html_stack.rb', line 40 def open?(tag) @open_tags.include?(tag) end |
#push_tag(tag) ⇒ Object
Registers opening of a tag. Returns the tag.
34 35 36 37 |
# File 'lib/jsduck/html_stack.rb', line 34 def push_tag(tag) @open_tags.push(tag) unless void?(tag) tag end |