Class: Vivlio::Starter::CLI::TocCommands::TocDocumentBuilder::ListState
- Inherits:
-
Object
- Object
- Vivlio::Starter::CLI::TocCommands::TocDocumentBuilder::ListState
- Defined in:
- lib/vivlio/starter/cli/toc.rb
Overview
<ul>/<li> の入れ子状態を管理する
Constant Summary collapse
- BASE_LEVEL =
1
Instance Method Summary collapse
-
#initialize(buffer) ⇒ ListState
constructor
A new instance of ListState.
-
#open_item(markup) ⇒ Object
<li> を開いてバッファへ追加する.
-
#prepare_for_postface ⇒ Object
後書き追加前に未閉じのリストを畳む.
-
#transition_to(level) ⇒ Object
指定レベルまでのネスト状態を調整する.
Constructor Details
#initialize(buffer) ⇒ ListState
Returns a new instance of ListState.
211 212 213 214 215 |
# File 'lib/vivlio/starter/cli/toc.rb', line 211 def initialize(buffer) @buffer = buffer @current_level = BASE_LEVEL @item_open = false end |
Instance Method Details
#open_item(markup) ⇒ Object
<li> を開いてバッファへ追加する
232 233 234 235 |
# File 'lib/vivlio/starter/cli/toc.rb', line 232 def open_item(markup) buffer << markup @item_open = true end |
#prepare_for_postface ⇒ Object
後書き追加前に未閉じのリストを畳む
238 239 240 241 242 243 244 |
# File 'lib/vivlio/starter/cli/toc.rb', line 238 def prepare_for_postface close_current_item while current_level > BASE_LEVEL buffer << "</ul>\n</li>\n" @current_level -= 1 end end |
#transition_to(level) ⇒ Object
指定レベルまでのネスト状態を調整する
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/vivlio/starter/cli/toc.rb', line 218 def transition_to(level) if level > current_level (level - current_level).times { buffer << "\n<ul>\n" } @item_open = false elsif level < current_level close_current_item (current_level - level).times { buffer << "</ul>\n</li>\n" } else close_current_item end @current_level = level end |