Class: BBCoder
- Inherits:
-
Object
show all
- Defined in:
- lib/bbcoder/tag.rb,
lib/bbcoder/base.rb,
lib/bbcoder/buffer.rb,
lib/bbcoder/version.rb,
lib/bbcoder/buffer_tags.rb,
lib/bbcoder/configuration.rb
Defined Under Namespace
Classes: Buffer, BufferTags, Configuration, Tag
Constant Summary
collapse
- VERSION =
"1.1.1"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(text) ⇒ BBCoder
Returns a new instance of BBCoder.
12
13
14
|
# File 'lib/bbcoder/base.rb', line 12
def initialize(text)
@raw = text.split(/(\[[^\[\]]+\])/i).select {|string| string.size > 0}
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
2
3
4
|
# File 'lib/bbcoder/base.rb', line 2
def raw
@raw
end
|
Class Method Details
.configuration ⇒ Object
8
9
10
|
# File 'lib/bbcoder/base.rb', line 8
def self.configuration
@configuration ||= BBCoder::Configuration.new
end
|
4
5
6
|
# File 'lib/bbcoder/base.rb', line 4
def self.configure(&block)
configuration.instance_eval(&block)
end
|
Instance Method Details
#_parse ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/bbcoder/base.rb', line 29
def _parse
raw.each do |data|
case data
when /\[\/([^\]]+)\]/
buffer.tags.pop($1) when /\[([^\]]+)\]/
buffer.tags.push($1) else
buffer.push(data) end
end
end
|
#buffer ⇒ Object
25
26
27
|
# File 'lib/bbcoder/base.rb', line 25
def buffer
@buffer ||= BBCoder::Buffer.new
end
|
#parse ⇒ Object
20
21
22
23
|
# File 'lib/bbcoder/base.rb', line 20
def parse
_parse
buffer.join
end
|
#to_html ⇒ Object
16
17
18
|
# File 'lib/bbcoder/base.rb', line 16
def to_html
@html ||= parse
end
|