bbcoder 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bbcoder (0.1.6)
4
+ bbcoder (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.1.2)
10
- rr (1.0.2)
11
- rspec (2.4.0)
12
- rspec-core (~> 2.4.0)
13
- rspec-expectations (~> 2.4.0)
14
- rspec-mocks (~> 2.4.0)
15
- rspec-core (2.4.0)
16
- rspec-expectations (2.4.0)
17
- diff-lcs (~> 1.1.2)
18
- rspec-mocks (2.4.0)
9
+ diff-lcs (1.1.3)
10
+ rr (1.0.4)
11
+ rspec (2.9.0)
12
+ rspec-core (~> 2.9.0)
13
+ rspec-expectations (~> 2.9.0)
14
+ rspec-mocks (~> 2.9.0)
15
+ rspec-core (2.9.0)
16
+ rspec-expectations (2.9.1)
17
+ diff-lcs (~> 1.1.3)
18
+ rspec-mocks (2.9.0)
19
19
 
20
20
  PLATFORMS
21
21
  ruby
data/README.md CHANGED
@@ -41,8 +41,8 @@ Configuration Examples
41
41
  tag :ol
42
42
  tag :li, :parents => [:ol, :ul]
43
43
 
44
- tag :img, :match => /^.*(png|bmp|jpg|gif)$/ do
45
- %(<a href="#{content}"><img src="#{content}" /></a>)
44
+ tag :img, :match => /^.*(png|bmp|jpe?g|gif)$/ do
45
+ %(<a href="#{singular? ? meta : content}"><img src="#{singular? ? meta : content}" /></a>)
46
46
  end
47
47
 
48
48
  tag :code do
@@ -66,7 +66,9 @@ Configuration Examples
66
66
  Options for #tag
67
67
 
68
68
  * :as (symbol) -> use this as the html element ([b] becomes strong)
69
- * :match (regex) -> convert this tag and its content to html only if the content matches the regex
69
+ * :match (regex) -> convert this tag and its content to html only if the content and meta matches the regex (see img tag above for example)
70
+ * :match_meta (regex) -> same as :match except only for meta
71
+ * :match_content (regex) -> same as :match except only for content
70
72
  * :parents ([symbol]) -> ignore this tag if there is no open tag that matches its parents
71
73
  * :singular (true|false) -> use this if the tag does not require an ending tag
72
74
 
data/lib/bbcoder/tag.rb CHANGED
@@ -8,7 +8,7 @@ class BBCoder
8
8
  end
9
9
 
10
10
  def to_html(meta, content, singularity = false)
11
- return self.class.reform(name, meta, content, true) unless content_valid?(content)
11
+ return self.class.reform(name, meta, content, singularity, true) unless content_valid?(content, singularity) && meta_valid?(meta, singularity)
12
12
 
13
13
  if options[:block].nil?
14
14
  "<#{options[:as]}>#{content}</#{options[:as]}>"
@@ -22,12 +22,33 @@ class BBCoder
22
22
  end
23
23
  end
24
24
 
25
- def content_valid?(content)
26
- return true if content.nil? && options[:singular]
25
+ def meta_valid?(meta, singularity)
26
+ return true if meta.nil?
27
+
28
+ unless options[:match].nil?
29
+ return false if meta.match(options[:match]).nil?
30
+ end
31
+
32
+ unless options[:match_meta].nil?
33
+ return false if meta.match(options[:match_meta]).nil?
34
+ end
35
+
36
+ return true
37
+ end
38
+
39
+ def content_valid?(content, singularity)
40
+ return true if content.nil? && (options[:singular] && singularity)
27
41
  return false if content.nil?
28
- return true if options[:match].nil?
29
42
 
30
- return !content.match(options[:match]).nil?
43
+ unless options[:match].nil?
44
+ return false if content.match(options[:match]).nil?
45
+ end
46
+
47
+ unless options[:match_content].nil?
48
+ return false if content.match(options[:match_content]).nil?
49
+ end
50
+
51
+ return true
31
52
  end
32
53
 
33
54
  def parents
@@ -53,8 +74,8 @@ class BBCoder
53
74
  end
54
75
  end
55
76
 
