Class: Bbcode::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bbcode/base.rb

Constant Summary collapse

@@handlers =
HashWithIndifferentAccess.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, locals = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/bbcode/base.rb', line 7

def initialize(string, locals = {})
	@string = string
end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals.



5
6
7
# File 'lib/bbcode/base.rb', line 5

def locals
  @locals
end

Class Method Details

.register_handler(name, handler) ⇒ Object



21
22
23
# File 'lib/bbcode/base.rb', line 21

def self.register_handler(name, handler)
	@@handlers[name] = handler
end

Instance Method Details

#to(handler, locals = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/bbcode/base.rb', line 11

def to(handler, locals = {})
	handler = @@handlers[handler]
	raise "Handler #{handler} isn't registered" if handler.blank?
	handler.locals = locals.with_indifferent_access
	Parser.new(Tokenizer.new).parse @string, handler
	result = handler.get_document.content.to_s
	handler.clear
	result
end