Skip to content

Commit

Permalink
Merge pull request cpjolicoeur#29 from cpjolicoeur/acre/master
Browse files Browse the repository at this point in the history
ACRE suggest 3 changes to master.
  • Loading branch information
cpjolicoeur committed Aug 28, 2014
2 parents 60a9f6f + aec1931 commit 8ed7498
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
10 changes: 5 additions & 5 deletions lib/bb-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ module BBRuby
/\[quote(:.*)?=(?:")?(.*?)(?:")?\](.*?)\[\/quote\1?\]/mi,
'<fieldset><legend>\2</legend><blockquote>\3</blockquote></fieldset>',
'Quote with citation',
"[quote=mike]Now is the time...[/quote]",
'[quote=mike]Now is the time...[/quote]',
:quote],
'Quote (Sourceless)' => [
/\[quote(:.*)?\](.*?)\[\/quote\1?\]/mi,
'<fieldset><blockquote>\2</blockquote></fieldset>',
'Quote (sourceclass)',
"[quote]Now is the time...[/quote]",
'[quote]Now is the time...[/quote]',
:quote],
'Link' => [
/\[url=(?:&quot;)?(.*?)(?:&quot;)?\](.*?)\[\/url\]/mi,
Expand All @@ -142,10 +142,10 @@ module BBRuby
/\[url\](.*?)\[\/url\]/mi,
'<a href="\1">\1</a>',
'Hyperlink (implied)',
"Maybe try looking on [url]http://google.com[/url]",
'Maybe try looking on [url]http://google.com[/url]',
:link],
'Link (Automatic)' => [
/(\A|\s)(https?:\/\/[^\s<]+)/,
%r{(\A|\s)(https?://[^\s<]+)},
' <a href="\2">\2</a>',
'Hyperlink (automatic)',
'Maybe try looking on http://www.google.com',
Expand Down Expand Up @@ -331,7 +331,7 @@ def simple_format( text )
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline => paragraph
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline => br
text.insert 0, start_tag
text << "</p>"
text << '</p>'
end
end # class << self

Expand Down
2 changes: 1 addition & 1 deletion lib/bb-ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BBRuby
VERSION = "1.0.4"
VERSION = '1.0.4'
end
50 changes: 25 additions & 25 deletions test/bb-ruby_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_link
assert_equal '<a href="http://google.com">http://google.com</a>', '[url]http://google.com[/url]'.bbcode_to_html
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
assert_equal %Q(<a href="http://www.altctrlsupr.com/dmstk/kdd070803/00.html"> ABRIR\nALBUM </a>),"[URL=http://www.altctrlsupr.com/dmstk/kdd070803/00.html] ABRIR\nALBUM [/URL]".bbcode_to_html
assert_equal '<a href="http://www.urimalet.com/cadaverex.mp3">aha</a>', "[URL=http://www.urimalet.com/cadaverex.mp3]aha[/URL]".bbcode_to_html
assert_equal '<a href="http://www.urimalet.com/cadaverex.mp3">aha</a>', '[URL=http://www.urimalet.com/cadaverex.mp3]aha[/URL]'.bbcode_to_html
# allow quoted urls:
assert_equal '<a href="http://www.apple.com">aha</a>', '[URL="http://www.apple.com"]aha[/URL]'.bbcode_to_html
end
Expand Down Expand Up @@ -170,34 +170,34 @@ def test_auto_link
end

def test_html_escaping
assert_equal "<strong>&lt;i&gt;foobar&lt;/i&gt;</strong>", '[b]<i>foobar</i>[/b]'.bbcode_to_html
assert_equal "<strong><i>foobar</i></strong>", '[b]<i>foobar</i>[/b]'.bbcode_to_html({}, false)
assert_equal "1 is &lt; 2", '1 is < 2'.bbcode_to_html
assert_equal "1 is < 2", '1 is < 2'.bbcode_to_html({}, false)
assert_equal "2 is &gt; 1", '2 is > 1'.bbcode_to_html
assert_equal "2 is > 1", '2 is > 1'.bbcode_to_html({}, false)
assert_equal '<strong>&lt;i&gt;foobar&lt;/i&gt;</strong>', '[b]<i>foobar</i>[/b]'.bbcode_to_html
assert_equal '<strong><i>foobar</i></strong>', '[b]<i>foobar</i>[/b]'.bbcode_to_html({}, false)
assert_equal '1 is &lt; 2', '1 is < 2'.bbcode_to_html
assert_equal '1 is < 2', '1 is < 2'.bbcode_to_html({}, false)
assert_equal '2 is &gt; 1', '2 is > 1'.bbcode_to_html
assert_equal '2 is > 1', '2 is > 1'.bbcode_to_html({}, false)
assert_equal %Q{&quot;double quotes&quot; and &apos;single quotes&apos;}, %Q{"double quotes" and 'single quotes'}.bbcode_to_html
assert_equal %Q{"double quotes" and 'single quotes'}, %Q{"double quotes" and 'single quotes'}.bbcode_to_html({}, false)
end

def test_disable_tags
assert_equal "[b]foobar[/b]", "[b]foobar[/b]".bbcode_to_html({}, true, :disable, :bold)
assert_equal "[b]<em>foobar</em>[/b]", "[b][i]foobar[/i][/b]".bbcode_to_html({}, true, :disable, :bold)
assert_equal "[b][i]foobar[/i][/b]", "[b][i]foobar[/i][/b]".bbcode_to_html({}, true, :disable, :bold, :italics)
assert_equal "<fieldset><blockquote>foobar</blockquote></fieldset>", "[quote]foobar[/quote]".bbcode_to_html({}, true, :disable, :underline)
assert_equal '[b]foobar[/b]', '[b]foobar[/b]'.bbcode_to_html({}, true, :disable, :bold)
assert_equal '[b]<em>foobar</em>[/b]', '[b][i]foobar[/i][/b]'.bbcode_to_html({}, true, :disable, :bold)
assert_equal '[b][i]foobar[/i][/b]', '[b][i]foobar[/i][/b]'.bbcode_to_html({}, true, :disable, :bold, :italics)
assert_equal '<fieldset><blockquote>foobar</blockquote></fieldset>', '[quote]foobar[/quote]'.bbcode_to_html({}, true, :disable, :underline)
end

def test_enable_tags
assert_equal "<strong>foobar</strong>", "[b]foobar[/b]".bbcode_to_html({}, true, :enable, :bold)
assert_equal "<strong>[i]foobar[/i]</strong>", "[b][i]foobar[/i][/b]".bbcode_to_html({}, true, :enable, :bold)
assert_equal "<strong><em>foobar</em></strong>", "[b][i]foobar[/i][/b]".bbcode_to_html({}, true, :enable, :bold, :italics)
assert_equal "[quote]foobar[/quote]", "[quote]foobar[/quote]".bbcode_to_html({}, true, :enable, :underline)
assert_equal '<strong>foobar</strong>', '[b]foobar[/b]'.bbcode_to_html({}, true, :enable, :bold)
assert_equal '<strong>[i]foobar[/i]</strong>', '[b][i]foobar[/i][/b]'.bbcode_to_html({}, true, :enable, :bold)
assert_equal '<strong><em>foobar</em></strong>', '[b][i]foobar[/i][/b]'.bbcode_to_html({}, true, :enable, :bold, :italics)
assert_equal '[quote]foobar[/quote]', '[quote]foobar[/quote]'.bbcode_to_html({}, true, :enable, :underline)
end

def test_to_html_bang_method
foo = "[b]foobar[/b]"
assert_equal "<strong>foobar</strong>", foo.bbcode_to_html!
assert_equal "<strong>foobar</strong>", foo
foo = '[b]foobar[/b]'
assert_equal '<strong>foobar</strong>', foo.bbcode_to_html!
assert_equal '<strong>foobar</strong>', foo
end

def test_to_html_with_no_markup
Expand Down Expand Up @@ -247,20 +247,20 @@ def test_redefinition_of_tag_html
end

def test_multiple_tag_test
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
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)
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
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)
end

def test_no_ending_tag
assert_equal "this [b]should not be bold", "this [b]should not be bold".bbcode_to_html
assert_equal 'this [b]should not be bold', 'this [b]should not be bold'.bbcode_to_html
end

def test_no_start_tag
assert_equal "this should not be bold[/b]", "this should not be bold[/b]".bbcode_to_html
assert_equal 'this should not be bold[/b]', 'this should not be bold[/b]'.bbcode_to_html
end

def test_different_start_and_ending_tags
assert_equal "this [b]should not do formatting[/i]", "this [b]should not do formatting[/i]".bbcode_to_html
assert_equal 'this [b]should not do formatting[/i]', 'this [b]should not do formatting[/i]'.bbcode_to_html
end

## proc tests below
Expand Down Expand Up @@ -289,7 +289,7 @@ def test_proc_modifer # sum as example
end

# for next test
def sum a, b; a + b end
def sum(a, b); a + b end

def test_proc_include_method # sum as example
mydef = {
Expand All @@ -305,7 +305,7 @@ def test_proc_include_method # sum as example

# Proc.new{} as opposed to lambda{} may have not params
def test_proc_instead_of_lambda # copyright
copyright = "2913-3013 The Company, Ltd."
copyright = '2913-3013 The Company, Ltd.'
mydef = {
'copy' => [
/\[copy\/\]/mi,
Expand Down

0 comments on commit 8ed7498

Please sign in to comment.