56
- def reform(tag, meta, content = nil, force_end = false)
57
- if content.nil? && !force_end
77
+ def reform(tag, meta, content = nil, singularity = false, force_end = false)
78
+ if (content.nil? && !force_end) || singularity
58
79
  %(#{reform_open(tag, meta)})
59
80
  else
60
81
  %(#{reform_open(tag, meta)}#{content}#{reform_end(tag)})
@@ -1,3 +1,3 @@
1
1
  class BBCoder
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/bbcoder.rb CHANGED
@@ -56,8 +56,8 @@ BBCoder.configure do
56
56
  end
57
57
  end
58
58
 
59
- tag :img, :match => /^.*(png|bmp|jpg|gif)$/ do
60
- %(<a href="#{content}"><img src="#{content}" /></a>)
59
+ tag :img, :match => /^.*(png|bmp|jpe?g|gif)$/, :singular => true do
60
+ %(<a href="#{singular? ? meta : content}"><img src="#{singular? ? meta : content}" /></a>)
61
61
  end
62
62
 
63
63
  tag :youtube do
data/spec/bbcoder_spec.rb CHANGED
@@ -136,6 +136,20 @@ EOS
136
136
  it "should handle singular tags in non singular form" do
137
137
  "[p]I [sub]me[/sub] think [sub]thought[/sub]; therefore [sup]well[/sup] I am[/p]".bbcode_to_html.should == "<p>I <sub>me</sub> think <sub>thought</sub>; therefore <sup>well</sup> I am</p>"
138
138
  end
139
+
140
+ it "should handle incorrect singular tags" do
141
+ "[img=image.exe]".bbcode_to_html.should == "[img=image.exe]"
142
+ end
143
+ end
144
+
145
+ context "with bad matches" do
146
+ it "should handle an img tag match for content" do
147
+ "[img]image.exe[/img]".bbcode_to_html.should == "[img]image.exe[/img]"
148
+ end
149
+
150
+ it "should handle an img tag match for meta" do
151
+ "[img=image.exe]".bbcode_to_html.should == "[img=image.exe]"
152
+ end
139
153
  end
140
154
  end
141
155
 
data/spec/tag_spec.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBCoder::Tag do
4
+
5
+ context "#meta_valid?" do
6
+ context "with match_meta" do
7
+ before do
8
+ @tag = BBCoder::Tag.new("img", :match_meta => /^.*(png|bmp|jpg|gif)$/)
9
+ end
10
+
11
+ it "should return false when tag meta is invalid" do
12
+ @tag.meta_valid?("image.exe", false).should == false
13
+ end
14
+
15
+ it "should return true when tag meta is valid" do
16
+ @tag.meta_valid?("image.png", false).should == true
17
+ end
18
+
19
+ it "should return true when tag meta is nil" do
20
+ @tag.meta_valid?(nil, false).should == true
21
+ end
22
+ end
23
+
24
+ context "with match" do
25
+ before do
26
+ @tag = BBCoder::Tag.new("img", :match => /^.*(png|bmp|jpg|gif)$/)
27
+ end
28
+
29
+ it "should return false when tag meta is invalid" do
30
+ @tag.meta_valid?("image.exe", false).should == false
31
+ end
32
+
33
+ it "should return true when tag meta is valid" do
34
+ @tag.meta_valid?("image.png", false).should == true
35
+ end
36
+
37
+ it "should return true when tag meta is nil" do
38
+ @tag.meta_valid?(nil, false).should == true
39
+ end
40
+ end
41
+ end # #meta_valid?
42
+
43
+ context "#content_valid?" do
44
+ context "with match_content" do
45
+ before do
46
+ @tag = BBCoder::Tag.new("strong", :match_content => /^.*(png|bmp|jpg|gif)$/)
47
+ @singular_tag = BBCoder::Tag.new("strong", :match_content => /^.*(png|bmp|jpg|gif)$/, :singular => true)
48
+ end
49
+
50
+ it "should return false when tag content is invalid" do
51
+ @tag.content_valid?("image.exe", false).should == false
52
+ end
53
+
54
+ it "should return true when tag content is valid" do
55
+ @tag.content_valid?("image.png", false).should == true
56
+ end
57
+
58
+ it "should return false if content is nil" do
59
+ @tag.content_valid?(nil, false).should == false
60
+ end
61
+
62
+ it "should return true when tag content is nil and tag is singular" do
63
+ @singular_tag.content_valid?(nil, true).should == true
64
+ end
65
+ end
66
+
67
+ context "with match" do
68
+ before do
69
+ @tag = BBCoder::Tag.new("strong", :match => /^.*(png|bmp|jpg|gif)$/)
70
+ @singular_tag = BBCoder::Tag.new("strong", :match => /^.*(png|bmp|jpg|gif)$/, :singular => true)
71
+ end
72
+
73
+ it "should return false when tag content is invalid" do
74
+ @tag.content_valid?("image.exe", false).should == false
75
+ end
76
+
77
+ it "should return true when tag content is valid" do
78
+ @tag.content_valid?("image.png", false).should == true
79
+ end
80
+
81
+ it "should return false if content is nil" do
82
+ @tag.content_valid?(nil, false).should == false
83
+ end
84
+
85
+ it "should return true when tag content is nil and tag is singular" do
86
+ @singular_tag.content_valid?(nil, true).should == true
87
+ end
88
+ end
89
+ end # #content_valid?
90
+ end
91
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbcoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-07 00:00:00.000000000Z
12
+ date: 2012-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &17173760 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *17173760
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rr
27
- requirement: &17173340 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *17173340
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  description: A gem for parsing bbcode that doesn't rely on regular expressions
37
47
  email:
38
48
  - machinist@asceth.com
@@ -61,6 +71,7 @@ files:
61
71
  - spec/buffer_spec.rb
62
72
  - spec/buffer_tags_spec.rb
63
73
  - spec/spec_helper.rb
74
+ - spec/tag_spec.rb
64
75
  homepage: http://github.com/asceth/bbcoder
65
76
  licenses: []
66
77
  post_install_message:
@@ -81,8 +92,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
92
  version: '0'
82
93
  requirements: []
83
94
  rubyforge_project: bbcoder
84
- rubygems_version: 1.8.10
95
+ rubygems_version: 1.8.21
85
96
  signing_key:
86
97
  specification_version: 3
87
98
  summary: BBCode parser
88
- test_files: []
99
+ test_files:
100
+ - spec/base_spec.rb
101
+ - spec/bbcoder_spec.rb
102
+ - spec/buffer_spec.rb
103
+ - spec/buffer_tags_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/tag_spec.rb