Module: BBGun

Defined in:
lib/bbgun.rb,
lib/bbgun/css.rb,
lib/bbgun/tags.rb,
lib/bbgun/parse.rb,
lib/bbgun/config.rb,
lib/bbgun/coderay.rb,
lib/bbgun/version.rb,
lib/bbgun/swear_filter.rb

Defined Under Namespace

Modules: Coderay, SwearFilter Classes: Config

Constant Summary collapse

Tags =
[[/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>',:strong_enabled,"[b]BOLD[/b]","<strong>BOLD</strong>"],
[/\[i\](.*?)\[\/i\]/,'<i>\1</i>',:italic_enabled,"[i]italics[/i]","<i>italics</i>"],
[/\[u\](.*?)\[\/u\]/,'<u>\1</u>',:underline_enabled,"[u]underline[/u]","<u>underline</u>"],
[/\[url\](.*?)\[\/url\]/,'<a href="\1" target="@config[:url_target]">\1</a>',:url_enabled,"[url]http://www.example.com[/url]","<a href=\"http://www.example.com\" target=\"_BLANK\">http://www.example.com</a>"],
[/\[url=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="@config[:url_target]">\2</a>',:url_enabled,"[url=http://www.example.com]Example[/url]","<a href=\"http://www.example.com\" target=\"_BLANK\">Example</a>"],
[/\[url=(.*?) target=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="\2">\3</a>',:url_enabled,"[url=http://www.example.com]Example[/url]","<a href=\"http://www.example.com\" target=\"_BLANK\">Example</a>"],
  [/\[img\](.*?)\[\/img\]/,'<img src="\1" alt="@config[:image_alt]" />',:image_enabled,"[img]test.jpg[/img]","<img src=\"test.jpg\" alt=\"Posted Image\" />"],
[/\[img alt=(.*?)\](.*?)\[\/img\]/,'<img src="\2" alt="\1" />',:image_enabled,"[img alt=Posted Image]test.jpg[/img]","<img src=\"test.jpg\" alt=\"Posted Image\" />"],
[/\[ul\](.*?)\[\/ul\]/,'<ul>\1</ul>',:list_enabled,"[ul]list[/ul]","<ul>list</ul>"],
[/\[ol\](.*?)\[\/ol\]/,'<ol>\1</ol>',:list_enabled,"[ol]list[/ol]","<ol>list</ol>"],
[/\[li\](.*?)\[\/li\]/,'<li>\1</li>',:list_enabled,"[li]list[/li]","<li>list</li>"],
[/\[quote\](.*?)\[\/quote\]/,'<blockquote>\1</blockquote>',:quote_enabled,"[quote]quote[/quote]","<blockquote>quote</blockquote>"],
[/\[quote=(.*?)\](.*?)\[\/quote\]/,'<blockquote><i>Posted by <b>\1</b></i><br />\2</blockquote>',:quote_enabled,"[quote=user]quote[/quote]","<blockquote><i>Posted by <b>user</b></i><br />quote</blockquote>"],
[/\[color=(.*?)\](.*?)\[\/color\]/,'<span style="color:\1;">\2</span>',:color_enabled,"[color=red]red text[/color]","<span style=\"color:red;\">red text</span>"],
[/\[center\](.*?)\[\/center\]/,'<div style="text-align:center">\1</div>',:alignment_enabled,"[center]centered text[/center]","<div style=\"text-align:center\">centered text</div>"],
[/\[left\](.*?)\[\/left\]/,'<div style="text-align:left">\1</div>',:alignment_enabled,"[left]left text[/left]","<div style=\"text-align:left\">left text</div>"],
[/\[right\](.*?)\[\/right\]/,'<div style="text-align:right">\1</div>',:alignment_enabled,"[right]right text[/right]","<div style=\"text-align:right\">right text</div>"],
[/\[acronym=(.*?)\](.*?)\[\/acronym\]/,'<acronym title="\1">\2</acronym>',:acronym_enabled,"[acronym=this]that[/acronym]","<acronym title=\"this\">that</acronym>"],
[/\[table\](.*?)\[\/table\]/,'<table width="@config[:table_width]">\1</table>',:table_enabled,"[table]...[/table]","<table width=\"100%\">...</table>"],
[/\[tr\](.*?)\[\/tr\]/,'<tr>\1</tr>',:table_enabled,"[tr]...[/tr]","<tr>...</tr>"],
[/\[td\](.*?)\[\/td\]/,'<td>\1</td>',:table_enabled,"[td]...[/td]","<td>...</td>"],
[/\[th\](.*?)\[\/th\]/,'<th>\1</th>',:table_enabled,"[th]...[/th]","<th>...</th>"],
[/\[h1\](.*?)\[\/h1\]/,'<h1>\1</h1>',:header_enabled,'[h1]heading[/h1]',"<h1>heading</h1>"],
[/\[h2\](.*?)\[\/h2\]/,'<h2>\1</h2>',:header_enabled,'[h2]heading[/h2]',"<h2>heading</h2>"],
[/\[h3\](.*?)\[\/h3\]/,'<h3>\1</h3>',:header_enabled,'[h3]heading[/h3]',"<h3>heading</h3>"],
[/\[h4\](.*?)\[\/h4\]/,'<h4>\1</h4>',:header_enabled,'[h4]heading[/h4]',"<h4>heading</h4>"]]
VERSION =
"1.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject



21
22
23
# File 'lib/bbgun.rb', line 21

def self.config
 @config
end

.configure {|@config| ... } ⇒ Object

Yields:



12
13
14
15
# File 'lib/bbgun.rb', line 12

def self.configure
    @config = Config.new
    yield(@config) 
end

.configured?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/bbgun.rb', line 17

def self.configured?
   @config ? true : false 
end

.parse(input) ⇒ Object

Parses the input and returns it in tbbc form.

TBBC.new.parse("[b]Bold[/b]")

Would return “<strong>Bold</strong>”



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bbgun/parse.rb', line 7

def self.parse(input)
  #Remove the < and > which will disable all HTML
  input=input.gsub("<","&lt;").gsub(">","&gt;") unless @config.disable_html == false
  #CodeRay
  input=Coderay.parse(input) unless @config.syntax_highlighting == false
  #Convert new lines to <br />'s
  input=input.gsub(/\n/,'<br />') unless @config.newline_enabled == false
  #[nobbc] tags
  input=nobbc input unless @config.nobbc_enabled == false
  #Swear Filtering
  input=SwearFilter.parse(input) unless @config.swear_filter_enabled == false
  #Loading Custom Tags
  #begin
    if @config.custom_tags then
      @config.custom_tags.each do |tag|
        input=runtag(input,tag)
      end
    end
  #rescue
    #input+="<br />Custom Tags failed to run"
  #end
  #Loading Default Tags and applying them
  if @config.allow_defaults then
     BBGun::Tags.each do |tag|
      input=runtag(input,tag)
    end 
  end
  input = correctbrs input
  input = escape input
  if needs_html_safe? then
    return input.html_safe
  else
    return input
  end
end

Instance Method Details

#css(config = nil) ⇒ Object

Returns the css required for coderay



4
5
6
7
# File 'lib/bbgun/css.rb', line 4

def css(config = nil)
       warn "[DEPRECATION] `css` is no longer used, styles are applied inline."
       ""
end