Class: BBCoder

Inherits:
Object
  • 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

#rawObject (readonly)

Returns the value of attribute raw.



2
3
4
# File 'lib/bbcoder/base.rb', line 2

def raw
  @raw
end

Class Method Details

.configurationObject



8
9
10
# File 'lib/bbcoder/base.rb', line 8

def self.configuration
  @configuration ||= BBCoder::Configuration.new
end

.configure(&block) ⇒ Object



4
5
6
# File 'lib/bbcoder/base.rb', line 4

def self.configure(&block)
  configuration.instance_eval(&block)
end

Instance Method Details

#_parseObject



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) # popping end tag
    when /\[([^\]]+)\]/
      buffer.tags.push($1) # pushing start tag
    else
      buffer.push(data) # content
    end
  end
end

#bufferObject



25
26
27
# File 'lib/bbcoder/base.rb', line 25

def buffer
  @buffer ||= BBCoder::Buffer.new
end

#parseObject



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

def parse
  _parse
  buffer.join
end

#to_htmlObject



16
17
18
# File 'lib/bbcoder/base.rb', line 16

def to_html
  @html ||= parse
end