bb-ruby 0.9.5 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ coverage/*
2
+ doc
3
+ log
4
+ tmp
5
+ pkg
6
+ debug.log
7
+ config
8
+ script
9
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bb-ruby.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bb-ruby (0.9.8)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ bb-ruby!
data/History.txt CHANGED
@@ -1,3 +1,20 @@
1
+ == 0.9.8 2012-10-03
2
+
3
+ * replace deprecated html <u> tag
4
+ * added align tag for floating images
5
+ * fixed nested quotes
6
+
7
+ == 0.9.7 2012-08-20
8
+
9
+ * merged with marcandre's fork:
10
+ * Simplify dev setup using bundler
11
+ * Allow quotes in URL
12
+
13
+ == 0.9.6 2012-08-17
14
+
15
+ * added align tag for floating images and other things
16
+ * fixed nested quotes
17
+
1
18
  == 0.9.5 2010-02-26
2
19
 
3
20
  * added to_html_with_formatting(!) methods
data/Rakefile CHANGED
@@ -1,31 +1,11 @@
1
- %w[rubygems rake rake/clean fileutils newgem rubigen hoe].each { |f| require f }
2
- require File.dirname(__FILE__) + '/lib/bb-ruby'
3
-
4
- Hoe.plugin :newgem
5
- Hoe.plugin :website
6
-
7
- # Generate all the Rake tasks
8
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
9
- $hoe = Hoe.spec('bb-ruby') do |p|
10
- p.version = BBRuby::VERSION
11
- p.developer('Craig P Jolicoeur', 'cpjolicoeur@gmail.com')
12
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
13
- p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
14
- p.rubyforge_name = p.name # TODO this is default value
15
- p.extra_dev_deps = [
16
- ['newgem', ">= #{::Newgem::VERSION}"]
17
- ]
18
-
19
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
20
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
21
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
22
- p.rsync_args = '-av --delete --ignore-errors'
23
-
24
- p.readme_file = "README.rdoc"
25
- end
26
-
27
- require 'newgem/tasks' # load /tasks/*.rake
28
- Dir['tasks/**/*.rake'].each { |t| load t }
29
-
30
- # TODO - want other tests/tasks run by default? Add them to the list
31
- # task :default => [:spec, :features]
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = false
10
+ end
11
+
data/bb-ruby.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bb-ruby/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Craig P. Jolicoeur"]
6
+ gem.email = ["cpjolicoeur@gmail.com"]
7
+ gem.description = %q{BBCode for Ruby}
8
+ gem.summary = %q{BBRuby is a BBCode implementation for Ruby. It will convert strings with BBCode markup to their HTML equivalent}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "bb-ruby"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = BBRuby::VERSION
17
+ end
data/lib/bb-ruby.rb CHANGED
@@ -1,11 +1,9 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
1
+ require "bb-ruby/version"
3
2
 
4
3
  module BBRuby
5
- VERSION = '0.9.5'
6
-
7
4
  # allowable image formats
8
5
  @@imageformats = 'png|bmp|jpg|gif|jpeg'
6
+ @@quote_matcher = '(&quot;|&apos;|)'
9
7
 
10
8
  # built-in BBCode tabs that will be processed
11
9
  @@tags = {
@@ -24,7 +22,7 @@ module BBRuby
24
22
  :italics],
25
23
  'Underline' => [
26
24
  /\[u(:.+)?\](.*?)\[\/u\1?\]/mi,
27
- '<u>\2</u>',
25
+ '<span style="text-decoration:underline;">\2</span>',
28
26
  'Underline',
29
27
  'Use it for [u]important[/u] things or something',
30
28
  :underline],
@@ -53,14 +51,14 @@ module BBRuby
53
51
  '[code]some code[/code]',
54
52
  :code],
