Class: Markbridge::Parsers::BBCode::Handlers::SelfClosingHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Markbridge::Parsers::BBCode::Handlers::SelfClosingHandler
- Defined in:
- lib/markbridge/parsers/bbcode/handlers/self_closing_handler.rb
Overview
Handler for self-closing tags (br, hr, etc.)
Instance Attribute Summary collapse
-
#element_class ⇒ Object
readonly
Returns the value of attribute element_class.
Instance Method Summary collapse
-
#initialize(element_class) ⇒ SelfClosingHandler
constructor
A new instance of SelfClosingHandler.
- #on_close(token:, context:, registry:, tokens: nil) ⇒ Object
- #on_open(token:, context:, registry:, tokens: nil) ⇒ Object
Methods inherited from BaseHandler
Constructor Details
#initialize(element_class) ⇒ SelfClosingHandler
Returns a new instance of SelfClosingHandler.
9 10 11 |
# File 'lib/markbridge/parsers/bbcode/handlers/self_closing_handler.rb', line 9 def initialize(element_class) @element_class = element_class end |
Instance Attribute Details
#element_class ⇒ Object (readonly)
Returns the value of attribute element_class.
23 24 25 |
# File 'lib/markbridge/parsers/bbcode/handlers/self_closing_handler.rb', line 23 def element_class @element_class end |
Instance Method Details
#on_close(token:, context:, registry:, tokens: nil) ⇒ Object
18 19 20 21 |
# File 'lib/markbridge/parsers/bbcode/handlers/self_closing_handler.rb', line 18 def on_close(token:, context:, registry:, tokens: nil) # Treat unexpected closing tag as text context.add_child(AST::Text.new(token.source)) end |
#on_open(token:, context:, registry:, tokens: nil) ⇒ Object
13 14 15 16 |
# File 'lib/markbridge/parsers/bbcode/handlers/self_closing_handler.rb', line 13 def on_open(token:, context:, registry:, tokens: nil) element = @element_class.new context.add_child(element) end |