ruby-bbcode 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +66 -0
- data/lib/ruby-bbcode/bbtree.rb +1 -3
- data/lib/ruby-bbcode/version.rb +1 -1
- data/test/ruby_bbcode_html_test.rb +1 -0
- metadata +5 -5
- data/README.textile +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37d4c690e1a1f4568999f6dd0828a1412bdb4258
|
4
|
+
data.tar.gz: aa02eeaae1f5ae2da7729f392f2d1d7245f6d374
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b684a64a382dab2ee8371ee013e2dc03955371724dc325df15530f0bd8ce3c06a62b74b531610eae22015903d572303976a4ee885316c9c91cf01219fb1e32d4
|
7
|
+
data.tar.gz: 1d9f6990314aaa90a072575039e45990449149ca9b8babe85c2fce09d869f70e625e9f767731ff7db86accc0640d4830f3be5ca376aad82748556ba2e0760798
|
data/CHANGELOG.md
CHANGED
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Ruby-BBCode
|
2
|
+
|
3
|
+
[![gem version](https://badge.fury.io/rb/ruby-bbcode.svg)](https://badge.fury.io/rb/ruby-bbcode) [![Build Status](https://travis-ci.org/veger/ruby-bbcode.svg?branch=master)](https://travis-ci.org/veger/ruby-bbcode) [![Code Coverage](https://coveralls.io/repos/github/veger/ruby-bbcode/badge.svg?branch=master)](https://coveralls.io/github/veger/ruby-bbcode?branch=master)
|
4
|
+
|
5
|
+
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.
|
6
|
+
Additionally, annotations can be added to the BBCode string the showing errors that are present, assuming there are any errors.
|
7
|
+
|
8
|
+
The parser recognizes all [official tags](http://www.bbcode.org/reference.php) and allows to easily extend this set with custom tags.
|
9
|
+
|
10
|
+
## Examples
|
11
|
+
|
12
|
+
`bbcode_to_html` can be used to convert a BBCode string to HTML:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
'This is [b]bold[/b] and this is [i]italic[/i].'.bbcode_to_html
|
16
|
+
=> 'This is <strong>bold</strong> and this is <em>italic</em>.'
|
17
|
+
```
|
18
|
+
|
19
|
+
`bbcode_show_errors` can be used to convert a BBCode to BBCode annotated with errors (assuming the original BBCode did contain errors):
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
'[img=no_dimensions_here]image.png[/img]'.bbcode_show_errors
|
23
|
+
=> '<span class=\'bbcode_error\' data-bbcode-errors=\'["The image parameters \'no_dimensions_here\' are incorrect, \'<width>x<height>\' excepted"]\'>[img]</span>image.png[/img]'
|
24
|
+
```
|
25
|
+
|
26
|
+
These HTML attributes containing the JSON representation of the errors can be used to inform the user about the problems.
|
27
|
+
The following JavaScript/jQuery example makes use of the [Bootstrap tooltips plugin](http://getbootstrap.com/javascript/#tooltips) to show the errors in tooltip popups:
|
28
|
+
```javascript
|
29
|
+
$(".bbcode_error").tooltip({
|
30
|
+
title: function() {
|
31
|
+
var errors = JSON.parse($(this).attr('data-bbcode-errors'));
|
32
|
+
return errors.join("\n");
|
33
|
+
}
|
34
|
+
});
|
35
|
+
```
|
36
|
+
|
37
|
+
## Installing
|
38
|
+
|
39
|
+
Add the following line to the Gemfile of your application:
|
40
|
+
```ruby
|
41
|
+
gem 'ruby-bbcode'
|
42
|
+
```
|
43
|
+
|
44
|
+
Or to use the source code from the repository:
|
45
|
+
```ruby
|
46
|
+
gem 'ruby-bbcode', :git => 'git://github.com/veger/ruby-bbcode.git'
|
47
|
+
```
|
48
|
+
|
49
|
+
Run
|
50
|
+
```shell
|
51
|
+
bundle install
|
52
|
+
```
|
53
|
+
|
54
|
+
And Ruby-BBCode is available in your application.
|
55
|
+
|
56
|
+
_Note_: Do not forget to restart your server!
|
57
|
+
|
58
|
+
## Acknowledgements
|
59
|
+
|
60
|
+
A big thanks to [@TheNotary](https://github.com/TheNotary) for all contributions he made to this project!
|
61
|
+
|
62
|
+
Some of the ideas and the tests came from [bb-ruby](https://github.com/cpjolicoeur/bb-ruby) of Craig P Jolicoeur.
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
MIT License. See the included [MIT-LICENCE](MIT-LICENSE) file.
|
data/lib/ruby-bbcode/bbtree.rb
CHANGED
@@ -46,7 +46,6 @@ module RubyBBCode
|
|
46
46
|
|
47
47
|
# Step down the bbtree a notch because we've reached a closing tag
|
48
48
|
def retrogress_bbtree
|
49
|
-
# print @tags_list[-1].inspect
|
50
49
|
if @tags_list[-1].definition[:self_closable]
|
51
50
|
# It is possible that the next (self_closable) tag is on the next line
|
52
51
|
# Remove newline of current tag and parent tag as they are (probably) not intented as an actual newline here but as tag separator
|
@@ -58,8 +57,7 @@ module RubyBBCode
|
|
58
57
|
# The parsed data manifests in @bbtree.current_node.children << TagNode.new(element) which I think is more confusing than needed
|
59
58
|
|
60
59
|
if within_open_tag?
|
61
|
-
|
62
|
-
@current_node = TagNode.new(self.nodes.last)
|
60
|
+
@current_node = @tags_list[-1]
|
63
61
|
else # If we're still at the root of the BBTree or have returned back to the root via encountring closing tags...
|
64
62
|
@current_node = TagNode.new({:nodes => self.nodes}) # Note: just passing in self works too...
|
65
63
|
end
|
data/lib/ruby-bbcode/version.rb
CHANGED
@@ -55,6 +55,7 @@ class RubyBbcodeHtmlTest < Minitest::Test
|
|
55
55
|
|
56
56
|
def test_list_common_syntax
|
57
57
|
assert_equal '<ul><li>item 1</li><li>item 2</li></ul>', '[list][*]item 1[*]item 2[/list]'.bbcode_to_html
|
58
|
+
assert_equal '<ul><li><strong>item 1</strong> test</li><li>item 2</li></ul>', "[list]\n[*][b]item 1[/b] test[*]item 2[/list]".bbcode_to_html
|
58
59
|
end
|
59
60
|
|
60
61
|
def test_newline_list_common_syntax
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-bbcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maarten Bezemer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -99,13 +99,13 @@ email: maarten.bezemer@gmail.com
|
|
99
99
|
executables: []
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files:
|
102
|
-
- README.
|
102
|
+
- README.md
|
103
103
|
- CHANGELOG.md
|
104
104
|
- MIT-LICENSE
|
105
105
|
files:
|
106
106
|
- CHANGELOG.md
|
107
107
|
- MIT-LICENSE
|
108
|
-
- README.
|
108
|
+
- README.md
|
109
109
|
- Rakefile
|
110
110
|
- lib/ruby-bbcode.rb
|
111
111
|
- lib/ruby-bbcode/bbtree.rb
|
@@ -150,7 +150,7 @@ rubyforge_project:
|
|
150
150
|
rubygems_version: 2.6.8
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
|
-
summary: ruby-bbcode-2.0.
|
153
|
+
summary: ruby-bbcode-2.0.2
|
154
154
|
test_files:
|
155
155
|
- test/unit/tag_sifter_test.rb
|
156
156
|
- test/unit/tags_test.rb
|
data/README.textile
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
h1. Ruby-BBCode
|
2
|
-
|
3
|
-
!https://badge.fury.io/rb/ruby-bbcode.svg!:http://badge.fury.io/rb/ruby-bbcode !https://travis-ci.org/veger/ruby-bbcode.svg?branch=master!:https://travis-ci.org/veger/ruby-bbcode !https://coveralls.io/repos/veger/ruby-bbcode/badge.svg?branch=master(Coverage Status)!:https://coveralls.io/r/veger/ruby-bbcode?branch=master
|
4
|
-
|
5
|
-
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.
|
6
|
-
Additionally, annotations can be added to the BBCode string the showing errors that are present, assuming there are any errors.
|
7
|
-
|
8
|
-
The parser recognizes all "official tags":http://www.bbcode.org/reference.php and allows to easily extend this set with custom tags.
|
9
|
-
|
10
|
-
See "changelog":CHANGELOG.md for the (recent) notable changes of this gem.
|
11
|
-
|
12
|
-
h2. Examples
|
13
|
-
|
14
|
-
<code>bbcode_to_html</code> can be used to convert a BBCode string to HTML:
|
15
|
-
|
16
|
-
<pre><code>'This is [b]bold[/b] and this is [i]italic[/i].'.bbcode_to_html
|
17
|
-
=> 'This is <strong>bold</strong> and this is <em>italic</em>.'</code></pre>
|
18
|
-
|
19
|
-
<code>bbcode_show_errors</code> can be used to convert a BBCode to BBCode annotated with errors (assuming the original BBCode did contain errors):
|
20
|
-
|
21
|
-
<pre><code>'[img=no_dimensions_here]image.png[/img]'.bbcode_show_errors
|
22
|
-
=> '<span class=\'bbcode_error\' data-bbcode-errors=\'["The image parameters \'no_dimensions_here\' are incorrect, \'<width>x<height>\' excepted"]\'>[img]</span>image.png[/img]'</code></pre>
|
23
|
-
|
24
|
-
These HTML attributes containing the JSON representation of the errors can be used to inform the user about the problems.
|
25
|
-
The following JavaScript/jQuery example makes use of the "Bootstrap tooltips plugin":http://getbootstrap.com/javascript/#tooltips to show the errors in tooltip popups:
|
26
|
-
<pre><code>$(".bbcode_error").tooltip({
|
27
|
-
title: function() {
|
28
|
-
var errors = JSON.parse($(this).attr('data-bbcode-errors'));
|
29
|
-
return errors.join("\n");
|
30
|
-
}
|
31
|
-
});</code></pre>
|
32
|
-
|
33
|
-
h2. Installing
|
34
|
-
|
35
|
-
Add the following line to the Gemfile of your application:
|
36
|
-
<pre><code>gem 'ruby-bbcode'</code></pre>
|
37
|
-
|
38
|
-
Or to use the source code from the repository:
|
39
|
-
<pre><code>gem 'ruby-bbcode', :git => 'git://github.com/veger/ruby-bbcode.git'</code></pre>
|
40
|
-
|
41
|
-
Run
|
42
|
-
<pre><code>bundle install</code></pre>
|
43
|
-
|
44
|
-
And Ruby-BBCode is available in your application.
|
45
|
-
|
46
|
-
_Note_: Do not forget to restart your server!
|
47
|
-
|
48
|
-
h2. Acknowledgements
|
49
|
-
|
50
|
-
A big thanks to "TheNotary":https://github.com/TheNotary for all contributions he made to this project!
|
51
|
-
|
52
|
-
Some of the ideas and the tests came from "bb-ruby":http://github.com/cpjolicoeur/bb-ruby of Craig P Jolicoeur.
|
53
|
-
|
54
|
-
h2. License
|
55
|
-
|
56
|
-
MIT License. See the included "MIT-LICENCE":MIT-LICENSE file.
|