rubb 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = RuBB
2
2
 
3
- BBCode Parser for Ruby.
3
+ BBCode gem for Ruby.
4
4
 
5
5
  RuBB parses BBCode by generating a parse tree, so it is able to handle nested BBCode tags properly.
6
6
 
@@ -18,23 +18,36 @@ RuBB parses BBCode by generating a parse tree, so it is able to handle nested BB
18
18
 
19
19
  RuBB supports the following BBCode tags:
20
20
 
21
- [b]text[/b]
22
- [i]text[/i]
23
- [u]text[/u]
24
- [s]text[/s]
25
- [size=10]text[/size]
26
- [color=#ff0000]text[/color]
27
- [center]text[/center]
28
- [quote]text[/quote]
29
- [quote=someone]text[/quote]
30
- [url]http://github.com/petejkim/rubb/[/url]
31
- [url=http://github.com/petejkim/rubb/]RuBB[/url]
32
- [img]http://test.com/test.jpg[/img]
33
- [img=640x480]http://test.com/test.jpg[/img]
34
- [ul][li]text[/li][/ul]
35
- [ol][li]text[/li][/ol]
36
- [code]text[/code]
37
- [table][tr][th]text[/th][/tr][tr][td]text[/td][/tr][/table]
21
+ [b]text[/b] => <strong>text</strong>
22
+ [i]text[/i] => <em>text</em>
23
+ [u]text[/u] => <ins>text</ins>
24
+ [s]text[/s] => <del>text</del>
25
+
26
+ [size=10]text[/size] => <span style="font-size: 10px;">text</span>
27
+ [color=#ff0000]text[/color] => <span style="color: #ff0000;">text</span>
28
+
29
+ [left]text[/left] => <span style="text-align: left;">text</span>
30
+ [center]text[/center] => <span style="text-align: center;">text</span>
31
+ [right]text[/right] => <span style="text-align: right;">text</span>
32
+
33
+ [quote]text[/quote] => <blockquote><p>text</p></blockquote>
34
+ [quote=someone]text[/quote] => <blockquote><dl><dt>someone</dt><dd><p>text</p></dd></dl></blockquote>
35
+
36
+ [url]http://github.com/petejkim/rubb/[/url] => <a href="http://github.com/petejkim/rubb/">http://github.com/petejkim/rubb/</a>
37
+ [url=http://github.com/petejkim/rubb/]RuBB[/url] => <a href="http://github.com/petejkim/rubb/">RuBB</a>
38
+
39
+ [email]test@test.com[/email] => <a href="mailto:test@test.com">test@test.com</a>
40
+ [email=test@test.com]Test Email[/email] => <a href="mailto:test@test.com">Test Email</a>
41
+
42
+ [img]http://test.com/test.jpg[/img] => <img src="http://test.com/test.jpg" alt="" />
43
+ [img=640x480]http://test.com/test.jpg[/img] => <img src="http://test.com/test.jpg" style="width: 640px; height: 480px;" alt="" />
44
+
45
+ [ul][li]text[/li][/ul] => <ul><li>text</li></ul>
46
+ [ol][li]text[/li][/ol] => <ol><li>text</li></ol>
47
+
48
+ [code]text[/code] => <pre>text</pre>
49
+
50
+ [table][tr][th]text[/th][/tr][tr][td]text[/td][/tr][/table] => <table><tr><th>text</th></tr><tr><td>text</td></tr></table>
38
51
 
39
52
  == Copyright
40
53
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
 
7
7
  Jeweler::Tasks.new do |s|
8
8
  s.name = "rubb"
9
- s.summary = "BBCode Parser for Ruby that supports nested BBCode tags."
9
+ s.summary = "BBCode gem for Ruby that supports nested BBCode tags."
10
10
  s.description = s.summary
11
11
  s.homepage = "http://github.com/petejkim/rubb"
12
12
  s.authors = ["Peter Jihoon Kim"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.9.2
@@ -1,11 +1,9 @@
1
1
  module RuBB
2
2
  class Node
3
3
  attr_accessor :children
4
- attr_accessor :leftover
5
4
 
6
5
  def initialize(options={})
7
6
  @children = options[:children] || []
8
- @leftover = options[:leftover]
9
7
  end
10
8
 
11
9
  def <<(child)
@@ -0,0 +1,26 @@
1
+ module RuBB
2
+ class Node
3
+ class Email < Node
4
+ attr_accessor :email
5
+
6
+ def initialize(options={})
7
+ super(options)
8
+ @email = options[:email] || ''
9
+ end
10
+
11
+ def to_html
12
+ unless(@email.empty?)
13
+ html = "<a href=\"mailto:#{Parser.escape_quotes(@email)}\">"
14
+ @children.each do |child|
15
+ html += child ? child.to_html : ''
16
+ end
17
+ html + '</a>'
18
+ else
19
+ email = Parser.escape_quotes(@children.map {|c| c ? c.to_html : '' }.join)
20
+ html = "<a href=\"mailto:#{email}\">#{email}</a>"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -9,13 +9,15 @@ module RuBB
9
9
  end
10
10
 
11
11
  def to_html
12
- html = '<p class="rubb_quote_header">Quote:</p><blockquote>'
13
- html += "<p class=\"rubb_quote_who\">Originally Posted by <strong>#{Parser.escape_quotes(@who)}</strong></p>" unless(@who.empty?)
14
- html += '<p class="rubb_quote_content">'
12
+ html = '<blockquote>'
13
+ html += "<dl><dt>#{Parser.escape_quotes(@who)}</dt><dd>" unless(@who.empty?)
14
+ html += '<p>'
15
15
  @children.each do |child|
16
16
  html += child ? child.to_html : ''
17
17
  end
18
- html + '</p></blockquote>'
18
+ html += '</p>'
19
+ html += '</dd></dl>' unless(@who.empty?)
20
+ html + '</blockquote>'
19
21
  end
20
22
  end
21
23
  end
@@ -43,17 +43,24 @@ module RuBB
43
43
  when 'size'
44
44
  Node::Styled.new(:style_hash => {'font-size' => (extra_params[:param] ? extra_params[:param].to_f.to_s + 'px' : nil)})
45
45
  when 'color'
46
- Node::Styled.new(:style_hash => {'color' => (extra_params[:param] || nil)})
46
+ Node::Styled.new(:style_hash => {'color' => (extra_params[:param] ? extra_params[:param].to_s : nil)})
47
+ when 'left'
48
+ Node::Styled.new(:style_hash => {'text-align' => 'left'})
47
49
  when 'center'
48
50
  Node::Styled.new(:style_hash => {'text-align' => 'center'})
51
+ when 'right'
52
+ Node::Styled.new(:style_hash => {'text-align' => 'right'})
49
53
  when 'quote'
50
- Node::Quote.new(:who => (extra_params[:param] || ''))
54
+ Node::Quote.new(:who => (extra_params[:param] ? extra_params[:param].to_s : ''))
51
55
  when 'url'
52
56
  ignore_bbcode_in_children = true if extra_params[:param].nil?
53
- Node::URL.new(:url => (extra_params[:param] || ''))
57
+ Node::URL.new(:url => (extra_params[:param] ? extra_params[:param].to_s : ''))
58
+ when 'email'
59
+ ignore_bbcode_in_children = true if extra_params[:param].nil?
60
+ Node::Email.new(:email => (extra_params[:param] ? extra_params[:param].to_s : ''))
54
61
  when 'img'
55
62
  ignore_bbcode_in_children = true
56
- if(extra_params[:param] && (dimensions = extra_params[:param].split('x')).size >= 2)
63
+ if(extra_params[:param] && (dimensions = extra_params[:param].to_s.split('x')).size >= 2)
57
64
  Node::Image.new(:width => dimensions[0].to_i, :height => dimensions[1].to_i)
58
65
  else
59
66
  Node::Image.new
@@ -101,9 +108,9 @@ module RuBB
101
108
  node << Node::Text.new(:text => match_data[0], :ignore_whitespace => true)
102
109
  else
103
110
  case tag_name
104
- when 'b', 'i', 'u', 's', 'code', 'center', 'ul', 'ol', 'table'
111
+ when 'b', 'i', 'u', 's', 'code', 'left', 'center', 'right', 'ul', 'ol', 'table'
105
112
  node << parse(code, tag_name)
106
- when 'url', 'img', 'size', 'color', 'quote'
113
+ when 'url', 'email', 'img', 'size', 'color', 'quote'
107
114
  if(tag[1] == '=' && tag.size > 2) # param is present
108
115
  param = remove_wrapping_quotes(tag[2..(tag.size)].join(' '))
109
116
  node << parse(code, tag_name, {:param => param})
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubb}
8
- s.version = "0.9.1"
8
+ s.version = "0.9.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Jihoon Kim"]
12
- s.date = %q{2010-07-12}
13
- s.description = %q{BBCode Parser for Ruby that supports nested BBCode tags.}
12
+ s.date = %q{2010-07-13}
13
+ s.description = %q{BBCode gem for Ruby that supports nested BBCode tags.}
14
14
  s.email = %q{raingrove@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "init.rb",
26
26
  "lib/rubb.rb",
27
27
  "lib/rubb/node.rb",
28
+ "lib/rubb/node/email.rb",
28
29
  "lib/rubb/node/image.rb",
29
30
  "lib/rubb/node/quote.rb",
30
31
  "lib/rubb/node/simple.rb",
@@ -40,7 +41,7 @@ Gem::Specification.new do |s|
40
41
  s.rdoc_options = ["--charset=UTF-8"]
41
42
  s.require_paths = ["lib"]
42
43
  s.rubygems_version = %q{1.3.7}
43
- s.summary = %q{BBCode Parser for Ruby that supports nested BBCode tags.}
44
+ s.summary = %q{BBCode gem for Ruby that supports nested BBCode tags.}
44
45
  s.test_files = [
45
46
  "test/test_helper.rb",
46
47
  "test/test_rubb.rb"
@@ -47,21 +47,33 @@ class RuBBTest < Test::Unit::TestCase
47
47
  assert_equal html, bb.bb_to_html
48
48
  end
49
49
 
50
+ def test_left
51
+ bb = '[left]hello[/left]'
52
+ html = '<span style="text-align: left;">hello</span>'
53
+ assert_equal html, bb.bb_to_html
54
+ end
55
+
50
56
  def test_center
51
57
  bb = '[center]hello[/center]'
52
58
  html = '<span style="text-align: center;">hello</span>'
53
59
  assert_equal html, bb.bb_to_html
54
60
  end
55
61
 
62
+ def test_right
63
+ bb = '[right]hello[/right]'
64
+ html = '<span style="text-align: right;">hello</span>'
65
+ assert_equal html, bb.bb_to_html
66
+ end
67
+
56
68
  def test_quote
57
69
  bb = '[quote]hello world![/quote]'
58
- html = '<p class="rubb_quote_header">Quote:</p><blockquote><p class="rubb_quote_content">hello world!</p></blockquote>'
70
+ html = '<blockquote><p>hello world!</p></blockquote>'
59
71
  assert_equal html, bb.bb_to_html
60
72
  end
61
73
 
62
74
  def test_named_quote
63
75
  bb = '[quote=raingrove]hello world![/quote]'
64
- html = '<p class="rubb_quote_header">Quote:</p><blockquote><p class="rubb_quote_who">Originally Posted by <strong>raingrove</strong></p><p class="rubb_quote_content">hello world!</p></blockquote>'
76
+ html = '<blockquote><dl><dt>raingrove</dt><dd><p>hello world!</p></dd></dl></blockquote>'
65
77
  assert_equal html, bb.bb_to_html
66
78
  end
67
79
 
@@ -107,6 +119,18 @@ class RuBBTest < Test::Unit::TestCase
107
119
  assert_equal html, bb.bb_to_html
108
120
  end
109
121
 
122
+ def test_email_simple
123
+ bb = '[email]test@test.com[/email]'
124
+ html = '<a href="mailto:test@test.com">test@test.com</a>'
125
+ assert_equal html, bb.bb_to_html
126
+ end
127
+
128
+ def test_email_named
129
+ bb = '[email=test@test.com]Test[/email]'
130
+ html = '<a href="mailto:test@test.com">Test</a>'
131
+ assert_equal html, bb.bb_to_html
132
+ end
133
+
110
134
  def test_escape_quotes
111
135
  bb = "[url=hello\">hello<p class='test'>hi</p><a href=\"]hello[/url]"
112
136
  html = "<a href=\"hello\\\"&gt;hello&lt;p class=\\\'test\\\'&gt;hi&lt;/p&gt;&lt;a href=\\\"\">hello</a>"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 1
9
- version: 0.9.1
8
+ - 2
9
+ version: 0.9.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Peter Jihoon Kim
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-12 00:00:00 +09:00
17
+ date: 2010-07-13 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: BBCode Parser for Ruby that supports nested BBCode tags.
21
+ description: BBCode gem for Ruby that supports nested BBCode tags.
22
22
  email: raingrove@gmail.com
23
23
  executables: []
24
24
 
@@ -36,6 +36,7 @@ files:
36
36
  - init.rb
37
37
  - lib/rubb.rb
38
38
  - lib/rubb/node.rb
39
+ - lib/rubb/node/email.rb
39
40
  - lib/rubb/node/image.rb
40
41
  - lib/rubb/node/quote.rb
41
42
  - lib/rubb/node/simple.rb
@@ -77,7 +78,7 @@ rubyforge_project:
77
78
  rubygems_version: 1.3.7
78
79
  signing_key:
79
80
  specification_version: 3
80
- summary: BBCode Parser for Ruby that supports nested BBCode tags.
81
+ summary: BBCode gem for Ruby that supports nested BBCode tags.
81
82
  test_files:
82
83
  - test/test_helper.rb
83
84
  - test/test_rubb.rb