55
53
  'Size' => [
56
- /\[size=['"]?(.*?)['"]?\](.*?)\[\/size\]/im,
57
- '<span style="font-size: \1px;">\2</span>',
54
+ /\[size=#{@@quote_matcher}(.*?)\1\](.*?)\[\/size\]/im,
55
+ '<span style="font-size: \2px;">\3</span>',
58
56
  'Change text size',
59
57
  '[size=20]Here is some larger text[/size]',
60
58
  :size],
61
59
  'Color' => [
62
- /\[color=['"]?(\w+|\#\w{6})['"]?(:.+)?\](.*?)\[\/color\2?\]/im,
63
- '<span style="color: \1;">\3</span>',
60
+ /\[color=#{@@quote_matcher}(\w+|\#\w{6})\1(:.+)?\](.*?)\[\/color\3?\]/im,
61
+ '<span style="color: \2;">\4</span>',
64
62
  'Change text color',
65
63
  '[color=red]This is red text[/color]',
66
64
  :color],
@@ -89,7 +87,7 @@ module BBRuby
89
87
  '[*]list item',
90
88
  :listitem],
91
89
  'Unordered list (alternative)' => [
92
- /\[list(:.*)?\]((?:(?!list).)*)\[\/list(:.)?\1?\]/mi,
90
+ /\[list(:.*)?\]((?:(?!\[list(:.*)?\]).)*)\[\/list(:.)?\1?\]/mi,
93
91
  '<ul>\2</ul>',
94
92
  'Unordered list item',
95
93
  '[list][*]item 1[*] item2[/list]',
@@ -125,7 +123,7 @@ module BBRuby
125
123
  '[dd]my definition[/dd',
126
124
  :definition],
127
125
  'Quote' => [
128
- /\[quote(:.*)?="?(.*?)"?\](.*?)\[\/quote\1?\]/mi,
126
+ /\[quote(:.*)?=(?:&quot;)?(.*?)(?:&quot;)?\](.*?)\[\/quote\1?\]/mi,
129
127
  '<fieldset><legend>\2</legend><blockquote>\3</blockquote></fieldset>',
130
128
  'Quote with citation',
131
129
  "[quote=mike]Now is the time...[/quote]",
@@ -137,7 +135,7 @@ module BBRuby
137
135
  "[quote]Now is the time...[/quote]",
138
136
  :quote],
139
137
  'Link' => [
140
- /\[url=(.*?)\](.*?)\[\/url\]/mi,
138
+ /\[url=(?:&quot;)?(.*?)(?:&quot;)?\](.*?)\[\/url\]/mi,
141
139
  '<a href="\1">\2</a>',
142
140
  'Hyperlink to somewhere else',
143
141
  'Maybe try looking on [url=http://google.com]Google[/url]?',
@@ -153,17 +151,17 @@ module BBRuby
153
151
  ' <a href="\2">\2</a>',
154
152
  'Hyperlink (automatic)',
155
153
  'Maybe try looking on http://www.google.com',
156
- :link],
154
+ :link],
157
155
  'Image (Resized)' => [
158
- /\[img(:.+)? size=(['"]?)(\d+)x(\d+)\2\](.*?)\[\/img\1?\]/im,
156
+ /\[img(:.+)? size=#{@@quote_matcher}(\d+)x(\d+)\2\](.*?)\[\/img\1?\]/im,
159
157
  '<img src="\5" style="width: \3px; height: \4px;" />',
160
- 'Display an image with a set width and height',
158
+ 'Display an image with a set width and height',
161
159
  '[img size=96x96]http://www.google.com/intl/en_ALL/images/logo.gif[/img]',
162
160
  :image],
163
161
  'Image (Alternative)' => [
164
162
  /\[img=([^\[\]].*?)\.(#{@@imageformats})\]/im,
165
163
  '<img src="\1.\2" alt="" />',
166
- 'Display an image (alternative format)',
164
+ 'Display an image (alternative format)',
167
165
  '[img=http://myimage.com/logo.gif]',
168
166
  :image],
169
167
  'Image' => [
@@ -171,31 +169,31 @@ module BBRuby
171
169
  '<img src="\2.\3" alt="" />',
172
170
  'Display an image',
173
171
  'Check out this crazy cat: [img]http://catsweekly.com/crazycat.jpg[/img]',
174
- :image],
172
+ :image],
175
173
  'YouTube' => [
176
174
  /\[youtube\](.*?)\?v=([\w\d\-]+).*\[\/youtube\]/im,
177
175
  # '<object width="400" height="330"><param name="movie" value="http://www.youtube.com/v/\2"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\2" type="application/x-shockwave-flash" wmode="transparent" width="400" height="330"></embed></object>',
178
176
  '<object width="320" height="265"><param name="movie" value="http://www.youtube.com/v/\2"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/\2" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed></object>',
179
- 'Display a video from YouTube.com',
177
+ 'Display a video from YouTube.com',
180
178
  '[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube]',
181
179
  :video],
182
180
  'YouTube (Alternative)' => [
183
181
  /\[youtube\](.*?)\/v\/([\w\d\-]+)\[\/youtube\]/im,
184
182
  # '<object width="400" height="330"><param name="movie" value="http://www.youtube.com/v/\2"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\2" type="application/x-shockwave-flash" wmode="transparent" width="400" height="330"></embed></object>',
185
183
  '<object width="320" height="265"><param name="movie" value="http://www.youtube.com/v/\2"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/\2" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed></object>',
186
- 'Display a video from YouTube.com (alternative format)',
184
+ 'Display a video from YouTube.com (alternative format)',
187
185
  '[youtube]http://youtube.com/watch/v/E4Fbk52Mk1w[/youtube]',
188
186
  :video],
189
187
  'Vimeo' => [
190
188
  /\[vimeo\](.*?)\/(\d+)\[\/vimeo\]/im,
191
189
  '<object type="application/x-shockwave-flash" width="500" height="350" data="http://www.vimeo.com/moogaloop.swf?clip_id=\2"><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" /></object>',
192
- 'Display a video from Vimeo',
190
+ 'Display a video from Vimeo',
193
191
  '[vimeo]http://www.vimeo.com/3485239[/vimeo]',
194
192
  :video],
195
193
  'Google Video' => [
196
194
  /\[gvideo\](.*?)\?docid=([-]{0,1}\d+).*\[\/gvideo\]/mi,
197
195
  '<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=\2" flashvars=""> </embed>',
198
- 'Display a video from Google Video',
196
+ 'Display a video from Google Video',
199
197
  '[gvideo]http://video.google.com/videoplay?docid=-2200109535941088987[/gvideo]',
200
198
  :video],
201
199
  'Email' => [
@@ -203,7 +201,13 @@ module BBRuby
203
201
  '<a href="mailto:\2">\2</a>',
204
202
  'Link to email address',
205
203
  '[email]wadus@wadus.com[/email]',
206
- :email]
204
+ :email],
205
+ 'Align' => [
206
+ /\[align=(.*?)\](.*?)\[\/align\]/mi,
207
+ "<span class=\"bb-ruby_align_\\1\" style=\"float:\\1;\">\\2</span>",
208
+ 'Align this object using float',
209
+ 'Here\'s a wrapped image: [align=right][img]image.png[/img][/align]',
210
+ :align]
207
211
  }
208
212
 
209
213
  class << self
@@ -245,24 +249,27 @@ module BBRuby
245
249
  #
246
250
  def to_html(text, tags_alternative_definition={}, escape_html=true, method=:disable, *tags)
247
251
  text = process_tags(text, tags_alternative_definition, escape_html, method, *tags)
248
-
252
+
249
253
  # parse spacing
250
254
  text.gsub!( /\r\n?/, "\n" )
251
255
  text.gsub!( /\n/, "<br />\n" )
256
+ text.gsub!(/\[quote\]/, '<fieldset><legend>Quote:</legend><blockquote>')
257
+ text.gsub!(/\[quote(:.*)?="?(.*?)"?\]/, '<fieldset><legend>Quote: \2</legend><blockquote>')
258
+ text.gsub!(/\[\/quote\]/, '</blockquote></fieldset>')
252
259
 
253
260
  # return markup
254
261
  text
255
262
  end
256
-
263
+
257
264
  # The same as BBRuby.to_html except the output is passed through simple_format first
258
265
  #
259
- # Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(\n\n)
260
- # are considered as a paragraph and wrapped in <p> tags. One newline (\n) is considered as a linebreak and
266
+ # Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(\n\n)
267
+ # are considered as a paragraph and wrapped in <p> tags. One newline (\n) is considered as a linebreak and
261
268
  # a <br /> tag is appended. This method does not remove the newlines from the text.
262
269
  #
263
270
  def to_html_with_formatting(text, tags_alternative_definition={}, escape_html=true, method=:disable, *tags)
264
271
  text = process_tags(text, tags_alternative_definition, escape_html, method, *tags)
265
-
272
+
266
273
  # parse spacing
267
274
  simple_format( text )
268
275
  end
@@ -271,19 +278,21 @@ module BBRuby
271
278
  def tag_list
272
279
  @@tags
273
280
  end
274
-
281
+
275
282
  private
276
-
283
+
277
284
  def process_tags(text, tags_alternative_definition={}, escape_html=true, method=:disable, *tags)
278
285
  text = text.dup
279
-
280
- # escape "<, >, &" to remove any html
286
+
287
+ # escape "<, >, &" and quotes to remove any html
281
288
  if escape_html
282
289
  text.gsub!( '&', '&amp;' )
283
290
  text.gsub!( '<', '&lt;' )
284
291
  text.gsub!( '>', '&gt;' )
292
+ text.gsub!( '"', '&quot;' )
293
+ text.gsub!( "'", '&apos;' )
285
294
  end
286
-
295
+
287
296
  tags_definition = @@tags.merge(tags_alternative_definition)
288
297
 
289
298
  # parse bbcode tags
@@ -294,10 +303,10 @@ module BBRuby
294
303
  # this works nicely because the default is disable and the default set of tags is [] (so none disabled) :)
295
304
  tags_definition.each_value { |t| text.gsub!(t[0], t[1]) unless tags.include?(t[4]) }
296
305
  end
297
-
306
+
298
307
  text
299
308
  end
300
-
309
+
301
310
  # extracted from Rails ActionPack
302
311
  def simple_format( text )
303
312
  start_tag = '<p>'
@@ -310,7 +319,8 @@ module BBRuby
310
319
  end
311
320
  end # class << self
312
321
 
313
- end # class BBRuby
322
+ end
323
+
314
324
 
315
325
  class String
316
326
  # Convert a string with BBCode markup into its corresponding HTML markup
@@ -0,0 +1,3 @@
1
+ module BBRuby
2
+ VERSION = "0.9.8"
3
+ end
@@ -1,4 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
+ #coding: utf-8
2
3
 
3
4
  require File.dirname(__FILE__) + '/test_helper.rb'
4
5
 
@@ -11,47 +12,51 @@ class TestBBRuby < Test::Unit::TestCase
11
12
  assert_equal "<strong>line 1<br />\nline 2</strong>", "[b:7a9ca2c5c3]line 1\nline 2[/b:7a9ca2c5c3]".bbcode_to_html
12
13
  assert_equal "<strong>1. text 1:</strong> text 2<br />\n<strong>2. text 3</strong>", "[b:post_uid0]1. text 1:[/b:post_uid0] text 2\n[b:post_uid0]2. text 3[/b:post_uid0]".bbcode_to_html
13
14
  end
14
-
15
+
15
16
  def test_em
16
17
  assert_equal '<em>simple</em>', '[i]simple[/i]'.bbcode_to_html
17
18
  assert_equal '<em>simple</em>', '[i:7a9ca2c5c3]simple[/i:7a9ca2c5c3]'.bbcode_to_html
18
19
  assert_equal "<em>line 1<br />\nline 2</em>", "[i:7a9ca2c5c3]line 1\nline 2[/i:7a9ca2c5c3]".bbcode_to_html
19
20
  end
20
-
21
+
21
22
  def test_u
22
- assert_equal '<u>simple</u>', '[u]simple[/u]'.bbcode_to_html
23
- assert_equal '<u>simple</u>', '[u:7a9ca2c5c3]simple[/u:7a9ca2c5c3]'.bbcode_to_html
24
- assert_equal "<u>line 1<br />\nline 2</u>", "[u:7a9ca2c5c3]line 1\nline 2[/u:7a9ca2c5c3]".bbcode_to_html
23
+ assert_equal '<span style="text-decoration:underline;">simple</span>', '[u]simple[/u]'.bbcode_to_html
24
+ assert_equal '<span style="text-decoration:underline;">simple</span>', '[u:7a9ca2c5c3]simple[/u:7a9ca2c5c3]'.bbcode_to_html
25
+ assert_equal '<span style="text-decoration:underline;">line 1<br />\nline 2</span>', "[u:7a9ca2c5c3]line 1\nline 2[/u:7a9ca2c5c3]".bbcode_to_html
25
26
  end
26
-
27
+
27
28
  def test_del
28
29
  assert_equal '<del>simple</del>', '[del]simple[/del]'.bbcode_to_html
29
30
  assert_equal '<del>simple</del>', '[del:7a9ca2c5c3]simple[/del:7a9ca2c5c3]'.bbcode_to_html
30
31
  assert_equal '<del>simple</del>', '[s]simple[/s]'.bbcode_to_html
31
32
  assert_equal '<del>simple</del>', '[s:7a9ca2c5c3]simple[/s:7a9ca2c5c3]'.bbcode_to_html
32
33
  end
33
-
34
+
34
35
  def test_ins
35
36
  assert_equal '<ins>simple</ins>', '[ins]simple[/ins]'.bbcode_to_html
36
37
  assert_equal '<ins>simple</ins>', '[ins:7a9ca2c5c3]simple[/ins:7a9ca2c5c3]'.bbcode_to_html
37
- end
38
-
38
+ end
39
+
39
40
  def test_code
40
41
  assert_equal '<code>simple</code>', '[code]simple[/code]'.bbcode_to_html
41
42
  assert_equal '<code>simple</code>', '[code:7a9ca2c5c3]simple[/code:7a9ca2c5c3]'.bbcode_to_html
42
43
  assert_equal "<code>var bxi = 0;<br />\n//Holds current speed of scrolling menu</code>", "[code:1:91cbdd72b7]var bxi = 0;\n//Holds current speed of scrolling menu[/code:1:91cbdd72b7]".bbcode_to_html
43
- end
44
-
44
+ end
45
+
45
46
  def test_size
46
47
  assert_equal '<span style="font-size: 32px;">12px Text</span>', '[size=32]12px Text[/size]'.bbcode_to_html
48
+ assert_equal '<span style="font-size: 32px;">12px Text</span>', '[size="32"]12px Text[/size]'.bbcode_to_html
49
+ assert_equal '<span style="font-size: 32px;">12px Text</span>', '[size=\'32\']12px Text[/size]'.bbcode_to_html
47
50
  end
48
-
51
+
49
52
  def test_color
50
53
  assert_equal '<span style="color: red;">Red Text</span>', '[color=red]Red Text[/color]'.bbcode_to_html
54
+ assert_equal '<span style="color: red;">Red Text</span>', '[color="red"]Red Text[/color]'.bbcode_to_html
55
+ assert_equal '<span style="color: red;">Red Text</span>', '[color=\'red\']Red Text[/color]'.bbcode_to_html
51
56
  assert_equal '<span style="color: #ff0023;">Hex Color Text</span>', '[color=#ff0023]Hex Color Text[/color]'.bbcode_to_html
52
57
  assert_equal '<span style="color: #B23803;">text</span>', '[color=#B23803:05d7c56429]text[/color:05d7c56429]'.bbcode_to_html
53
58
  end
54
-
59
+
55
60
  def test_ordered_list
56
61
  assert_equal '<ol><li>item 1</li><li>item 2</li></ol>', '[ol][li]item 1[/li][li]item 2[/li][/ol]'.bbcode_to_html
57
62
  assert_equal '<ol><li>item 1</li><li>item 2</li></ol>', '[ol][*]item 1[*]item 2[/ol]'.bbcode_to_html
@@ -61,16 +66,18 @@ class TestBBRuby < Test::Unit::TestCase
61
66
  assert_equal '<ul><li>item 1</li><li>item 2</li></ul>', '[ul][li]item 1[/li][li]item 2[/li][/ul]'.bbcode_to_html
62
67
  assert_equal '<ul><li>item 1</li><li>item 2</li></ul>', '[ul][*]item 1[*]item 2[/ul]'.bbcode_to_html
63
68
  end
64
-
69
+
65
70
  def test_list_unordered
66
71
  assert_equal '<ul><li>item 1</li><li>item 2</li></ul>', '[list][li]item 1[/li][li]item 2[/li][/list]'.bbcode_to_html
72
+ #Added this test which raising an error because of the "list" word in list items.
73
+ assert_equal '<ul><li>list item 1</li><li>list item 2</li></ul>', '[list][li]list item 1[/li][li]list item 2[/li][/list]'.bbcode_to_html
67
74
  assert_equal '<ul><li>item 1</li><li>item 2</li></ul>', '[list:7a9ca2c5c3][li]item 1[/li][li]item 2[/li][/list:o:7a9ca2c5c3]'.bbcode_to_html
68
- assert_equal '<ul><li>item 1</li><li>item 2</li></ul><ul><li>item 3</li><li>item 4</li></ul>',
75
+ assert_equal '<ul><li>item 1</li><li>item 2</li></ul><ul><li>item 3</li><li>item 4</li></ul>',
69
76
  '[list:7a9ca2c5c3][li]item 1[/li][li]item 2[/li][/list:o:7a9ca2c5c3][list:7a9ca2c5c3][li]item 3[/li][li]item 4[/li][/list:o:7a9ca2c5c3]'.bbcode_to_html
70
- assert_equal '<ul><li>item 1</li><li>item 2</li></ul><ul><li>item 3</li><li>item 4</li></ul><ul><li>item 5</li><li>item 6</li></ul><ul><li>item 7</li><li>item 8</li></ul>',
77
+ assert_equal '<ul><li>item 1</li><li>item 2</li></ul><ul><li>item 3</li><li>item 4</li></ul><ul><li>item 5</li><li>item 6</li></ul><ul><li>item 7</li><li>item 8</li></ul>',
71
78
  '[list:7a9ca2c5c3][li]item 1[/li][li]item 2[/li][/list:o:7a9ca2c5c3][list:7a9ca2c5c3][li]item 3[/li][li]item 4[/li][/list:o:7a9ca2c5c3][list:7a9ca2c5c3][li]item 5[/li][li]item 6[/li][/list:o:7a9ca2c5c3][list:7a9ca2c5c3][li]item 7[/li][li]item 8[/li][/list:o:7a9ca2c5c3]'.bbcode_to_html
72
79
  end
73
-
80
+
74
81
  def test_list_unordered_alternative
75
82
  assert_equal '<li>item1</li><li>item2</li>', '[*:asdf]item1[*:asdf]item2'.bbcode_to_html
76
83
  assert_equal '<ul><li>item1</li><li>item2</li></ul>', '[list:5d7cf5560a][*]item1[*]item2[/list:u:5d7cf5560a]'.bbcode_to_html
@@ -86,61 +93,65 @@ class TestBBRuby < Test::Unit::TestCase
86
93
  assert_equal '<ol sytle="list-style-type: lower-alpha;"><li>item 1</li><li>item 2</li></ol>', '[list=a][li]item 1[/li][li]item 2[/li][/list]'.bbcode_to_html
87
94
  assert_equal '<ol sytle="list-style-type: lower-alpha;"><li>item 1</li><li>item 2</li></ol>', '[list=a:7a9ca2c5c3][li]item 1[/li][li]item 2[/li][/list:o:7a9ca2c5c3]'.bbcode_to_html
88
95
  end
89
-
96
+
90
97
  def test_two_lists
91
- assert_equal '<ul><li>item1</li><li>item2</li></ul><ul><li>item1</li><li>item2</li></ul>',
98
+ assert_equal '<ul><li>item1</li><li>item2</li></ul><ul><li>item1</li><li>item2</li></ul>',
92
99
  '[list:5d7cf5560a][*:5d7cf5560a]item1[*:5d7cf5560a]item2[/list:u:5d7cf5560a][list:5d7cf5560a][*:5d7cf5560a]item1[*:5d7cf5560a]item2[/list:u:5d7cf5560a]'.bbcode_to_html
93
100
  end
94
-
101
+
95
102
  def test_definition_list_term_definition
96
103
  assert_equal '<dl><dt>term 1</dt><dd>definition 1</dd><dt>term 2</dt><dd>definition 2</dd></dl>', '[dl][dt]term 1[/dt][dd]definition 1[/dd][dt]term 2[/dt][dd]definition 2[/dd][/dl]'.bbcode_to_html
97
104
  end
98
-
105
+
99
106
  def test_quote
100
107
  assert_equal '<fieldset><blockquote>quoting</blockquote></fieldset>', '[quote]quoting[/quote]'.bbcode_to_html
101
108
  assert_equal '<fieldset><blockquote>quoting</blockquote></fieldset>', '[quote]quoting[/quote]'.bbcode_to_html.bbcode_to_html({}, false, :disable)
102
- assert_equal '<fieldset><legend>black</legend><blockquote>si el niño hubiera sido de "penalty" le hubieran llamado <strong>system Error</strong>!!! :)</blockquote></fieldset>', "[quote:7a9ca2c5c3=\"black\"]si el niño hubiera sido de \"penalty\" le hubieran llamado [b:7a9ca2c5c3]system Error[/b:7a9ca2c5c3]!!! :)[/quote:7a9ca2c5c3]".bbcode_to_html
103
- assert_equal '<fieldset><legend>black</legend><blockquote>si el niño hubiera sido de "penalty" le hubieran llamado <strong>system Error</strong>!!! :)</blockquote></fieldset>', "[quote:7a9ca2c5c3=\"black\"]si el niño hubiera sido de \"penalty\" le hubieran llamado [b:7a9ca2c5c3]system Error[/b:7a9ca2c5c3]!!! :)[/quote:7a9ca2c5c3]".bbcode_to_html.bbcode_to_html({}, false, :disable)
109
+ assert_equal '<fieldset><legend>black</legend><blockquote>si el niño hubiera sido de &quot;penalty&quot; le hubieran llamado <strong>system Error</strong>!!! :)</blockquote></fieldset>', "[quote:7a9ca2c5c3=\"black\"]si el niño hubiera sido de \"penalty\" le hubieran llamado [b:7a9ca2c5c3]system Error[/b:7a9ca2c5c3]!!! :)[/quote:7a9ca2c5c3]".bbcode_to_html
110
+ assert_equal '<fieldset><legend>black</legend><blockquote>si el niño hubiera sido de &quot;penalty&quot; le hubieran llamado <strong>system Error</strong>!!! :)</blockquote></fieldset>', "[quote:7a9ca2c5c3=\"black\"]si el niño hubiera sido de \"penalty\" le hubieran llamado [b:7a9ca2c5c3]system Error[/b:7a9ca2c5c3]!!! :)[/quote:7a9ca2c5c3]".bbcode_to_html.bbcode_to_html({}, false, :disable)
104
111
  assert_equal '<fieldset><legend>Who</legend><blockquote>said that</blockquote></fieldset>', '[quote=Who]said that[/quote]'.bbcode_to_html
105
112
  assert_equal '<fieldset><legend>Who</legend><blockquote>said that</blockquote></fieldset>', '[quote=Who]said that[/quote]'.bbcode_to_html.bbcode_to_html({}, false, :disable)
106
113
  end
107
-
114
+
108
115
  def test_double_quote
109
116
  assert_equal '<fieldset><legend>Kitten</legend><blockquote><fieldset><legend>creatiu</legend><blockquote>f1</blockquote></fieldset>f2</blockquote></fieldset>',
110
117
  '[quote:26fe26a6a9="Kitten"][quote:26fe26a6a93="creatiu"]f1[/quote:26fe26a6a93]f2[/quote:26fe26a6a9]'.bbcode_to_html.bbcode_to_html({}, false, :disable)
111
118
  end
112
-
119
+
113
120
  def test_link
114
121
  assert_equal '<a href="http://google.com">Google</a>', '[url=http://google.com]Google[/url]'.bbcode_to_html
115
122
  assert_equal '<a href="http://google.com">http://google.com</a>', '[url]http://google.com[/url]'.bbcode_to_html
116
123
  assert_equal '<a href="http://www.altctrlsupr.com/dmstk/kdd070803/00.html"> ABRIR ALBUM </a>','[URL=http://www.altctrlsupr.com/dmstk/kdd070803/00.html] ABRIR ALBUM [/URL]'.bbcode_to_html
117
124
  assert_equal %Q(<a href="http://www.altctrlsupr.com/dmstk/kdd070803/00.html"> ABRIR<br />\nALBUM </a>),"[URL=http://www.altctrlsupr.com/dmstk/kdd070803/00.html] ABRIR\nALBUM [/URL]".bbcode_to_html
118
125
  assert_equal '<a href="http://www.urimalet.com/cadaverex.mp3">aha</a>', "[URL=http://www.urimalet.com/cadaverex.mp3]aha[/URL]".bbcode_to_html
126
+ # allow quoted urls:
127
+ assert_equal '<a href="http://www.apple.com">aha</a>', '[URL="http://www.apple.com"]aha[/URL]'.bbcode_to_html
119
128
  end
120
-
129
+
121
130
  def test_image
122
131
  assert_equal '<img src="http://zoople/hochzeit.png" alt="" />', '[img]http://zoople/hochzeit.png[/img]'.bbcode_to_html
123
132
  assert_equal '<img src="http://zoople/hochzeit.png" alt="" />', '[img=http://zoople/hochzeit.png]'.bbcode_to_html
124
133
  assert_equal '<img src="http://zoople/hochzeit.png" style="width: 95px; height: 96px;" />', '[img size=95x96]http://zoople/hochzeit.png[/img]'.bbcode_to_html
125
134
  assert_equal '<img src="http://zoople/hochzeit.png" alt="" />', '[img:7a9ca2c5c3]http://zoople/hochzeit.png[/img:7a9ca2c5c3]'.bbcode_to_html
126
135
  assert_equal '<img src="http://zoople/hochzeit.png" style="width: 95px; height: 96px;" />', '[img:7a9ca2c5c3 size=95x96]http://zoople/hochzeit.png[/img:7a9ca2c5c3]'.bbcode_to_html
136
+ assert_equal '<img src="http://zoople/hochzeit.png" style="width: 95px; height: 96px;" />', '[img:7a9ca2c5c3 size="95x96"]http://zoople/hochzeit.png[/img:7a9ca2c5c3]'.bbcode_to_html
137
+ assert_equal '<img src="http://zoople/hochzeit.png" style="width: 95px; height: 96px;" />', '[img:7a9ca2c5c3 size=\'95x96\']http://zoople/hochzeit.png[/img:7a9ca2c5c3]'.bbcode_to_html
127
138
  assert_equal '<img src="http://www.marcodigital.com/sitanddie/sitanddiepequeño.jpg" alt="" />', '[img:post_uid0]http://www.marcodigital.com/sitanddie/sitanddiepequeño.jpg[/img:post_uid0]'.bbcode_to_html
128
139
  end
129
-
140
+
130
141
  def test_youtube
131
142
  # Uncomment below if using 4:3 format youtube video embed
132
143
  # assert_equal '<object width="320" height="265"><param name="movie" value="http://www.youtube.com/v/E4Fbk52Mk1w"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/E4Fbk52Mk1w" type="application/x-shockwave-flash" wmode="transparent" width="320" height="265"></embed></object>','[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube]'.bbcode_to_html
133
144
  assert_equal '<object width="320" height="265"><param name="movie" value="http://www.youtube.com/v/E4Fbk52Mk1w"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/E4Fbk52Mk1w" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed></object>', '[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube]'.bbcode_to_html
134
145
  end
135
-
146
+
136
147
  def test_vimeo
137
148
  assert_equal '<object type="application/x-shockwave-flash" width="500" height="350" data="http://www.vimeo.com/moogaloop.swf?clip_id=3485239"><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=3485239" /></object>', '[vimeo]http://www.vimeo.com/3485239[/vimeo]'.bbcode_to_html
138
149
  end
139
-
150
+
140
151
  def test_google_video
141
152
  assert_equal '<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-2200109535941088987" flashvars=""> </embed>', '[gvideo]http://video.google.com/videoplay?docid=-2200109535941088987[/gvideo]'.bbcode_to_html
142
153
  end
143
-
154
+
144
155
  def test_email
145
156
  assert_equal '<a href="mailto:wadus@wadus.com">wadus@wadus.com</a>', '[email]wadus@wadus.com[/email]'.bbcode_to_html
146
157
  end
@@ -160,6 +171,8 @@ class TestBBRuby < Test::Unit::TestCase
160
171
  assert_equal "1 is < 2", '1 is < 2'.bbcode_to_html({}, false)
161
172
  assert_equal "2 is &gt; 1", '2 is > 1'.bbcode_to_html
162
173
  assert_equal "2 is > 1", '2 is > 1'.bbcode_to_html({}, false)
174
+ assert_equal %Q{&quot;double quotes&quot; and &apos;single quotes&apos;}, %Q{"double quotes" and 'single quotes'}.bbcode_to_html
175
+ assert_equal %Q{"double quotes" and 'single quotes'}, %Q{"double quotes" and 'single quotes'}.bbcode_to_html({}, false)
163
176
  end
164
177
 
165
178
  def test_disable_tags
@@ -179,12 +192,12 @@ class TestBBRuby < Test::Unit::TestCase
179
192
  assert_equal "<strong>foobar</strong>", foo.bbcode_to_html!
180
193
  assert_equal "<strong>foobar</strong>", foo
181
194
  end
182
-
195
+
183
196
  def test_to_html_with_no_markup
184
197
  foo = "first paragraph\n\nsecond paragraph\nwith a linebreak"
185
198
  assert_equal "first paragraph<br />\n<br />\nsecond paragraph<br />\nwith a linebreak", foo.bbcode_to_html
186
199
  end
187
-
200
+
188
201
  def test_to_html_with_formatting
189
202
  foo = "first paragraph\n\nsecond paragraph\nwith a linebreak"
190
203
  assert_equal %Q(<p>first paragraph</p>\n\n<p>second paragraph\n<br />with a linebreak</p>), foo.bbcode_to_html_with_formatting
@@ -193,11 +206,11 @@ class TestBBRuby < Test::Unit::TestCase
193
206
  def test_self_tag_list
194
207
  assert_equal 32, BBRuby.tag_list.size
195
208
  end
196
-
209
+
197
210
  def test_redefinition_of_tag_html
198
211
  mydef = {
199
212
  'Quote' => [
200
- /\[quote(:.*)?="?(.*?)"?\](.*?)\[\/quote\1?\]/mi,
213
+ /\[quote(:.*)?=(?:&quot;)?(.*?)(?:&quot;)?\](.*?)\[\/quote\1?\]/mi,
201
214
  '<div class="quote"><p><cite>\2</cite></p><blockquote>\3</blockquote></div>',
202
215
  'Quote with citation',
203
216
  nil, nil,
@@ -205,13 +218,13 @@ class TestBBRuby < Test::Unit::TestCase
205
218
  'Image (Resized)' => [
206
219
  /\[img(:.+)? size=(['"]?)(\d+)x(\d+)\2\](.*?)\[\/img\1?\]/im,
207
220
  '<div class="post_image"><img src="\5" style="width: \3px; height: \4px;" /></div>',
208
- 'Display an image with a set width and height',
221
+ 'Display an image with a set width and height',
209
222
  '[img size=96x96]http://www.google.com/intl/en_ALL/images/logo.gif[/img]',
210
223
  :image],
211
224
  'Image (Alternative)' => [
212
225
  /\[img=([^\[\]].*?)\.(png|bmp|jpg|gif|jpeg)\]/im,
213
226
  '<div class="post_image"><img src="\1.\2" alt="" /></div>',
214
- 'Display an image (alternative format)',
227
+ 'Display an image (alternative format)',
215
228
  '[img=http://myimage.com/logo.gif]',
216
229
  :image],
217
230
  'Image' => [
@@ -219,7 +232,7 @@ class TestBBRuby < Test::Unit::TestCase
219
232
  '<div class="post_image"><img src="\2.\3" alt="" /></div>',
220
233
  'Display an image',
221
234
  'Check out this crazy cat: [img]http://catsweekly.com/crazycat.jpg[/img]',
222
- :image],
235
+ :image],
223
236
  }
224
237
  assert_equal '<div class="quote"><p><cite>Who</cite></p><blockquote>said that</blockquote></div>', '[quote=Who]said that[/quote]'.bbcode_to_html(mydef)
225
238
  assert_equal '<div class="quote"><p><cite>flandepan</cite></p><blockquote>hola</blockquote></div>', '[quote:0fc8a224d2="flandepan"]hola[/quote:0fc8a224d2]'.bbcode_to_html(mydef)
@@ -227,12 +240,12 @@ class TestBBRuby < Test::Unit::TestCase
227
240
  end
228
241
 
229
242
  def test_multiple_tag_test
230
- assert_equal "<strong>bold</strong><em>italic</em><u>underline</u><fieldset><blockquote>quote</blockquote></fieldset><a href=\"foobar\">link</a>", "[b]bold[/b][i]italic[/i][u]underline[/u][quote]quote[/quote][url=foobar]link[/url]".bbcode_to_html
231
- assert_equal "<strong>bold</strong><em>italic</em><u>underline</u><fieldset><blockquote>quote</blockquote></fieldset><a href=\"foobar\">link</a>", "[b]bold[/b][i]italic[/i][u]underline[/u][quote]quote[/quote][url=foobar]link[/url]".bbcode_to_html({}, true, :enable, :bold, :italics, :underline, :link, :quote)
243
+ assert_equal "<strong>bold</strong><em>italic</em><span style=\"text-decoration:underline;\">underline</span><fieldset><blockquote>quote</blockquote></fieldset><a href=\"foobar\">link</a>", "[b]bold[/b][i]italic[/i][u]underline[/u][quote]quote[/quote][url=foobar]link[/url]".bbcode_to_html
244
+ assert_equal "<strong>bold</strong><em>italic</em><span style=\"text-decoration:underline;\">underline</span><fieldset><blockquote>quote</blockquote></fieldset><a href=\"foobar\">link</a>", "[b]bold[/b][i]italic[/i][u]underline[/u][quote]quote[/quote][url=foobar]link[/url]".bbcode_to_html({}, true, :enable, :bold, :italics, :underline, :link, :quote)
232
245
  end
233
246
 
234
247
  def test_no_ending_tag
235
- assert_equal "this [b]should not be bold", "this [b]should not be bold".bbcode_to_html
248
+ assert_equal "this [b]should not be bold", "this [b]should not be bold".bbcode_to_html
236
249
  end
237
250
 
238
251
  def test_no_start_tag
metadata CHANGED
@@ -1,86 +1,59 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bb-ruby
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.8
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
- - Craig P Jolicoeur
7
+ authors:
8
+ - Craig P. Jolicoeur
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2010-02-26 00:00:00 -05:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: newgem
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.5.2
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: hoe
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 2.3.2
34
- version:
35
- description: BBRuby is a BBCode (http://www.bbcode.org) implementation for Ruby. It will convert strings with BBCode markup to their HTML equivalent.
36
- email:
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: BBCode for Ruby
15
+ email:
37
16
  - cpjolicoeur@gmail.com
38
17
  executables: []
39
-
40
18
  extensions: []
41
-
42
- extra_rdoc_files:
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Gemfile.lock
43
24
  - History.txt
44
- - Manifest.txt
45
- - PostInstall.txt
46
- files:
47
- - History.txt
48
- - Manifest.txt
49
- - PostInstall.txt
50
25
  - README.rdoc
51
26
  - Rakefile
27
+ - bb-ruby.gemspec
52
28
  - lib/bb-ruby.rb
53
- - test/test_bb-ruby.rb
29
+ - lib/bb-ruby/version.rb
30
+ - test/bb-ruby_test.rb
54
31
  - test/test_helper.rb
55
- has_rdoc: true
56
- homepage: http://bb-ruby.rubyforge.org
32
+ homepage: ''
57
33
  licenses: []
58
-
59
- post_install_message: PostInstall.txt
60
- rdoc_options:
61
- - --main
62
- - README.rdoc
63
- require_paths:
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
64
37
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- version:
71
- required_rubygems_version: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: "0"
76
- version:
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
77
50
  requirements: []
78
-
79
- rubyforge_project: bb-ruby
80
- rubygems_version: 1.3.5
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.21
81
53
  signing_key:
82
54
  specification_version: 3
83
- summary: BBRuby is a BBCode (http://www.bbcode.org) implementation for Ruby
84
- test_files:
85
- - test/test_bb-ruby.rb
55
+ summary: BBRuby is a BBCode implementation for Ruby. It will convert strings with
56
+ BBCode markup to their HTML equivalent
57
+ test_files:
58
+ - test/bb-ruby_test.rb
86
59
  - test/test_helper.rb
data/Manifest.txt DELETED
@@ -1,8 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- PostInstall.txt
4
- README.rdoc
5
- Rakefile
6
- lib/bb-ruby.rb
7
- test/test_bb-ruby.rb
8
- test/test_helper.rb
data/PostInstall.txt DELETED
@@ -1,2 +0,0 @@
1
-
2
- For more information on bb-ruby, see http://bb-ruby.rubyforge.org