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_alt] + '',@config[:image_enabled]], [/\[img alt=(.*?)\](.*?)\[\/img\]/,'\1',@config[:image_enabled]], #Un-Ordered List [/\[ul\](.*?)\[\/ul\]/,'',@config[:list_enabled]], #Ordered List [/\[ol\](.*?)\[\/ol\]/,'
    \1
',@config[:list_enabled]], #List Item [/\[li\](.*?)\[\/li\]/,'
  • \1
  • ',@config[:list_enabled]] ] end def nobbc(s) find=s.scan(/\[nobbc\](.*?)\[\/nobbc\]/) find.each do |f| replace=f[0].gsub("[","[").gsub("]","]") s=s.gsub(f[0],replace) end s=s.gsub("[nobbc]","").gsub("[/nobbc]","") return s end end #Add .tbbc to Strings class String def tbbc bbc=TBBC.new bbc.parse(self) end end