bbcoder 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +1 -2
- data/lib/bbcoder/base.rb +10 -8
- data/lib/bbcoder/buffer_tags.rb +7 -3
- data/lib/bbcoder/configuration.rb +9 -13
- data/lib/bbcoder/tag.rb +11 -5
- data/lib/bbcoder/version.rb +1 -1
- data/spec/base_spec.rb +6 -6
- data/spec/bbcoder_spec.rb +1 -2
- data/spec/tag_spec.rb +16 -1
- metadata +15 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ecc0ce999076a868e4dec52ade4e9029e8157691
|
4
|
+
data.tar.gz: 979b7907d53a0e7d99e53c6c6a474d86e4846b99
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbb36720136b6e1efda20ed2db5cde4ad4a876a6e3e47e57ad73eb5677cf047dcc7f93ccb37a114dd33eab08dbd683b01f509de7a178ff76613cb49cee6b4026
|
7
|
+
data.tar.gz: 1631b9da9ca17bcb71bd4a0f13a7ed9b71b5880b4a627f6652635f1c0e850e2b3443a7aaffa7d004b344ae36f9c6b7dccd31bf5a53bd11f91dc24736b197ec0b
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
Status
|
2
2
|
--------
|
3
|
-
I consider bbcoder to be stable so you won't see many updates to it in the future. It is perfectly fine to use in
|
4
|
-
the board with newer frameworks etc. If you find any issues or think it needs a feature please submit an issue.
|
3
|
+
I consider bbcoder to be stable so you won't see many updates to it in the future. It is perfectly fine to use in production. The gem itself is pretty simple so it should work across the board with newer frameworks etc. If you find any issues or think it needs a feature please submit an issue.
|
5
4
|
|
6
5
|
|
7
6
|
Features
|
data/lib/bbcoder/base.rb
CHANGED
@@ -18,6 +18,15 @@ class BBCoder
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def parse
|
21
|
+
_parse
|
22
|
+
buffer.join
|
23
|
+
end
|
24
|
+
|
25
|
+
def buffer
|
26
|
+
@buffer ||= BBCoder::Buffer.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def _parse
|
21
30
|
raw.each do |data|
|
22
31
|
case data
|
23
32
|
when /\[\/([^\]]+)\]/
|
@@ -28,12 +37,5 @@ class BBCoder
|
|
28
37
|
buffer.push(data) # content
|
29
38
|
end
|
30
39
|
end
|
31
|
-
|
32
|
-
buffer.join
|
33
|
-
end
|
34
|
-
|
35
|
-
def buffer
|
36
|
-
@buffer ||= BBCoder::Buffer.new
|
37
|
-
end
|
40
|
+
end # _parse
|
38
41
|
end
|
39
|
-
|
data/lib/bbcoder/buffer_tags.rb
CHANGED
@@ -26,13 +26,17 @@ class BBCoder
|
|
26
26
|
|
27
27
|
# logic when popping specific tag
|
28
28
|
def pop(original_tag)
|
29
|
-
tag = original_tag.
|
29
|
+
tag = if original_tag.is_a?(Symbol)
|
30
|
+
original_tag
|
31
|
+
else
|
32
|
+
original_tag.downcase.to_sym
|
33
|
+
end
|
30
34
|
|
31
35
|
# no more tags left to pop || this tag isn't in the list
|
32
36
|
if empty? || !include?(tag)
|
33
37
|
buffer.push("[/#{original_tag}]")
|
34
38
|
elsif last == tag
|
35
|
-
buffer.push(BBCoder::Tag.to_html(_internal.pop, _meta.delete(size+1), buffer.pop(+1)))
|
39
|
+
buffer.push(BBCoder::Tag.to_html(_internal.pop, buffer.depth, _meta.delete(size+1), buffer.pop(+1)))
|
36
40
|
elsif include?(tag)
|
37
41
|
# repeats pop(tag) until we reach the last == tag
|
38
42
|
buffer.push(join(+1))
|
@@ -46,7 +50,7 @@ class BBCoder
|
|
46
50
|
|
47
51
|
1.upto(limit).to_a.collect do
|
48
52
|
# singular tags are caught in the handle method
|
49
|
-
[BBCoder::Tag.handle(_internal.pop, _meta.delete(size+1)), buffer.pop(+1)].join # +1 depth modifier for the buffer
|
53
|
+
[BBCoder::Tag.handle(_internal.pop, buffer.depth, _meta.delete(size+1)), buffer.pop(+1)].join # +1 depth modifier for the buffer
|
50
54
|
end.reverse.join
|
51
55
|
end
|
52
56
|
|
@@ -1,29 +1,25 @@
|
|
1
1
|
class BBCoder
|
2
2
|
class Configuration
|
3
|
-
|
3
|
+
attr_accessor :tags
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@tags = {}
|
7
|
+
end
|
4
8
|
|
5
9
|
def [](value)
|
6
|
-
|
10
|
+
@tags[value]
|
7
11
|
end
|
8
12
|
|
9
13
|
def clear
|
10
|
-
|
14
|
+
@tags = {}
|
11
15
|
end
|
12
16
|
|
13
17
|
def remove name
|
14
|
-
|
18
|
+
@tags.delete(name.to_sym)
|
15
19
|
end
|
16
20
|
|
17
21
|
def tag(name, options = {}, &block)
|
18
|
-
|
19
|
-
block.binding.eval <<-EOS
|
20
|
-
def meta; @meta; end
|
21
|
-
def content; @content; end
|
22
|
-
def singular?; @singularity; end
|
23
|
-
EOS
|
24
|
-
end
|
25
|
-
@@tags[name.to_sym] = BBCoder::Tag.new(name.to_sym, options.merge(:block => block))
|
22
|
+
@tags[name.to_sym] = BBCoder::Tag.new(name.to_sym, options.merge(:block => block))
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
29
|
-
|
data/lib/bbcoder/tag.rb
CHANGED
@@ -7,7 +7,7 @@ class BBCoder
|
|
7
7
|
@options = options.merge(:as => (options[:as] || name), :singular => (options[:singular] || false))
|
8
8
|
end
|
9
9
|
|
10
|
-
def to_html(meta, content, singularity = false)
|
10
|
+
def to_html(depth, meta, content, singularity = false)
|
11
11
|
unless content_valid?(content, singularity) && meta_valid?(meta, singularity) && link_valid?(meta, content)
|
12
12
|
return self.class.reform(name, meta, content, singularity, true)
|
13
13
|
end
|
@@ -16,9 +16,14 @@ class BBCoder
|
|
16
16
|
"<#{options[:as]}>#{content}</#{options[:as]}>"
|
17
17
|
else
|
18
18
|
options[:block].binding.eval <<-EOS
|
19
|
+
@depth = #{depth}
|
19
20
|
@meta = %Q{#{Regexp.escape(meta.to_s)}}
|
20
21
|
@content = %Q{#{Regexp.escape(content.to_s)}}
|
21
22
|
@singularity = #{singularity.to_s}
|
23
|
+
def depth; @depth; end
|
24
|
+
def meta; @meta; end
|
25
|
+
def content; @content; end
|
26
|
+
def singular?; @singularity; end
|
22
27
|
EOS
|
23
28
|
options[:block].call
|
24
29
|
end
|
@@ -75,16 +80,17 @@ class BBCoder
|
|
75
80
|
end
|
76
81
|
|
77
82
|
module ClassMethods
|
78
|
-
def to_html(tag, meta, content, singularity = false)
|
79
|
-
BBCoder.configuration[tag].to_html(meta, content, singularity)
|
83
|
+
def to_html(tag, depth, meta, content, singularity = false)
|
84
|
+
BBCoder.configuration[tag].to_html(depth, meta, content, singularity)
|
80
85
|
end
|
81
86
|
|
82
87
|
# need #handle so we don't get into a reform loop from to_html
|
83
88
|
# checking content validity
|
84
|
-
def handle(tag, meta, content = nil, force_end = false)
|
89
|
+
def handle(tag, depth, meta, content = nil, force_end = false)
|
85
90
|
if BBCoder.configuration[tag] && BBCoder.configuration[tag].singular?
|
86
|
-
to_html(tag, meta, content, true)
|
91
|
+
to_html(tag, depth, meta, content, true)
|
87
92
|
else
|
93
|
+
# reform doesn't really care about depth, so we don't pass it in.
|
88
94
|
reform(tag, meta, content, force_end)
|
89
95
|
end
|
90
96
|
end
|
data/lib/bbcoder/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -6,11 +6,11 @@ describe BBCoder do
|
|
6
6
|
|
7
7
|
context "#configuration" do
|
8
8
|
before do
|
9
|
-
@tags = BBCoder
|
9
|
+
@tags = BBCoder.configuration.tags.clone
|
10
10
|
end
|
11
11
|
|
12
12
|
after do
|
13
|
-
BBCoder
|
13
|
+
BBCoder.configuration.tags = @tags
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should return the same object for multiple calls" do
|
@@ -31,11 +31,11 @@ describe BBCoder do
|
|
31
31
|
|
32
32
|
context "#configure" do
|
33
33
|
before do
|
34
|
-
@tags = BBCoder
|
34
|
+
@tags = BBCoder.configuration.tags.clone
|
35
35
|
end
|
36
36
|
|
37
37
|
after do
|
38
|
-
BBCoder
|
38
|
+
BBCoder.configuration.tags = @tags
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should fail without a block" do
|
@@ -44,8 +44,9 @@ describe BBCoder do
|
|
44
44
|
|
45
45
|
it "should instance_eval the block onto configuration" do
|
46
46
|
block = Proc.new { tag :p }
|
47
|
-
mock(BBCoder).configuration.stub!.instance_eval(&block)
|
48
47
|
BBCoder.configure(&block)
|
48
|
+
|
49
|
+
BBCoder.configuration.tags[:p].should_not be_nil
|
49
50
|
end
|
50
51
|
|
51
52
|
it "should be able to remove a tag" do
|
@@ -75,4 +76,3 @@ describe BBCoder do
|
|
75
76
|
end
|
76
77
|
end
|
77
78
|
end
|
78
|
-
|
data/spec/bbcoder_spec.rb
CHANGED
@@ -175,7 +175,7 @@ EOS
|
|
175
175
|
|
176
176
|
it "should handle an img tag match for meta" do
|
177
177
|
"[img=image.exe]".bbcode_to_html.should == "[img=image.exe]"
|
178
|
-
end
|
178
|
+
p end
|
179
179
|
end
|
180
180
|
|
181
181
|
context "with xss attacks" do
|
@@ -219,4 +219,3 @@ S
|
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
222
|
-
|
data/spec/tag_spec.rb
CHANGED
@@ -87,5 +87,20 @@ describe BBCoder::Tag do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end # #content_valid?
|
90
|
-
end
|
91
90
|
|
91
|
+
|
92
|
+
|
93
|
+
#
|
94
|
+
# Test our depth logic and verify we are binding the variable:
|
95
|
+
# TODO
|
96
|
+
#
|
97
|
+
context "with depths" do
|
98
|
+
before do
|
99
|
+
@depth = BBCoder::Tag.new("strong", :block => proc { "<strong>depth: #{depth} - #{content}</strong>" })
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should allow blocks to use depth as a binded variable" do
|
103
|
+
@depth.to_html(0, nil, "test", false).should == "<strong>depth: 0 - test</strong>"
|
104
|
+
end
|
105
|
+
end # context "with depths"
|
106
|
+
end
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bbcoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- John 'asceth' Long
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rr
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: A gem for parsing bbcode that doesn't rely on regular expressions
|
@@ -66,8 +59,8 @@ executables: []
|
|
66
59
|
extensions: []
|
67
60
|
extra_rdoc_files: []
|
68
61
|
files:
|
69
|
-
- .gemtest
|
70
|
-
- .rspec
|
62
|
+
- ".gemtest"
|
63
|
+
- ".rspec"
|
71
64
|
- Gemfile
|
72
65
|
- Gemfile.lock
|
73
66
|
- LICENSE
|
@@ -90,27 +83,26 @@ files:
|
|
90
83
|
- spec/tag_spec.rb
|
91
84
|
homepage: http://github.com/asceth/bbcoder
|
92
85
|
licenses: []
|
86
|
+
metadata: {}
|
93
87
|
post_install_message:
|
94
88
|
rdoc_options: []
|
95
89
|
require_paths:
|
96
90
|
- lib
|
97
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
92
|
requirements:
|
100
|
-
- -
|
93
|
+
- - ">="
|
101
94
|
- !ruby/object:Gem::Version
|
102
95
|
version: '0'
|
103
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
-
none: false
|
105
97
|
requirements:
|
106
|
-
- -
|
98
|
+
- - ">="
|
107
99
|
- !ruby/object:Gem::Version
|
108
100
|
version: '0'
|
109
101
|
requirements: []
|
110
102
|
rubyforge_project: bbcoder
|
111
|
-
rubygems_version:
|
103
|
+
rubygems_version: 2.4.5
|
112
104
|
signing_key:
|
113
|
-
specification_version:
|
105
|
+
specification_version: 4
|
114
106
|
summary: BBCode parser
|
115
107
|
test_files:
|
116
108
|
- spec/base_spec.rb
|