class TBBC
def initialize
self.conf(:configed_by => "system")
end
def conf(config)
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)
#First off remove the < and > which will disable all HTML
s=s.gsub("<","<").gsub(">",">")
#Convert new lines to
's
s=s.gsub(/\n/,'
')
#[nobbc] tags
unless @config[:nobbc_enabled] == false
s=nobbc s
end
#Loading Custom Tags
if @config[:custom_tags] then
@config[:custom_tags].each do |tag|
s=s.gsub(tag[0],tag[1]) unless tag[2] == false
end
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]],
#Image
[/\[img\](.*?)\[\/img\]/,'',@config[:image_enabled]],
[/\[img alt=(.*?)\](.*?)\[\/img\]/,'
',@config[:image_enabled]],
#Un-Ordered List
[/\[ul\](.*?)\[\/ul\]/,'