class TBBC
def initialize
self.conf(:configed_by => "system")
end
def conf(config)
require 'rubygems'
begin
require 'uv'
#UV Settings
config[:syntax_output] ||= "HTML"
config[:syntax_line_numbers] ||= true
config[:syntax_theme] ||= "twilight"
rescue LoadError
config[:syntax_highlighting]=false
end
config[:configed_by] ||= "user"
config[:image_alt] ||= "Posted Image"
config[:url_target] ||= "_BLANK"
config[:allow_defaults] ||= true
#Instanize the config variable
@config=config
end
def parse(s)
#Run the UV Parser (if enabled) to sort out any code
s=uv s unless @config[:syntax_highlighting] == false
#Remove the < and > which will disable all HTML
s=s.gsub("<","<").gsub(">",">") unless @config[:disable_html] == false
#Convert new lines to
's
s=s.gsub(/\n/,'
') unless @config[:newline_enabled] == false
#[nobbc] tags
s=nobbc s unless @config[:nobbc_enabled] == false
#Loading Custom Tags
begin
if @config[:custom_tags] then
@config[:custom_tags].each do |tag|
s=s.gsub(tag[0],tag[1]) unless tag[2] == false
end
end
rescue
s+="
Custom Tags failed to run"
end
#Loading Default Tags and applying them
if @config[:allow_defaults] then
tags=load_default_tags
tags.each do |tag|
s=s.gsub(tag[0],tag[1]) unless tag[2] == false
end
end
return s
end
def load_default_tags
tags=[
#Bold
[/\[b\](.*?)\[\/b\]/,'\1',@config[:strong_enabled]],
#Italic
[/\[i\](.*?)\[\/i\]/,'\1',@config[:italic_enabled]],
#Underline
[/\[u\](.*?)\[\/u\]/,'\1',@config[:underline_enabled]],
#Url
[/\[url\](.*?)\[\/url\]/,'\1',@config[:url_enabled]],
[/\[url=(.*?)\](.*?)\[\/url\]/,'\2',@config[:url_enabled]],
[/\[url=(.*?) target=(.*?)\](.*?)\[\/url\]/,'\3',@config[:url_enabled]],
#Image
[/\[img\](.*?)\[\/img\]/,'',@config[:image_enabled]],
[/\[img alt=(.*?)\](.*?)\[\/img\]/,'
',@config[:image_enabled]],
#Un-Ordered List
[/\[ul\](.*?)\[\/ul\]/,'
\1',@config[:quote_enabled]], [/\[quote=(.*?)\](.*?)\[\/quote\]/,'
Posted by \1',@config[:quote_enabled]], #Color [/\[color=(.*?)\](.*?)\[\/color\]/,'\2',@config[:color_enabled]], #Alignment [/\[center\](.*?)\[\/center\]/,'
\2