ruby-bbcode 2.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,33 +1,37 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class RubyBbcodeValidityTest < Minitest::Test
4
+ def before_setup
5
+ RubyBBCode.reset
6
+ end
7
+
4
8
  def test_multiple_errors
5
9
  input = '[b]Bold not closed, [li]Illegal list item[/li]'
6
10
  errors = input.bbcode_check_validity
7
11
  assert_equal 2, errors.length
8
- assert_includes errors, "[b] not closed"
9
- assert_includes errors, "[li] can only be used in [ul] and [ol], so using it in a [b] tag is not allowed"
12
+ assert_includes errors, '[b] not closed'
13
+ assert_includes errors, '[li] can only be used in [ul] and [ol], so using it in a [b] tag is not allowed'
10
14
  end
11
15
 
12
16
  def test_illegal_items
13
17
  assert_equal ['[li] can only be used in [ul] and [ol]'],
14
- '[li]Illegal item[/li]'.bbcode_check_validity
18
+ '[li]Illegal item[/li]'.bbcode_check_validity
15
19
  assert_equal ['[li] can only be used in [ul] and [ol], so using it in a [b] tag is not allowed'],
16
- '[b][li]Illegal item[/li][/b]'.bbcode_check_validity
20
+ '[b][li]Illegal item[/li][/b]'.bbcode_check_validity
17
21
  end
18
22
 
19
23
  def test_illegal_list_contents
20
24
  assert_equal ['[ul] can only contain [li] and [*] tags, so "Illegal list" is not allowed'],
21
- '[ul]Illegal list[/ul]'.bbcode_check_validity
25
+ '[ul]Illegal list[/ul]'.bbcode_check_validity
22
26
  assert_equal ['[ul] can only contain [li] and [*] tags, so [b] is not allowed'],
23
- '[ul][b]Illegal list[/b][/ul]'.bbcode_check_validity
27
+ '[ul][b]Illegal list[/b][/ul]'.bbcode_check_validity
24
28
  end
25
29
 
26
30
  def test_illegal_list_contents_text_between_list_items
27
31
  assert_equal ['[ul] can only contain [li] and [*] tags, so "Illegal text" is not allowed'],
28
- '[ul][li]item[/li]Illegal text[/ul]'.bbcode_check_validity
32
+ '[ul][li]item[/li]Illegal text[/ul]'.bbcode_check_validity
29
33
  assert_equal ['[ul] can only contain [li] and [*] tags, so "Illegal text" is not allowed'],
30
- '[ul][li]item[/li]Illegal text[li]item[/li][/ul]'.bbcode_check_validity
34
+ '[ul][li]item[/li]Illegal text[li]item[/li][/ul]'.bbcode_check_validity
31
35
  end
32
36
 
33
37
  def test_unordered_list_omit_closing
@@ -71,15 +75,15 @@ class RubyBbcodeValidityTest < Minitest::Test
71
75
  end
72
76
 
73
77
  def test_no_ending_tag
74
- assert_equal ["[b] not closed"], "this [b]should not be bold".bbcode_check_validity
78
+ assert_equal ['[b] not closed'], 'this [b]should not be bold'.bbcode_check_validity
75
79
  end
76
80
 
77
81
  def test_no_start_tag
78
- assert_equal ["Closing tag [/b] doesn't match an opening tag"], "this should not be bold[/b]".bbcode_check_validity
82
+ assert_equal ["Closing tag [/b] doesn't match an opening tag"], 'this should not be bold[/b]'.bbcode_check_validity
79
83
  end
80
84
 
81
85
  def test_different_start_and_ending_tags
82
- assert_equal ["Closing tag [/i] doesn't match [b]", "[b] not closed"], "this [b]should not do formatting[/i]".bbcode_check_validity
86
+ assert_equal ["Closing tag [/i] doesn't match [b]", '[b] not closed'], 'this [b]should not do formatting[/i]'.bbcode_check_validity
83
87
  end
84
88
 
85
89
  def test_failing_between_texts
@@ -94,10 +98,10 @@ class RubyBbcodeValidityTest < Minitest::Test
94
98
 
95
99
  def test_addition_of_tags
