cbot-bbcodeizer 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +21 -0
  4. data/README +128 -0
  5. data/Rakefile +22 -0
  6. data/bbcodeizer.gemspec +23 -0
  7. data/init.rb +4 -0
  8. data/lib/bbcodeizer.rb +171 -0
  9. data/lib/bbcodeizer/version.rb +3 -0
  10. data/lib/bbcodeizer_helper.rb +8 -0
  11. data/rdoc/BBCodeizeHelper.html +182 -0
  12. data/rdoc/Bbcodeizer.html +146 -0
  13. data/rdoc/README.html +214 -0
  14. data/rdoc/created.rid +5 -0
  15. data/rdoc/images/brick.png +0 -0
  16. data/rdoc/images/brick_link.png +0 -0
  17. data/rdoc/images/bug.png +0 -0
  18. data/rdoc/images/bullet_black.png +0 -0
  19. data/rdoc/images/bullet_toggle_minus.png +0 -0
  20. data/rdoc/images/bullet_toggle_plus.png +0 -0
  21. data/rdoc/images/date.png +0 -0
  22. data/rdoc/images/find.png +0 -0
  23. data/rdoc/images/loadingAnimation.gif +0 -0
  24. data/rdoc/images/macFFBgHack.png +0 -0
  25. data/rdoc/images/package.png +0 -0
  26. data/rdoc/images/page_green.png +0 -0
  27. data/rdoc/images/page_white_text.png +0 -0
  28. data/rdoc/images/page_white_width.png +0 -0
  29. data/rdoc/images/plugin.png +0 -0
  30. data/rdoc/images/ruby.png +0 -0
  31. data/rdoc/images/tag_green.png +0 -0
  32. data/rdoc/images/wrench.png +0 -0
  33. data/rdoc/images/wrench_orange.png +0 -0
  34. data/rdoc/images/zoom.png +0 -0
  35. data/rdoc/index.html +60 -0
  36. data/rdoc/js/darkfish.js +116 -0
  37. data/rdoc/js/jquery.js +32 -0
  38. data/rdoc/js/quicksearch.js +114 -0
  39. data/rdoc/js/thickbox-compressed.js +10 -0
  40. data/rdoc/lib/bbcodeize_helper_rb.html +54 -0
  41. data/rdoc/lib/bbcodeizer/version_rb.html +52 -0
  42. data/rdoc/lib/bbcodeizer_helper_rb.html +54 -0
  43. data/rdoc/lib/bbcodeizer_rb.html +52 -0
  44. data/rdoc/rdoc.css +763 -0
  45. data/test/bbcodeizer_test.rb +145 -0
  46. metadata +125 -0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bbcodeizer.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2006 Jonathan Dance / Agora Games
