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 =
"0.1.2"

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

#bufferObject



35
36
37
# File 'lib/bbcoder/base.rb', line 35

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

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bbcoder/base.rb', line 20

def parse
  raw.each do |data|
    case data
    when /\[\/([^\]]+)\]/
      buffer.tags.pop($1.to_sym)
    when /\[([^\]]+)\]/
      buffer.tags.push($1)
    else
      buffer.push(data)
    end
  end

  buffer.join
end

#to_htmlObject



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

def to_html
  @html ||= parse
end