Sha256: 5d31cc6036af1955619e2d4546b1f22129841fbf6e610ce6e05dcf772c31b27f

Contents?: true

Size: 725 Bytes

Versions: 2

Compression:

Stored size: 725 Bytes

Contents

class BBCoder
  attr_reader :raw

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

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

  def initialize(text)
    @raw = text.split(/(\[[^\[\]]+\])/i).select {|string| string.size > 0}
  end

  def to_html
    @html ||= parse
  end

  def parse
    _parse
    buffer.join
  end

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

  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 # _parse
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bbcoder-1.1.1 lib/bbcoder/base.rb
bbcoder-1.1.0 lib/bbcoder/base.rb