Class: PPZ::ParserContext
- Inherits:
-
Object
- Object
- PPZ::ParserContext
- Defined in:
- lib/doc/parser/context.rb
Overview
当前行,所处的上下文比如 一级 section 下面的 ul 下的 第 n 个 ul
Instance Method Summary collapse
- #append(target) ⇒ Object
- #head ⇒ Object
-
#initialize(root) ⇒ ParserContext
constructor
A new instance of ParserContext.
- #pop ⇒ Object
- #root ⇒ Object
Constructor Details
#initialize(root) ⇒ ParserContext
Returns a new instance of ParserContext.
5 6 7 |
# File 'lib/doc/parser/context.rb', line 5 def initialize root @stack = [root] end |
Instance Method Details
#append(target) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/doc/parser/context.rb', line 9 def append target # ContainerClass: 容器类,如果上级不是,就造一个 if(PPZ::Func::class_has_const? target, :ContainerClass) and (head.class != target.class::ContainerClass) append target.class::ContainerClass.new end # UpperClass: 上级类,如果上级不是,就出栈 if(PPZ::Func::class_has_const? target, :UpperClass) and (head.class != target.class::UpperClass) pop_to target.class::UpperClass end head.append target # 加入 model @stack.push target if target.is_a? PPZ::AbstractWrapperModel # 加入 stack end |
#head ⇒ Object
27 28 29 |
# File 'lib/doc/parser/context.rb', line 27 def head @stack[-1] end |
#pop ⇒ Object
23 24 25 |
# File 'lib/doc/parser/context.rb', line 23 def pop @stack.pop end |
#root ⇒ Object
31 32 33 |
# File 'lib/doc/parser/context.rb', line 31 def root @stack[0] end |