Class: VivlioStarter::CLI::TocCommands::TocDocumentBuilder::ListState
- Inherits:
-
Object
- Object
- VivlioStarter::CLI::TocCommands::TocDocumentBuilder::ListState
- Defined in:
- lib/vivlio_starter/cli/toc.rb
Overview
- /
- の入れ子状態を管理する
Constant Summary collapse
- BASE_LEVEL =
1
Instance Method Summary collapse
-
#initialize(buffer) ⇒ ListState
constructor
A new instance of ListState.
-
#open_item(markup) ⇒ Object
- を開いてバッファへ追加する.
-
#prepare_for_postface ⇒ Object
後書き追加前に未閉じのリストを畳む.
-
#transition_to(level) ⇒ Object
指定レベルまでのネスト状態を調整する.
Constructor Details
#initialize(buffer) ⇒ ListState
Returns a new instance of ListState.
225 226 227 228 229 |
# File 'lib/vivlio_starter/cli/toc.rb', line 225 def initialize(buffer) @buffer = buffer @current_level = BASE_LEVEL @item_open = false end |
Instance Method Details
#open_item(markup) ⇒ Object
246 247 248 249 |
# File 'lib/vivlio_starter/cli/toc.rb', line 246 def open_item(markup) buffer << markup @item_open = true end |
#prepare_for_postface ⇒ Object
後書き追加前に未閉じのリストを畳む
252 253 254 255 256 257 258 |
# File 'lib/vivlio_starter/cli/toc.rb', line 252 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
指定レベルまでのネスト状態を調整する
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/vivlio_starter/cli/toc.rb', line 232 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 |