Class: Markbridge::Parsers::BBCode::Handlers::AlignHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/markbridge/parsers/bbcode/handlers/align_handler.rb

Overview

Handler for ALIGN tags (center, left, right, justify) Creates a generic Align element with the appropriate alignment

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#auto_closeable?, #on_close

Constructor Details

#initialize(alignment = nil) ⇒ AlignHandler

Returns a new instance of AlignHandler.



10
11
12
13
# File 'lib/markbridge/parsers/bbcode/handlers/align_handler.rb', line 10

def initialize(alignment = nil)
  @alignment = alignment
  @element_class = AST::Align
end

Instance Attribute Details

#element_classObject (readonly)

Returns the value of attribute element_class.



21
22
23
# File 'lib/markbridge/parsers/bbcode/handlers/align_handler.rb', line 21

def element_class
  @element_class
end

Instance Method Details

#on_open(token:, context:, registry:, tokens: nil) ⇒ Object



15
16
17
18
19
# File 'lib/markbridge/parsers/bbcode/handlers/align_handler.rb', line 15

def on_open(token:, context:, registry:, tokens: nil)
  alignment = @alignment || token.tag.downcase
  element = AST::Align.new(alignment:)
  context.push(element, token:)
end