96
100
  mydef = {
97
- :test => {
98
- :description => 'This is a test',
99
- :example => '[test]Test here[/test]',
100
- :param_tokens => [{:token => :param}]
101
+ test: {
102
+ description: 'This is a test',
103
+ example: '[test]Test here[/test]',
104
+ param_tokens: [{ token: :param }]
101
105
  }
102
106
  }
103
107
  # Currently, unknown tags are treated as text and no (missing) parameter values are checked for bbcode_check_validity
@@ -106,14 +110,13 @@ class RubyBbcodeValidityTest < Minitest::Test
106
110
  assert 'pre [test]Test here[/test] post'.bbcode_check_validity(mydef)
107
111
  end
108
112
 
109
- # TODO: This stack level problem should be validated during the validations
110
- #def test_stack_level_too_deep
113
+ # TODO: This stack level problem should be validated during the validations
114
+ # def test_stack_level_too_deep
111
115
  # num = 2300 # increase this number if the test starts failing. It's very near the tipping point
112
116
  # openers = "[s]hi i'm" * num
113
117
  # closers = "[/s]" * num
114
118
  # assert_raise( SystemStackError ) do
115
119
  # (openers+closers).bbcode_to_html
116
120
  # end
117
- #end
118
-
121
+ # end
119
122
  end
@@ -2,19 +2,18 @@ require 'coveralls'
2
2
  Coveralls.wear!
3
3
 
4
4
  require 'ruby-bbcode'
5
- require "minitest/autorun"
5
+ require 'minitest/autorun'
6
6
 
7
7
  # This hack allows us to make all the private methods of a class public.
8
8
  class Class
9
9
  def publicize_methods
10
- saved_private_instance_methods = self.private_instance_methods
11
- self.class_eval { public(*saved_private_instance_methods) }
10
+ saved_private_instance_methods = private_instance_methods
11
+ class_eval { public(*saved_private_instance_methods) }
12
12
  yield
13
- self.class_eval { private(*saved_private_instance_methods) }
13
+ class_eval { private(*saved_private_instance_methods) }
14
14
  end
15
15
  end
16
16
 
17
-
18
17
  # This is for measuring memory usage...
19
18
  def get_current_memory_usage
20
19
  `ps -o rss= -p #{Process.pid}`.to_i
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < MiniTest::Test
4
+ def before_setup
5
+ RubyBBCode.reset
6
+ end
7
+
8
+ def test_configuration
9
+ refute_equal :ignore, RubyBBCode.configuration.ignore_unknown_tags
10
+
11
+ RubyBBCode.configuration.ignore_unknown_tags = :ignore
12
+
13
+ assert_equal :ignore, RubyBBCode.configuration.ignore_unknown_tags
14
+ end
15
+
16
+ def test_configuration_reset
17
+ refute_equal :exception, RubyBBCode.configuration.ignore_unknown_tags
18
+
19
+ RubyBBCode.configuration.ignore_unknown_tags = :exception
20
+
21
+ assert_equal :exception, RubyBBCode.configuration.ignore_unknown_tags
22
+
23
+ RubyBBCode.reset
24
+
25
+ refute_equal :exception, RubyBBCode.configuration.ignore_unknown_tags
26
+ end
27
+
28
+ def test_configuration_block
29
+ refute_equal :ignore, RubyBBCode.configuration.ignore_unknown_tags
30
+
31
+ RubyBBCode.configure do |config|
32
+ config.ignore_unknown_tags = :ignore
33
+ end
34
+
35
+ assert_equal :ignore, RubyBBCode.configuration.ignore_unknown_tags
36
+ end
37
+ end
@@ -3,36 +3,34 @@ require 'test_helper'
3
3
  class TagSifterTest < MiniTest::Test
4
4
  include RubyBBCode::Tags
5
5
  def test_youtube_parser
6
- url1 = "http://www.youtube.com/watch?v=E4Fbk52Mk1w"
6
+ url1 = 'http://www.youtube.com/watch?v=E4Fbk52Mk1w'
7
7
  just_an_id = 'E4Fbk52Mk1w'
8
- url_without_http = "www.youtube.com/watch?v=E4Fbk52Mk1w"
9
- url_without_www = "youtube.com/watch?v=E4Fbk52Mk1w"
10
- url_with_feature = "http://www.youtube.com/watch?feature=player_embedded&v=E4Fbk52Mk1w"
8
+ url_without_http = 'www.youtube.com/watch?v=E4Fbk52Mk1w'
9
+ url_without_www = 'youtube.com/watch?v=E4Fbk52Mk1w'
10
+ url_with_feature = 'http://www.youtube.com/watch?feature=player_embedded&v=E4Fbk52Mk1w'
11
11
  mock_regex_matches = @@tags[:youtube][:url_matches]
12
12
 
13
13
  expected_output = 'E4Fbk52Mk1w'
14
14
 
15
15
  RubyBBCode::TagSifter.publicize_methods do
16
- ts = RubyBBCode::TagSifter.new "", ""
16
+ ts = RubyBBCode::TagSifter.new '', ''
17
17
  assert_equal expected_output, ts.match_url_id(url1, mock_regex_matches)
18
18
  assert_equal expected_output, ts.match_url_id(just_an_id, mock_regex_matches)
19
19
  assert_equal expected_output, ts.match_url_id(url_without_http, mock_regex_matches)
20
20
  assert_equal expected_output, ts.match_url_id(url_without_www, mock_regex_matches)
21
21
  assert_equal expected_output, ts.match_url_id(url_with_feature, mock_regex_matches)
22
22
  end
23
-
24
23
  end
25
24
 
26
25
  # I think the answer to this is creating a new tag named [youtube]
27
26
  # but that captures specifically the .be or .com and treats them differently...
28
27
  def test_youtubes_via_there_url_shortener
29
- url_from_shortener = "http://youtu.be/E4Fbk52Mk1w"
30
- directory_format = "http://youtube.googleapis.com/v/E4Fbk52Mk1w"
28
+ url_from_shortener = 'http://youtu.be/E4Fbk52Mk1w'
31
29
  expected_output = 'E4Fbk52Mk1w'
32
30
  mock_regex_matches = @@tags[:youtube][:url_matches]
33
31
 
34
32
  RubyBBCode::TagSifter.publicize_methods do
35
- ts = RubyBBCode::TagSifter.new "", ""
33
+ ts = RubyBBCode::TagSifter.new '', ''
36
34
 
37
35
  # this test is now hopelessly broken because generating an ID from a link requires that @bbtree.current_node.definition be properly populated with regex matches...
38
36
  assert_equal expected_output, ts.match_url_id(url_from_shortener, mock_regex_matches)
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class TagSifterTest < MiniTest::Test
4
4
  def test_taglist_modification
5
5
  tags = RubyBBCode::Tags.tag_list
6
- assert_equal nil, RubyBBCode::Tags.tag_list[:test]
6
+ assert_nil RubyBBCode::Tags.tag_list[:test]
7
7
  begin
8
8
  tags[:test] = 'test'
9
9
 
@@ -12,6 +12,6 @@ class TagSifterTest < MiniTest::Test
12
12
  # Always restore as this change is permanent (and messes with other tests)
13
13
  tags.delete :test
14
14
  end
15
- assert_equal nil, RubyBBCode::Tags.tag_list[:test]
15
+ assert_nil RubyBBCode::Tags.tag_list[:test]
16
16
  end
17
17
  end
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.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Bezemer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-09 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,16 +16,30 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.3
19
+ version: 4.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.3
26
+ version: 4.2.2
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: irb
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -53,34 +67,77 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: coveralls
70
+ name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - '='
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: 0.8.0
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: 0.8.0
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: solargraph
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: term-ansicolor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  description: Convert BBCode to HTML and check whether the BBCode is valid.
70
126
  email: maarten.bezemer@gmail.com
71
127
  executables: []
72
128
  extensions: []
73
129
  extra_rdoc_files:
74
- - README.textile
130
+ - README.md
75
131
  - CHANGELOG.md
76
132
  - MIT-LICENSE
77
133
  files:
78
134
  - CHANGELOG.md
79
135
  - MIT-LICENSE
80
- - README.textile
136
+ - README.md
81
137
  - Rakefile
82
138
  - lib/ruby-bbcode.rb
83
139
  - lib/ruby-bbcode/bbtree.rb
140
+ - lib/ruby-bbcode/configuration.rb
84
141
  - lib/ruby-bbcode/tag_collection.rb
85
142
  - lib/ruby-bbcode/tag_info.rb
86
143
  - lib/ruby-bbcode/tag_node.rb
@@ -93,6 +150,7 @@ files:
93
150
  - test/ruby_bbcode_html_test.rb
94
151
  - test/ruby_bbcode_validity_test.rb
95
152
  - test/test_helper.rb
153
+ - test/unit/configuration_test.rb
96
154
  - test/unit/tag_sifter_test.rb
97
155
  - test/unit/tags_test.rb
98
156
  homepage: http://github.com/veger/ruby-bbcode
@@ -111,22 +169,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
169
  requirements:
112
170
  - - ">="
113
171
  - !ruby/object:Gem::Version
114
- version: 1.9.3
172
+ version: 2.3.0
115
173
  required_rubygems_version: !ruby/object:Gem::Requirement
116
174
  requirements:
117
175
  - - ">="
118
176
  - !ruby/object:Gem::Version
119
177
  version: '0'
120
178
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.4.5
179
+ rubygems_version: 3.1.2
123
180
  signing_key:
124
181
  specification_version: 4
125
- summary: ruby-bbcode-2.0.0
182
+ summary: ruby-bbcode-2.1.1
126
183
  test_files:
184
+ - test/unit/tags_test.rb
185
+ - test/unit/tag_sifter_test.rb
186
+ - test/unit/configuration_test.rb
127
187
  - test/test_helper.rb
128
188
  - test/ruby_bbcode_validity_test.rb
129
189
  - test/ruby_bbcode_bbcode_test.rb
130
190
  - test/ruby_bbcode_html_test.rb
131
- - test/unit/tag_sifter_test.rb
132
- - test/unit/tags_test.rb
@@ -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.