2
+ Copyright (c) 2006 Trevor Turk
3
+ Copyright (c) 2011 Luke Curley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the "Software"),
7
+ to deal in the Software without restriction, including without limitation
8
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,128 @@
1
+ == BBCodeizer
2
+
3
+ BBCodeizer is a gem used to translate BBCode to HTML. The main interface
4
+ is provided through the helper method "bbcodeize." Use of it is as simple as
5
+ passing a string to bbcodeize:
6
+
7
+ <%= bbcodeize post.body %>
8
+
9
+ You can also invoke the BBCodeizer directly without the helper:
10
+
11
+ render :text => BBCodeizer.bbcodeize(post.body)
12
+
13
+ All settings are centralized so you can very quickly deactivate any tag or
14
+ modify the HTML that is generated. You can modify these settings by adding
15
+ lines to the end of your environment.rb. For example:
16
+
17
+ # deactivate [color], [size], and [code] tags
18
+ BBCodeizer.deactivate(:color, :size, :code)
19
+
20
+ # use <b> instead of <strong>
21
+ BBCodeizer.replace_using(:bold, '<b>\1</b>')
22
+
23
+ These changes should be considered one-time configuration, e.g. tags
24
+ cannot be deactivated then activated again.
25
+
26
+ == Warning
27
+
28
+ While BBCodeizer does some validation (see below), you should be aware it is
29
+ possible to create unsafe HTML in the wrong hands (for example, invoking
30
+ Javascript using the [url] tag). It is highly recommended you run the
31
+ resulting HTML through a sanity checker such as WhiteList:
32
+
33
+ http://svn.techno-weenie.net/projects/plugins/white_list/
34
+
35
+ Once installed, the following is a helper method that will produce nicely
36
+ formatted, safe HTML:
37
+
38
+ def format_text(text)
39
+ white_list(simple_format(auto_link(bbcodeize(h(text)))))
40
+ end
41
+
42
+ == Supported Tags
43
+
44
+ BBCodeizer currently supports the following tags. The default HTML expansion
45
+ is documented here.
46
+
47
+ [u]text[/u]
48
+
49
+ <u>text</u>
50
+
51
+ [b]text[/b]
52
+
53
+ <strong>text</strong>
54
+
55
+ [i]text[/i]
56
+
57
+ <em>text</em>
58
+
59
+ [img]http://example.com/image.gif[/img]
60
+
61
+ <img src="http://example.com/image.gif" />
62
+
63
+ [email=joe@example.com]Joe Example[/email]
64
+
65
+ <a href="mailto:joe@example.com">Joe Example</a>
66
+
67
+ [email]joe@example.com[/email]
68
+
69
+ <a href="mailto:joe@example.com">joe@example.com</a>
70
+
71
+ [code]bbcodeize(string)[/code]
72
+
73
+ <pre>bbcodeize(string)</pre>
74
+
75
+ [url=http://www.google.com]Google[/url]
76
+
77
+ <a href="http://www.google.com">Google</a>
78
+
79
+ [url]http://www.google.com[/url]
80
+
81
+ <a href="http://www.google.com">http://www.google.com</a>
82
+
83
+ [quote="Shakespeare"]To be or not to be[/quote]
84
+
85
+ <blockquote><cite>Shakespeare wrote:</cite><br />To be or not to
86
+ be</blockquote>
87
+
88
+ [quote]That is the question[/quote]
89
+
90
+ <blockquote>That is the question</blockquote>
91
+
92
+ [size=32]Big Text[/size]
93
+
94
+ <span style="font-size: 32px">Big Text</span>
95
+
96
+ [color=red]Red Text[/color] [color=#ABCDEF]Alphabet-colored Text[/color]
97
+
98
+ <span style="color: red">Red Text</span>
99
+ <span style="color: #ABCDEF">Alphabet Colored Text</span>
100
+
101
+ == Validation
102
+
103
+ BBCodeizer aims to produce HTML that will not break your site - all opening
104
+ tags must have a closing tag or they will not be replaced (unmatched tags are
105
+ left as-is). All [code] and [quote] tags are left entirely untouched if there
106
+ is any mismatch with either of these. All other tags will replace as many as
107
+ possible and leave the remaining unmatched tags as-is.
108
+
109
+ BBCodeizer attempts to produce XHTML-compliant markup, however, misuse of
110
+ nesting tags is not validated or corrected. For example:
111
+
112
+ [b]bold [u]bold + underline[/b] underline[/u]
113
+
114
+ Will produce the following HTML:
115
+
116
+ <strong>bold <u>bold + underline</strong> underline</u>
117
+
118
+ Colors in the [color] tag are not validated - any string can be used. Strings
119
+ containing semicolons are not allowed to prevent users from adding additional
120
+ style rules.
121
+
122
+ Sizes used in the [size] tag are validated - only 1 or 2 digit numbers are
123
+ accepted.
124
+
125
+ -----------------
126
+ Copyright (c) 2006 Jonathan Dance / Agora Games
127
+ Copyright (c) 2011 Luke Curley
128
+ Distributed under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the BBCodeizer plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the BBCodeizer plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'BBCodeizer'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bbcodeizer/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cbot-bbcodeizer"
7
+ s.version = Bbcodeizer::VERSION
8
+ s.authors = ["Jonathan Dance", "Luke Curley"]
9
+ s.email = ["jd+bbcodeizer@wuputah.com", "luke@box.net"]
10
+ s.homepage = "https://github.com/qpingu/bbcodeizer"
11
+ s.summary = %q{BBCodeizer is a simple gem that translates BBCode to HTML}
12
+
13
+ s.rubyforge_project = "bbcodeizer"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # specify any dependencies here; for example:
21
+ s.add_development_dependency "rake"
22
+ s.add_development_dependency "rdoc"
23
+ end
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'bbcodeizer'
2
+ require 'bbcodeize_helper'
3
+
4
+ ActionView::Base.send :include, BBCodeizeHelper
data/lib/bbcodeizer.rb ADDED
@@ -0,0 +1,171 @@
1
+ module BBCodeizer
2
+ class << self
3
+
4
+ #:nodoc:
5
+ Tags = {
6
+ :literal => [ /\[\[(.+?)\]\]/im, '&#91\1&#93' ],
7
+ :start_code => [ /\[code\](\r\n?)?/i, '<pre><code>' ],
8
+ :end_code => [ /(\r\n?)?\[\/code\]/i, '</code></pre>' ],
9
+ :start_list => [ /\[list\](\r\n?)?/i, '<ul>' ],
10
+ :start_li => [ /\[li\](\r\n?)?/i, '<li>' ],
11
+ :end_li => [ /(\r\n?)?\[\/li\](\r\n?)?/i, '</li>' ],
12
+ :end_list => [ /(\r\n?)?\[\/list\]/i, '</ul>' ],
13
+ :start_quote => [ /\[quote(?:=.*?)?\](\r\n?)?/i, '<blockquote>' ],
14
+ :start_quote_with_cite => [ /\[quote=(.*?)\](\r\n?)?/i, '<blockquote><p><cite>\1 wrote:</cite></p>' ],
15
+ :start_quote_sans_cite => [ /\[quote\](\r\n?)?/i, '<blockquote>' ],
16
+ :end_quote => [ /(\r\n?)?\[\/quote\]/i, '</blockquote>' ],
17
+ :bold => [ /\[b\](.+?)\[\/b\]/im, '<strong>\1</strong>' ],
18
+ :italic => [ /\[i\](.+?)\[\/i\]/im, '<em>\1</em>' ],
19
+ :underline => [ /\[u\](.+?)\[\/u\]/im, '<u>\1</u>' ],
20
+ :del => [ /\[del\](.+?)\[\/del\]/im, '<del>\1</del>' ],
21
+ :strike => [ /\[strike\](.+?)\[\/strike\]/im, '<del>\1</del>' ],
22
+ :email_with_name => [ /\[email=(.+?)\](.+?)\[\/email\]/i, '<a href="mailto:\1">\2</a>' ],
23
+ :email_sans_name => [ /\[email\](.+?)\[\/email\]/i, '<a href="mailto:\1">\1</a>' ],
24
+ :url_with_title => [ /\[url=(.+?)\](.+?)\[\/url\]/i, '<a href="\1" target="_blank">\2</a>' ],
25
+ :url_sans_title => [ /\[url\](.+?)\[\/url\]/i, '<a href="\1" target="_blank">\1</a>' ],
26
+ :image => [ /\[img\](.+?)\[\/img\]/i, '<img src="\1" alt="\1" />' ],
27
+ :size => [ /\[size=(\d{1,2})\](.+?)\[\/size\]/im, '<span style="font-size: \1px">\2</span>' ],
28
+ :color => [ /\[color=([^;]+?)\](.+?)\[\/color\]/im, '<span style="color: \1">\2</span>' ],
29
+ :youtube => [ /\[youtube\](.+?)youtube.com\/watch\?v=(.+?)\[\/youtube\]/i, '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/\2?fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/\2?fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="350"></embed></object>' ],
30
+ :googlevid => [ /\[googlevid\](.+?)video.google.com\/videoplay\?docid=(.*?)\[\/googlevid\]/i, '<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=\2&amp;hl=en"></embed>' ],
31
+ :flash => [ /\[flash\](.+?)\[\/flash\]/i, '<object width="100%" height="100%"><param name="movie" value="\1"></param><embed src="\1" type="application/x-shockwave-flash" width="100%" height="100%"></embed></object>' ],
32
+ :spoiler => [ /\[spoiler\](.+?)\[\/spoiler\]/im, '<a href="#" class="spoiler-link" onclick="$(\'_RANDOM_ID_\').toggle(); return false;">SPOILER</a><div id="_RANDOM_ID_" class="spoiler" style="display:none;">\1</div>' ],
33
+ :nsfw => [ /\[nsfw\](.+?)\[\/nsfw\]/im, '<a href="#" class="nsfw-link" onclick="$(\'_RANDOM_ID_\').toggle(); return false;">NSFW</a><div id="_RANDOM_ID_" class="nsfw" style="display:none;">\1</div>' ],
34
+ :hide => [ /\[hide=(.+?)\](.+?)\[\/hide\]/im, '<a href="#" class="hide-link" onclick="$(\'_RANDOM_ID_\').toggle(); return false;">\1</a><div id="_RANDOM_ID_" class="hide" style="display:none;">\2</div>' ],
35
+ :mp3 => [ /\[mp3\](.+?)\[\/mp3\]/i, '<script language="JavaScript" src="/javascripts/audio-player.js"></script><object type="application/x-shockwave-flash" data="/flash/player.swf" id="_RANDOM_ID_" height="24" width="290"><param name="movie" value="/flash/player.swf"><param name="FlashVars" value="playerID=_RANDOM_ID_&amp;soundFile=\1"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="transparent"></object>' ],
36
+ :superdeluxe => [ /\[superdeluxe\](.+?)superdeluxe.com\/sd\/contentDetail.do\?id=(.+?)\[\/superdeluxe\]/i, '<object width="400" height="350"><param name="allowFullScreen" value="true" /><param name="movie" value="http://www.superdeluxe.com/static/swf/share_vidplayer.swf" /><param name="FlashVars" value="id=\2" /><embed src="http://www.superdeluxe.com/static/swf/share_vidplayer.swf" FlashVars="id=\2" type="application/x-shockwave-flash" width="400" height="350" allowFullScreen="true" ></embed></object>' ],
37
+ :comedycentral => [ /\[comedycentral\](.+?)comedycentral.com(.+?)?(.+?)=(.+?)\[\/comedycentral\]/i, '<embed FlashVars="config=http://www.comedycentral.com/motherload/xml/data_synd.jhtml?vid=\4%26myspace=false" src="http://www.comedycentral.com/motherload/syndicated_player/index.jhtml" quality="high" bgcolor="#006699" width="340" height="325" name="comedy_player" align="middle" allowScriptAccess="always" allownetworking="external" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' ],
38
+ :revver => [ /\[revver\](.+?)revver.com\/video\/(.+?)\/(.+?)\[\/revver\]/i, '<embed type="application/x-shockwave-flash" src="http://flash.revver.com/player/1.0/player.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" scale="noScale" salign="TL" bgcolor="#000000" flashvars="mediaId=\2&affiliateId=0&allowFullScreen=true" allowfullscreen="true" height="392" width="480"></embed>' ],
39
+ :myspacetv => [ /\[myspacetv\](.+?)myspace(.+?)videoid=(.+?)\[\/myspacetv\]/i, '<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m=\3&v=2&type=video" type="application/x-shockwave-flash" width="430" height="346"></embed>' ],
40
+ :collegehumor => [ /\[collegehumor\](.+?)collegehumor.com\/video:(.+?)\[\/collegehumor\]/i, '<embed src="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=\2" quality="best" width="400" height="300" type="application/x-shockwave-flash"></embed>' ],
41
+ :hulu => [ /\[hulu\](.+?)\[\/hulu\]/i, '<object width="512" height="296"><param name="movie" value="http://www.hulu.com/embed/\1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.hulu.com/embed/\1" type="application/x-shockwave-flash" allowFullScreen="true" width="512" height="296"></embed></object>' ],
42
+ :metacafe => [ /\[metacafe\](.+?)metacafe.com\/watch\/(.+?)\/(.+?)\/\[\/metacafe\]/i, '<embed src="http://www.metacafe.com/fplayer/\2/\3.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' ],
43
+ :yahoovid => [ /\[yahoovid\](.+?)video.yahoo.com\/watch\/(.+?)\/(.+?)\[\/yahoovid\]/i, '<object width="512" height="323"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.2" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="id=\3&vid=\2&lang=en-us&intl=us&embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.2" type="application/x-shockwave-flash" width="512" height="323" allowFullScreen="true" flashVars="id=\3&vid=\2&lang=en-us&intl=us&embed=1" ></embed></object>' ],
44
+ :flickr => [ /\[flickr\](.+?)\/photos\/(.+?)\/(.+?)\[\/flickr\]/i, '<object type="application/x-shockwave-flash" width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=1.162"><param name="flashvars" value="intl_lang=en-us&amp;photo_id=\3&amp;show_info_box=true"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=1.162"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=1.162" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&amp;photo_id=\3&amp;flickr_show_info_box=true" height="300" width="400"></embed></object>' ],
45
+ :gametrailers => [ /\[gametrailers\](.+?)gametrailers.com\/player\/(.+?)\.(.+?)\[\/gametrailers\]/i, '<object codebase="http://download.macromedia.com/pub/shockwave/ca...=8,0,0,0" id="gtembed" width="480" height="392"> <param name="allowScriptAccess" value="sameDomain" /> <param name="allowFullScreen" value="true" /> <param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid=\2"/> <param name="quality" value="high" /> <embed src="http://www.gametrailers.com/remote_wrap.php?mid=\2" swLiveConnect="true" name="gtembed" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="480" height="392"></embed> </object>' ], :slideshare => [ /\[slideshare id=(.+?)&(.+?)=(.+?)&(.+?)=(.+?)\]/i, '<object type="application/x-shockwave-flash" wmode="transparent" data="https://s3.amazonaws.com:443/slideshare/ssplayer.swf?id=\1&#038;doc=\3" width="\5" height="348"><param name="movie" value="https://s3.amazonaws.com:443/slideshare/ssplayer.swf?id=\1&#038;doc=\3" /></object>' ],
46
+ :funnyordie => [ /\[funnyordie\](.+?)funnyordie.com\/videos\/([^\/]+)(.*)\[\/funnyordie\]/i, '<object width="464" height="388"><param name="movie" value="http://www2.funnyordie.com/public/flash/fodplayer.swf?6045" /><param name="flashvars" value="key=\2" /><param name="allowfullscreen" value="true" /><embed width="464" height="388" flashvars="key=\2" allowfullscreen="true" quality="high" src="http://www2.funnyordie.com/public/flash/fodplayer.swf?6045" type="application/x-shockwave-flash"></embed></object>' ],
47
+ :atomfilms => [ /\[atomfilms\](.+?)atomfilms.com\/film\/(.+?)\[\/atomfilms\]/i, '<embed src="http://www.atomfilms.com:80/a/autoplayer/shareEmbed.swf?keyword=\2" width="426" height="350"></embed>' ],
48
+ :current => [ /\[current\](.+?)current.com\/items\/(.+?)\/(.+?)\[\/current\]/i, '<object width="400" height="400"><param name="movie" value="http://current.com/e/\2/en_US"></param><param name="wmode" value="transparent"></param><param name="allowfullscreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://current.com/e/\2/en_US" type="application/x-shockwave-flash" width="400" height="400" wmode="transparent" allowfullscreen="true" allowscriptaccess="always"></embed></object>' ],
49
+ :vimeo => [ /\[vimeo\](.+?)vimeo.com\/(.+?)\[\/vimeo\]/i, '<object type="application/x-shockwave-flash" width="400" height="300" data="http://www.vimeo.com/moogaloop.swf?clip_id=\2&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color="> <param name="quality" value="best" /> <param name="allowfullscreen" value="true" /> <param name="scale" value="showAll" /> <param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=\2&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=" /></object>' ],
50
+ :grooveshark => [ /\[grooveshark\](.+?)\[\/grooveshark\]/i, '<object width="250" height="40"> <param name="movie" value="http://listen.grooveshark.com/songWidget.swf"></param> <param name="wmode" value="window"></param> <param name="allowScriptAccess" value="always"></param> <param name="flashvars" value="hostname=cowbell.grooveshark.com&widgetID=\1&style=grass&p=0"></param> <embed src="http://listen.grooveshark.com/songWidget.swf" type="application/x-shockwave-flash" width="250" height="40" flashvars="hostname=cowbell.grooveshark.com&widgetID=\1&style=grass&p=0" allowScriptAccess="always" wmode="window"></embed></object>'],
51
+ :sup => [ /\[sup\](.+?)\[\/sup\]/im, '<sup>\1</sup>' ],
52
+ :sub => [ /\[sub\](.+?)\[\/sub\]/im, '<sub>\1</sub>' ],
53
+ :auto_link => [ /(\A|\s|>)((https?:\/\/|www\.)[^\s<]+)/, '\1<a href="\2" target="_blank">\2</a>' ],
54
+ }
55
+
56
+ # Tags in this list are invoked. To deactivate a particular tag, call BBCodeizer.deactivate.
57
+ # These names correspond to either names above or methods in this module.
58
+ # The ':literal' tag MUST be first for it to work correctly
59
+ TagList = [ :literal, :bold, :italic, :underline, :del, :strike, :email_with_name,
60
+ :email_sans_name, :image, :size, :color, :code, :quote, :youtube, :googlevid,
61
+ :flash, :spoiler, :nsfw, :hide, :mp3, :superdeluxe, :comedycentral, :revver,
62
+ :myspacetv, :collegehumor, :hulu, :metacafe, :yahoovid, :flickr, :gametrailers,
63
+ :slideshare, :funnyordie, :atomfilms, :vimeo, :li, :list, :current, :auto_link,
64
+ :url_with_title, :url_sans_title ]
65
+
66
+ TagGroups = { :video => [ :youtube, :googlevid, :flash, :superdeluxe, :comedycentral, :revver,
67
+ :myspacetv, :collegehumor, :hulu, :metacafe, :yahoovid, :gametrailers,
68
+ :funnyordie, :atomfilms, :vimeo ],
69
+ :image => [ :image, :flickr ] }
70
+
71
+ # Parses all bbcode in +text+ and returns a new HTML-formatted string.
72
+ def bbcodeize(text, options = Hash.new)
73
+ text = text.dup
74
+
75
+ disabled = Array.new
76
+ disabled += @deactivated if @deactivated
77
+ disabled += decode_tags(options[:disabled]) if options[:disabled]
78
+
79
+ (TagList - disabled).each do |tag|
80
+ if Tags.has_key?(tag)
81
+ apply_tag(text, tag)
82
+ else
83
+ self.send(tag, text)
84
+ end
85
+ # Replace the matching random ids for the following tags: spoiler, nsfw, mp3
86
+ @random_id = random_string
87
+ 2.times { text = text.sub('_RANDOM_ID_', @random_id) }
88
+ end
89
+ text
90
+ end
91
+
92
+ # Configuration option to deactivate particular +tags+.
93
+ def deactivate(*tags)
94
+ @deactivated ||= Array.new
95
+ @deactivated += decode_tags(*tags)
96
+ end
97
+
98
+ # Configuration option to reactivate particular +tags+.
99
+ def activate(*tags)
100
+ @deactivated ||= Array.new
101
+ @deactivated -= decode_tags(*tags)
102
+ end
103
+
104
+ # Configuration option to change the replacement string used for a particular +tag+. The source
105
+ # code should be referenced to determine what an appropriate replacement +string+ would be.
106
+ def replace_using(tag, string)
107
+ Tags[tag][1] = string
108
+ end
109
+
110
+ private
111
+
112
+ def code(string)
113
+ # code tags must match, else don't do any replacing.
114
+ if string.scan(Tags[:start_code].first).size == string.scan(Tags[:end_code].first).size
115
+ apply_tags(string, :start_code, :end_code)
116
+ # strip out newlines from within the tags and replace them with '<br />', otherwise
117
+ # simple_format will simply append a '<br />' to the newlines, creating double spaces
118
+ string.gsub!(/#{Tags[:start_code].last}.+?#{Tags[:end_code].last}/im) { |s| s.gsub(/\r\n?/, '<br />') }
119
+ end
120
+ end
121
+
122
+ def li(string)
123
+ # list tags must match, else don't do any replacing.
124
+ if string.scan(Tags[:start_li].first).size == string.scan(Tags[:end_li].first).size
125
+ apply_tags(string, :start_li, :end_li)
126
+ # strip out newlines from within the tags and replace them with '<br />', otherwise
127
+ # simple_format will simply append a '<br />' to the newlines, creating double spaces
128
+ string.gsub!(/#{Tags[:start_li].last}.+?#{Tags[:end_li].last}/im) { |s| s.gsub(/\r\n?/, '<br />') }
129
+ end
130
+ end
131
+
132
+ def list(string)
133
+ # list tags must match, else don't do any replacing.
134
+ if string.scan(Tags[:start_list].first).size == string.scan(Tags[:end_list].first).size
135
+ apply_tags(string, :start_list, :end_list)
136
+ # strip out newlines from within the tags and replace them with '<br />', otherwise
137
+ # simple_format will simply append a '<br />' to the newlines, creating double spaces
138
+ string.gsub!(/#{Tags[:start_list].last}.+?#{Tags[:end_list].last}/im) { |s| s.gsub(/\r\n?/, '<br />') }
139
+ end
140
+ end
141
+
142
+ def quote(string)
143
+ # quotes must match, else don't do any replacing
144
+ if string.scan(Tags[:start_quote].first).size == string.scan(Tags[:end_quote].first).size
145
+ apply_tags(string, :start_quote_with_cite, :start_quote_sans_cite, :end_quote)
146
+ # strip out newlines from within the tags and replace them with '<br />', otherwise
147
+ # simple_format will simply append a '<br />' to the newlines, creating double spaces
148
+ string.gsub!(/#{Tags[:start_quote].last}.+?#{Tags[:end_quote].last}/im) { |s| s.gsub(/\r\n?/, '<br />') }
149
+ end
150
+ end
151
+
152
+ def apply_tags(string, *tags)
153
+ tags.each do |tag|
154
+ string.gsub!(*Tags[tag])
155
+ end
156
+ end
157
+ alias_method :apply_tag, :apply_tags
158
+
159
+ def decode_tags(*tags)
160
+ tags.inject(Array.new) do |decoded_tags, tag|
161
+ decoded_tag = TagGroups.key?(tag) ? TagGroups[tag] : tag
162
+ decoded_tags + Array(decoded_tag)
163
+ end
164
+ end
165
+
166
+ # http://stackoverflow.com/questions/88311/how-best-to-generate-a-random-string-in-ruby
167
+ def random_string
168
+ (0...16).map{ ('a'..'z').to_a[rand(26)] }.join
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,3 @@
1
+ module Bbcodeizer
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'bbcodeizer'
2
+
3
+ module BBCodeizeHelper
4
+ # Parses all bbcode in +text+ and returns a new HTML-formatted string.
5
+ def bbcodeize(text, options = Hash.new)
6
+ BBCodeizer.bbcodeize(text, options)
7
+ end
8
+ end
@@ -0,0 +1,182 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
7
+
8
+ <title>Module: BBCodeizeHelper</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="./js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="./js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
15
+ <script src="./js/darkfish.js" type="text/javascript" charset="utf-8"></script>
16
+
17
+ </head>
18
+ <body id="top" class="module">
19
+
20
+ <div id="metadata">
21
+ <div id="home-metadata">
22
+ <div id="home-section" class="section">
23
+ <h3 class="section-header">
24
+ <a href="./index.html">Home</a>
25
+ <a href="./index.html#classes">Classes</a>
26
+ <a href="./index.html#methods">Methods</a>
27
+ </h3>
28
+ </div>
29
+ </div>
30
+
31
+ <div id="file-metadata">
32
+ <div id="file-list-section" class="section">
33
+ <h3 class="section-header">In Files</h3>
34
+ <div class="section-body">
35
+ <ul>
36
+
37
+ <li><a href="./lib/bbcodeizer_helper_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
38
+ class="thickbox" title="lib/bbcodeizer_helper.rb">lib/bbcodeizer_helper.rb</a></li>
39
+
40
+ </ul>
41
+ </div>
42
+ </div>
43
+
44
+
45
+ </div>
46
+
47
+ <div id="class-metadata">
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+ <!-- Method Quickref -->
56
+ <div id="method-list-section" class="section">
57
+ <h3 class="section-header">Methods</h3>
58
+ <ul class="link-list">
59
+
60
+ <li><a href="#method-i-bbcodeize">#bbcodeize</a></li>
61
+
62
+ </ul>
63
+ </div>
64
+
65
+
66
+
67
+ </div>
68
+
69
+ <div id="project-metadata">
70
+
71
+
72
+ <div id="fileindex-section" class="section project-section">
73
+ <h3 class="section-header">Files</h3>
74
+ <ul>
75
+
76
+ <li class="file"><a href="./README.html">README</a></li>
77
+
78
+ </ul>
79
+ </div>
80
+
81
+
82
+ <div id="classindex-section" class="section project-section">
83
+ <h3 class="section-header">Class/Module Index
84
+ <span class="search-toggle"><img src="./images/find.png"
85
+ height="16" width="16" alt="[+]"
86
+ title="show/hide quicksearch" /></span></h3>
87
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
88
+ <fieldset>
89
+ <legend>Quicksearch</legend>
90
+ <input type="text" name="quicksearch" value=""
91
+ class="quicksearch-field" />
92
+ </fieldset>
93
+ </form>
94
+
95
+ <ul class="link-list">
96
+
97
+ <li><a href="./BBCodeizeHelper.html">BBCodeizeHelper</a></li>
98
+
99
+ <li><a href="./Bbcodeizer.html">Bbcodeizer</a></li>
100
+
101
+ </ul>
102
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
103
+ </div>
104
+
105
+
106
+ </div>
107
+ </div>
108
+
109
+ <div id="documentation">
110
+ <h1 class="module">BBCodeizeHelper</h1>
111
+
112
+ <div id="description" class="description">
113
+
114
+ </div><!-- description -->
115
+
116
+
117
+
118
+
119
+ <div id="5Buntitled-5D" class="documentation-section">
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+ <!-- Methods -->
129
+
130
+ <div id="public-instance-method-details" class="method-section section">
131
+ <h3 class="section-header">Public Instance Methods</h3>
132
+
133
+
134
+ <div id="bbcodeize-method" class="method-detail ">
135
+ <a name="method-i-bbcodeize"></a>
136
+
137
+
138
+ <div class="method-heading">
139
+ <span class="method-name">bbcodeize</span><span
140
+ class="method-args">(text, options = Hash.new)</span>
141
+ <span class="method-click-advice">click to toggle source</span>
142
+ </div>
143
+
144
+
145
+ <div class="method-description">
146
+
147
+ <p>Parses all bbcode in <tt>text</tt> and returns a new HTML-formatted string.</p>
148
+
149
+
150
+
151
+ <div class="method-source-code" id="bbcodeize-source">
152
+ <pre>
153
+ <span class="ruby-comment"># File lib/bbcodeizer_helper.rb, line 5</span>
154
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">bbcodeize</span>(<span class="ruby-identifier">text</span>, <span class="ruby-identifier">options</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>)
155
+ <span class="ruby-constant">BBCodeizer</span>.<span class="ruby-identifier">bbcodeize</span>(<span class="ruby-identifier">text</span>, <span class="ruby-identifier">options</span>)
156
+ <span class="ruby-keyword">end</span></pre>
157
+ </div><!-- bbcodeize-source -->
158
+
159
+ </div>
160
+
161
+
162
+
163
+
164
+ </div><!-- bbcodeize-method -->
165
+
166
+
167
+ </div><!-- public-instance-method-details -->
168
+
169
+ </div><!-- 5Buntitled-5D -->
170
+
171
+
172
+ </div><!-- documentation -->
173
+
174
+ <div id="validator-badges">
175
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
176
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
177
+ Rdoc Generator</a> 2</small>.</p>
178
+ </div>
179
+
180
+ </body>
181
+ </html>
182
+