ruby-bbcode 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +3 -1
- data/lib/ruby-bbcode/version.rb +1 -1
- data/lib/ruby-bbcode.rb +5 -4
- data/test/dummy/config/environment.rb +10 -0
- data/test/ruby_bbcode_test.rb +13 -0
- metadata +21 -40
data/README.textile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
h1. Ruby-BBcode
|
2
2
|
|
3
|
-
This
|
3
|
+
This gem adds support for "BBCode":http:/www.bbcode.org/ to Ruby. The BBCode is parsed by a parser before converted to HTML, allowing to convert nested BBCode tags in strings to their correct HTML equivalent. The parser also checks whether the BBCode is valid and gives errors for incorrect BBCode texts.
|
4
4
|
|
5
5
|
The parser recognizes all "official tags":http://www.bbcode.org/reference.php and allows to easily extend this set with custom tags.
|
6
6
|
|
@@ -12,6 +12,8 @@ h2. Example
|
|
12
12
|
h2. Installing
|
13
13
|
|
14
14
|
Add the folling line to the Gemfile in your Rails application:
|
15
|
+
<pre><code>gem 'ruby-bbcode'</code></pre>
|
16
|
+
Or grab it directly from the repository:
|
15
17
|
<pre><code>gem 'ruby-bbcode', :git => 'git://github.com/veger/ruby-bbcode.git'</code></pre>
|
16
18
|
Run
|
17
19
|
<pre><code>bundle install</code></pre>
|
data/lib/ruby-bbcode/version.rb
CHANGED
data/lib/ruby-bbcode.rb
CHANGED
@@ -24,8 +24,6 @@ module RubyBBCode
|
|
24
24
|
text.gsub!('<', '<')
|
25
25
|
text.gsub!('>', '>')
|
26
26
|
end
|
27
|
-
text.gsub!("\r\n", "\n")
|
28
|
-
text.gsub!("\n", "<br />\n")
|
29
27
|
|
30
28
|
valid = parse(text, use_tags)
|
31
29
|
raise valid.join(', ') if valid != true
|
@@ -77,7 +75,7 @@ module RubyBBCode
|
|
77
75
|
# Check if the found tag is allowed
|
78
76
|
last_tag = tags[tags_list.last.to_sym]
|
79
77
|
allowed_tags = last_tag[:only_allow]
|
80
|
-
if (!ti[:is_tag] and last_tag[:require_between] != true) or (ti[:is_tag] and (allowed_tags.include?(ti[:tag].to_sym) == false))
|
78
|
+
if (!ti[:is_tag] and last_tag[:require_between] != true and ti[:text].lstrip != "") or (ti[:is_tag] and (allowed_tags.include?(ti[:tag].to_sym) == false))
|
81
79
|
# Last opened tag does not allow tag
|
82
80
|
err = "[#{tags_list.last}] can only contain [#{allowed_tags.to_sentence(@@to_sentence_bbcode_tags)}] tags, so "
|
83
81
|
err += "[#{ti[:tag]}]" if ti[:is_tag]
|
@@ -94,7 +92,10 @@ module RubyBBCode
|
|
94
92
|
element = {:is_tag => true, :tag => ti[:tag].to_sym, :nodes => [] }
|
95
93
|
element[:params] = {:tag_param => ti[:params][:tag_param]} if tag[:allow_tag_param] and ti[:params][:tag_param] != nil
|
96
94
|
else
|
97
|
-
|
95
|
+
text = ti[:text]
|
96
|
+
text.gsub!("\r\n", "\n")
|
97
|
+
text.gsub!("\n", "<br />\n")
|
98
|
+
element = {:is_tag => false, :text => text }
|
98
99
|
if bbtree_depth > 0
|
99
100
|
tag = tags[bbtree_current_node[:tag]]
|
100
101
|
if tag[:require_between] == true
|
@@ -1,5 +1,15 @@
|
|
1
1
|
# Load the rails application
|
2
2
|
require File.expand_path('../application', __FILE__)
|
3
3
|
|
4
|
+
|
5
|
+
Dummy::Application.configure do
|
6
|
+
# Log error messages when you accidentally call methods on nil
|
7
|
+
config.whiny_nils = true
|
8
|
+
|
9
|
+
# Print deprecation notices to the stderr
|
10
|
+
config.active_support.deprecation = :stderr
|
11
|
+
end
|
12
|
+
|
13
|
+
|
4
14
|
# Initialize the rails application
|
5
15
|
Dummy::Application.initialize!
|
data/test/ruby_bbcode_test.rb
CHANGED
@@ -2,6 +2,11 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class RubyBbcodeTest < Test::Unit::TestCase
|
4
4
|
|
5
|
+
def test_multiline
|
6
|
+
assert_equal "line1<br />\nline2", "line1\nline2".bbcode_to_html
|
7
|
+
assert_equal "line1<br />\nline2", "line1\r\nline2".bbcode_to_html
|
8
|
+
end
|
9
|
+
|
5
10
|
def test_strong
|
6
11
|
assert_equal '<strong>simple</strong>', '[b]simple[/b]'.bbcode_to_html
|
7
12
|
assert_equal "<strong>line 1<br />\nline 2</strong>", "[b]line 1\nline 2[/b]".bbcode_to_html
|
@@ -48,6 +53,14 @@ class RubyBbcodeTest < Test::Unit::TestCase
|
|
48
53
|
'[ul][li]item1[/li][li]item2[/li][/ul][ul][li]item1[/li][li]item2[/li][/ul]'.bbcode_to_html
|
49
54
|
end
|
50
55
|
|
56
|
+
def test_whitespace_in_only_allowed_tags
|
57
|
+
assert_equal "<ol><br />\n<li>item 1</li><br />\n<li>item 2</li><br />\n</ol>",
|
58
|
+
"[ol]\n[li]item 1[/li]\n[li]item 2[/li]\n[/ol]".bbcode_to_html
|
59
|
+
assert_equal "<ol> <li>item 1</li> <li>item 2</li> </ol>",
|
60
|
+
"[ol] [li]item 1[/li] [li]item 2[/li] [/ol]".bbcode_to_html
|
61
|
+
|
62
|
+
end
|
63
|
+
|
51
64
|
def test_illegal_items
|
52
65
|
assert_raise RuntimeError do
|
53
66
|
'[li]Illegal item[/li]'.bbcode_to_html
|
metadata
CHANGED
@@ -1,33 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-bbcode
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Maarten Bezemer
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-01-19 00:00:00 Z
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Convert BBCode to HTML and check whether the BBCode is valid.
|
22
|
-
email:
|
15
|
+
email:
|
23
16
|
- maarten.bezemer@gmail.com
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- lib/tags/tags.rb
|
32
22
|
- lib/ruby-bbcode/version.rb
|
33
23
|
- lib/ruby-bbcode.rb
|
@@ -42,38 +32,29 @@ files:
|
|
42
32
|
- test/test_helper.rb
|
43
33
|
homepage: http://github.com/veger/ruby-bbcode
|
44
34
|
licenses: []
|
45
|
-
|
46
35
|
post_install_message:
|
47
36
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
37
|
+
require_paths:
|
50
38
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
40
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
- 0
|
59
|
-
version: "0"
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
46
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
version: "0"
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
69
51
|
requirements: []
|
70
|
-
|
71
52
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.
|
53
|
+
rubygems_version: 1.8.11
|
73
54
|
signing_key:
|
74
55
|
specification_version: 3
|
75
|
-
summary: ruby-bbcode-0.0.
|
76
|
-
test_files:
|
56
|
+
summary: ruby-bbcode-0.0.3
|
57
|
+
test_files:
|
77
58
|
- test/ruby_bbcode_test.rb
|
78
59
|
- test/dummy/config/environments/test.rb
|
79
60
|
- test/dummy/config/application.rb
|