trainbbcode 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- TrainBBCode (1.0.1)
4
+ TrainBBCode (1.1.0)
5
5
  coderay
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- coderay (0.9.6)
10
+ coderay (0.9.7)
11
11
  diff-lcs (1.1.2)
12
12
  rspec (2.3.0)
13
13
  rspec-core (~> 2.3.0)
@@ -23,5 +23,4 @@ PLATFORMS
23
23
 
24
24
  DEPENDENCIES
25
25
  TrainBBCode!
26
- coderay
27
26
  rspec
data/README.rdoc CHANGED
@@ -1,24 +1,18 @@
1
1
  = Train BBCode
2
2
 
3
+ {Homepage}[http://trainbbcode.arcath.net/]
4
+
3
5
  Rails Gem for BBCode
4
6
 
5
7
  == Install
6
8
 
7
- === As a Gem
8
-
9
- gem install trainbbcode
10
-
11
- For rails you will need to add:
12
-
13
- config.gem "trainbbcode"
9
+ Add:
14
10
 
15
- to config/enviroments.rb and then install the gem using:
11
+ gem "trainbbcode"
16
12
 
17
- rake gems:install
18
-
19
- === As a Plugin
13
+ to your Gemfile and then install the gem using:
20
14
 
21
- script/plugin install git://github.com/Arcath/TrainBBCode
15
+ bundle install
22
16
 
23
17
  == Usage
24
18
 
data/lib/trainbbcode.rb CHANGED
@@ -4,6 +4,7 @@ require 'trainbbcode/configure.rb'
4
4
  require 'trainbbcode/string.rb'
5
5
  require 'trainbbcode/css.rb'
6
6
  require 'trainbbcode/swear_filter.rb'
7
+ require 'trainbbcode/coderay'
7
8
  require 'rubygems'
8
9
  require 'coderay'
9
10
 
@@ -37,18 +38,6 @@ class TBBC
37
38
  s=s.gsub(/<br \/><(ul|li|table|tr|td|th)/,'<\1')
38
39
  s=s.gsub(/<br \/><\/(ul|li|table|tr|td|th)/,'</\1')
39
40
  end
40
-
41
- def coderay(input)
42
- input=input.gsub("\r","")
43
- scan=input.scan(/\[code lang=(.+?)\](.+?)\[\/code\]/m)
44
- scan.each do |splits|
45
- parse=splits[1].gsub("&lt;","<").gsub("&gt;",">")
46
- lang=splits[0]
47
- parsed="[nobbc]" + CodeRay.scan(parse, lang).div(:line_numbers => @config[:syntax_highlighting_line_numbers]) + "[/nobbc]"
48
- input=input.gsub("[code lang=#{lang}]#{splits[1]}[/code]",parsed)
49
- end
50
- input
51
- end
52
41
 
53
42
  def needs_html_safe?
54
43
  if defined? Rails
@@ -4,4 +4,4 @@ module TBBCHelper
4
4
  bbc.conf(config) if config
5
5
  bbc.css
6
6
  end
7
- end
7
+ end
@@ -0,0 +1,27 @@
1
+ class TBBC
2
+ def coderay(input)
3
+ input=input.gsub("\r","")
4
+ scan=input.scan(/\[code lang=(.+?)\](.+?)\[\/code\]/m)
5
+ scan.each do |splits|
6
+ parse=splits[1].gsub("&lt;","<").gsub("&gt;",">")
7
+ lang=splits[0]
8
+ parsed="[nobbc]" + CodeRay.scan(parse, lang).div(:line_numbers => @config[:syntax_highlighting_line_numbers], :css => :class) + "[/nobbc]"
9
+ input=input.gsub("[code lang=#{lang}]#{splits[1]}[/code]",parsed)
10
+ end
11
+ coderay_styled(input)
12
+ end
13
+
14
+ def coderay_styled(input)
15
+ output = input.gsub(/class="CodeRay"/,"style=\"background-color: #232323; border: 1px solid black; font-family: 'Courier New', 'Terminal', monospace; color: #E6E0DB; padding: 3px 5px; overflow: auto; font-size: 12px; margin: 12px 0;\"")
16
+ output = output.gsub(/<pre>/,"<pre style=\"margin: 0px; padding: 0px;\">")
17
+ output = output.gsub(/class="an"/,"style=\"#{@config[:syntax_highlighting_html]}\"").gsub(/class="c"/,"style=\"#{@config[:syntax_highlighting_comment]}\"")
18
+ output = output.gsub(/class="ch"/,"style=\"#{@config[:syntax_highlighting_escaped]}\"").gsub(/class="cl"/,"style=\"#{@config[:syntax_highlighting_class]}\"")
19
+ output = output.gsub(/class="co"/,"style=\"#{@config[:syntax_highlighting_constant]}\"").gsub(/class="fl"/,"style=\"#{@config[:syntax_highlighting_float]}\"")
20
+ output = output.gsub(/class="fu"/,"style=\"#{@config[:syntax_highlighting_function]}\"").gsub(/class="gv"/,"style=\"#{@config[:syntax_highlighting_global]}\"")
21
+ output = output.gsub(/class="i"/,"style=\"#{@config[:syntax_highlighting_integer]}\"").gsub(/class="il"/,"style=\"#{@config[:syntax_highlighting_inline]}\"")
22
+ output = output.gsub(/class="iv"/,"style=\"#{@config[:syntax_highlighting_instance]}\"").gsub(/class="pp"/,"style=\"#{@config[:syntax_highlighting_doctype]}\"")
23
+ output = output.gsub(/class="r"/,"style=\"#{@config[:syntax_highlighting_keyword]}\"").gsub(/class="rx"/,"style=\"#{@config[:syntax_highlighting_regex]}\"")
24
+ output = output.gsub(/class="s"/,"style=\"#{@config[:syntax_highlighting_string]}\"").gsub(/class="sy"/,"style=\"#{@config[:syntax_highlighting_symbol]}\"")
25
+ output = output.gsub(/class="ta"/,"style=\"#{@config[:syntax_highlighting_html]}\"").gsub(/class="pc"/,"style=\"#{@config[:syntax_highlighting_boolean]}\"")
26
+ end
27
+ end
@@ -20,31 +20,31 @@ class TBBC
20
20
  #
21
21
  # Is non-overiding so any config set by the user in thier own file remains.
22
22
  def load_config_from_defaults
23
- @config[:configed_by] ||= "user"
24
- @config[:image_alt] ||= "Posted Image"
25
- @config[:url_target] ||= "_BLANK"
26
- @config[:allow_defaults] ||= true
27
- @config[:table_width] ||= "100%"
28
- @config[:syntax_highlighting] ||= true
29
- @config[:syntax_highlighting_html] ||= "color:#E7BE69"
30
- @config[:syntax_highlighting_comment] ||= "color:#BC9358; font-style: italic;"
31
- @config[:syntax_highlighting_escaped] ||= "color:#509E4F"
32
- @config[:syntax_highlighting_class] ||= "color:#FFF"
33
- @config[:syntax_highlighting_constant] ||= "color:#FFF"
34
- @config[:syntax_highlighting_float] ||= "color:#A4C260"
35
- @config[:syntax_highlighting_function] ||= "color:#FFC56D"
36
- @config[:syntax_highlighting_global] ||= "color:#D0CFFE"
37
- @config[:syntax_highlighting_integer] ||= "color:#A4C260"
38
- @config[:syntax_highlighting_inline] ||= "background:#151515"
39
- @config[:syntax_highlighting_instance] ||= "color:#D0CFFE"
40
- @config[:syntax_highlighting_doctype] ||= "color:#E7BE69"
41
- @config[:syntax_highlighting_keyword] ||= "color:#CB7832"
42
- @config[:syntax_highlighting_regex] ||= "color:#A4C260"
43
- @config[:syntax_highlighting_string] ||= "color:#A4C260"
44
- @config[:syntax_highlighting_symbol] ||= "color:#6C9CBD"
45
- @config[:syntax_highlighting_html] ||= "color:#E7BE69"
46
- @config[:syntax_highlighting_boolean] ||= "color:#6C9CBD"
47
- @config[:syntax_highlighting_line_numbers]||= :inline
48
- @config[:swear_words] ||= []
23
+ @config[:configed_by] ||= "user"
24
+ @config[:image_alt] ||= "Posted Image"
25
+ @config[:url_target] ||= "_BLANK"
26
+ @config[:allow_defaults] ||= true
27
+ @config[:table_width] ||= "100%"
28
+ @config[:syntax_highlighting] ||= true
29
+ @config[:syntax_highlighting_html] ||= "color:#E7BE69"
30
+ @config[:syntax_highlighting_comment] ||= "color:#BC9358; font-style: italic;"
31
+ @config[:syntax_highlighting_escaped] ||= "color:#509E4F"
32
+ @config[:syntax_highlighting_class] ||= "color:#FFF"
33
+ @config[:syntax_highlighting_constant] ||= "color:#FFF"
34
+ @config[:syntax_highlighting_float] ||= "color:#A4C260"
35
+ @config[:syntax_highlighting_function] ||= "color:#FFC56D"
36
+ @config[:syntax_highlighting_global] ||= "color:#D0CFFE"
37
+ @config[:syntax_highlighting_integer] ||= "color:#A4C260"
38
+ @config[:syntax_highlighting_inline] ||= "background:#151515"
39
+ @config[:syntax_highlighting_instance] ||= "color:#D0CFFE"
40
+ @config[:syntax_highlighting_doctype] ||= "color:#E7BE69"
41
+ @config[:syntax_highlighting_keyword] ||= "color:#CB7832"
42
+ @config[:syntax_highlighting_regex] ||= "color:#A4C260"
43
+ @config[:syntax_highlighting_string] ||= "color:#A4C260"
44
+ @config[:syntax_highlighting_symbol] ||= "color:#6C9CBD"
45
+ @config[:syntax_highlighting_html] ||= "color:#E7BE69"
46
+ @config[:syntax_highlighting_boolean] ||= "color:#6C9CBD"
47
+ @config[:syntax_highlighting_line_numbers] ||= :inline
48
+ @config[:swear_words] ||= []
49
49
  end
50
50
  end
@@ -2,46 +2,7 @@ class TBBC
2
2
 
3
3
  # Returns the css required for coderay
4
4
  def css(config = nil)
5
- conf config
6
- output=" <style type=\"text/css\">
7
- .CodeRay {
8
- background-color: #232323;
9
- border: 1px solid black;
10
- font-family: 'Courier New', 'Terminal', monospace;
11
- color: #E6E0DB;
12
- padding: 3px 5px;
13
- overflow: auto;
14
- font-size: 12px;
15
- margin: 12px 0;
16
- }
17
- .CodeRay pre {
18
- margin: 0px;
19
- padding: 0px;
20
- }
21
-
22
- .CodeRay .an { #{@config[:syntax_highlighting_html]} } /* html attribute */
23
- .CodeRay .c { #{@config[:syntax_highlighting_comment]} } /* comment */
24
- .CodeRay .ch { #{@config[:syntax_highlighting_escaped]} } /* escaped character */
25
- .CodeRay .cl { #{@config[:syntax_highlighting_class]} } /* class */
26
- .CodeRay .co { #{@config[:syntax_highlighting_constant]} } /* constant */
27
- .CodeRay .fl { #{@config[:syntax_highlighting_float]} } /* float */
28
- .CodeRay .fu { #{@config[:syntax_highlighting_function]} } /* function */
29
- .CodeRay .gv { #{@config[:syntax_highlighting_global]} } /* global variable */
30
- .CodeRay .i { #{@config[:syntax_highlighting_integer]} } /* integer */
31
- .CodeRay .il { #{@config[:syntax_highlighting_inline]} } /* inline code */
32
- .CodeRay .iv { #{@config[:syntax_highlighting_instance]} } /* instance variable */
33
- .CodeRay .pp { #{@config[:syntax_highlighting_doctype]} } /* doctype */
34
- .CodeRay .r { #{@config[:syntax_highlighting_keyword]} } /* keyword */
35
- .CodeRay .rx { #{@config[:syntax_highlighting_regex]} } /* regex */
36
- .CodeRay .s { #{@config[:syntax_highlighting_string]} } /* string */
37
- .CodeRay .sy { #{@config[:syntax_highlighting_symbol]} } /* symbol */
38
- .CodeRay .ta { #{@config[:syntax_highlighting_html]} } /* html tag */
39
- .CodeRay .pc { #{@config[:syntax_highlighting_boolean]} } /* boolean */
40
- </style>"
41
- if needs_html_safe? then
42
- return output.html_safe
43
- else
44
- return output
45
- end
5
+ warn "[DEPRECATION] `css` is no longer used, styles are applied inline."
6
+ ""
46
7
  end
47
8
  end
@@ -1,26 +1,30 @@
1
1
  class TBBC
2
- Tags = [[/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>',:strong_enabled],
3
- [/\[i\](.*?)\[\/i\]/,'<i>\1</i>',:italic_enabled],
4
- [/\[u\](.*?)\[\/u\]/,'<u>\1</u>',:underline_enabled],
5
- [/\[url\](.*?)\[\/url\]/,'<a href="\1" target="@config[:url_target]">\1</a>',:url_enabled],
6
- [/\[url=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="@config[:url_target]">\2</a>',:url_enabled],
7
- [/\[url=(.*?) target=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="\2">\3</a>',:url_enabled],
8
- [/\[img\](.*?)\[\/img\]/,'<img src="\1" alt="@config[:image_alt]" />',:image_enabled],
9
- [/\[img alt=(.*?)\](.*?)\[\/img\]/,'<img src="\2" alt="\1" />',:image_enabled],
10
- [/\[ul\](.*?)\[\/ul\]/,'<ul>\1</ul>',:list_enabled],
11
- [/\[ol\](.*?)\[\/ol\]/,'<ol>\1</ol>',:list_enabled],
12
- [/\[li\](.*?)\[\/li\]/,'<li>\1</li>',:list_enabled],
13
- [/\[quote\](.*?)\[\/quote\]/,'<blockquote>\1</blockquote>',:quote_enabled],
14
- [/\[quote=(.*?)\](.*?)\[\/quote\]/,'<blockquote><i>Posted by <b>\1</b></i><br />\2</blockquote>',:quote_enabled],
15
- [/\[color=(.*?)\](.*?)\[\/color\]/,'<span style="color:\1;">\2</span>',:color_enabled],
16
- [/\[center\](.*?)\[\/center\]/,'<div style="text-align:center">\1</div>',:alignment_enabled],
17
- [/\[left\](.*?)\[\/left\]/,'<div style="text-align:left">\1</div>',:alignment_enabled],
18
- [/\[right\](.*?)\[\/right\]/,'<div style="text-align:right">\1</div>',:alignment_enabled],
19
- [/\[acronym=(.*?)\](.*?)\[\/acronym\]/,'<acronym title="\1">\2</acronym>',:acronym_enabled],
20
- [/\[table\](.*?)\[\/table\]/,'<table width="@config[:table_width]">\1</table>',:table_enabled],
21
- [/\[tr\](.*?)\[\/tr\]/,'<tr>\1</tr>',:table_enabled],
22
- [/\[td\](.*?)\[\/td\]/,'<td>\1</td>',:table_enabled],
23
- [/\[th\](.*?)\[\/th\]/,'<th>\1</th>',:table_enabled]]
2
+ Tags = [[/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>',:strong_enabled,"[b]BOLD[/b]","<strong>BOLD</strong>"],
3
+ [/\[i\](.*?)\[\/i\]/,'<i>\1</i>',:italic_enabled,"[i]italics[/i]","<i>italics</i>"],
4
+ [/\[u\](.*?)\[\/u\]/,'<u>\1</u>',:underline_enabled,"[u]underline[/u]","<u>underline</u>"],
5
+ [/\[url\](.*?)\[\/url\]/,'<a href="\1" target="@config[:url_target]">\1</a>',:url_enabled,"[url]http://www.example.com[/url]","<a href=\"http://www.example.com\" target=\"_BLANK\">http://www.example.com</a>"],
6
+ [/\[url=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="@config[:url_target]">\2</a>',:url_enabled,"[url=http://www.example.com]Example[/url]","<a href=\"http://www.example.com\" target=\"_BLANK\">Example</a>"],
7
+ [/\[url=(.*?) target=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="\2">\3</a>',:url_enabled,"[url=http://www.example.com]Example[/url]","<a href=\"http://www.example.com\" target=\"_BLANK\">Example</a>"],
8
+ [/\[img\](.*?)\[\/img\]/,'<img src="\1" alt="@config[:image_alt]" />',:image_enabled,"[img]test.jpg[/img]","<img src=\"test.jpg\" alt=\"Posted Image\" />"],
9
+ [/\[img alt=(.*?)\](.*?)\[\/img\]/,'<img src="\2" alt="\1" />',:image_enabled,"[img alt=Posted Image]test.jpg[/img]","<img src=\"test.jpg\" alt=\"Posted Image\" />"],
10
+ [/\[ul\](.*?)\[\/ul\]/,'<ul>\1</ul>',:list_enabled,"[ul]list[/ul]","<ul>list</ul>"],
11
+ [/\[ol\](.*?)\[\/ol\]/,'<ol>\1</ol>',:list_enabled,"[ol]list[/ol]","<ol>list</ol>"],
12
+ [/\[li\](.*?)\[\/li\]/,'<li>\1</li>',:list_enabled,"[li]list[/li]","<li>list</li>"],
13
+ [/\[quote\](.*?)\[\/quote\]/,'<blockquote>\1</blockquote>',:quote_enabled,"[quote]quote[/quote]","<blockquote>quote</blockquote>"],
14
+ [/\[quote=(.*?)\](.*?)\[\/quote\]/,'<blockquote><i>Posted by <b>\1</b></i><br />\2</blockquote>',:quote_enabled,"[quote=user]quote[/quote]","<blockquote><i>Posted by <b>user</b></i><br />quote</blockquote>"],
15
+ [/\[color=(.*?)\](.*?)\[\/color\]/,'<span style="color:\1;">\2</span>',:color_enabled,"[color=red]red text[/color]","<span style=\"color:red;\">red text</span>"],
16
+ [/\[center\](.*?)\[\/center\]/,'<div style="text-align:center">\1</div>',:alignment_enabled,"[center]centered text[/center]","<div style=\"text-align:center\">centered text</div>"],
17
+ [/\[left\](.*?)\[\/left\]/,'<div style="text-align:left">\1</div>',:alignment_enabled,"[left]left text[/left]","<div style=\"text-align:left\">left text</div>"],
18
+ [/\[right\](.*?)\[\/right\]/,'<div style="text-align:right">\1</div>',:alignment_enabled,"[right]right text[/right]","<div style=\"text-align:right\">right text</div>"],
19
+ [/\[acronym=(.*?)\](.*?)\[\/acronym\]/,'<acronym title="\1">\2</acronym>',:acronym_enabled,"[acronym=this]that[/acronym]","<acronym title=\"this\">that</acronym>"],
20
+ [/\[table\](.*?)\[\/table\]/,'<table width="@config[:table_width]">\1</table>',:table_enabled,"[table]...[/table]","<table width=\"100%\">...</table>"],
21
+ [/\[tr\](.*?)\[\/tr\]/,'<tr>\1</tr>',:table_enabled,"[tr]...[/tr]","<tr>...</tr>"],
22
+ [/\[td\](.*?)\[\/td\]/,'<td>\1</td>',:table_enabled,"[td]...[/td]","<td>...</td>"],
23
+ [/\[th\](.*?)\[\/th\]/,'<th>\1</th>',:table_enabled,"[th]...[/th]","<th>...</th>"],
24
+ [/\[h1\](.*?)\[\/h1\]/,'<h1>\1</h1>',:header_enabled,'[h1]heading[/h1]',"<h1>heading</h1>"],
25
+ [/\[h2\](.*?)\[\/h2\]/,'<h2>\1</h2>',:header_enabled,'[h2]heading[/h2]',"<h2>heading</h2>"],
26
+ [/\[h3\](.*?)\[\/h3\]/,'<h3>\1</h3>',:header_enabled,'[h3]heading[/h3]',"<h3>heading</h3>"],
27
+ [/\[h4\](.*?)\[\/h4\]/,'<h4>\1</h4>',:header_enabled,'[h4]heading[/h4]',"<h4>heading</h4>"]]
24
28
 
25
29
  private
26
30
 
@@ -1,3 +1,3 @@
1
1
  class TBBC
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -5,9 +5,11 @@ def upcaser(input)
5
5
  end
6
6
 
7
7
  describe TBBC, "#parse" do
8
- it "Should return <strong>BOLD</strong> for [b]BOLD[/b]" do
9
- TBBC.new.parse("[b]BOLD[/b]").should == "<strong>BOLD</strong>"
10
- end
8
+ TBBC::Tags.each do |tag|
9
+ it "Should return #{tag[4]} for #{tag[3]}" do
10
+ tag[3].tbbc.should == tag[4]
11
+ end
12
+ end
11
13
  end
12
14
 
13
15
  describe String, "#tbbc" do
@@ -33,5 +35,5 @@ describe String, "#tbbc" do
33
35
 
34
36
  it "Should allow for 2 identical callbacks per string" do
35
37
  "[up]HeLlo WorLd[/up] and [up]Bye bYe WorLd[/up]".tbbc(:custom_tags => [[/\[up\](.*?)\[\/up\]/,"Callback: upcaser",true]]).should == "HELLO WORLD and BYE BYE WORLD"
36
- end
38
+ end
37
39
  end
data/trainbbcode.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Adam \"Arcath\" Laycock"]
10
10
  s.email = ["gems@arcath.net"]
11
- s.homepage = "http://www.arcath.net"
11
+ s.homepage = "http://trainbbcode.arcath.net"
12
12
  s.summary = "Provides BBCode for Ruby."
13
13
 
14
14
  s.add_development_dependency "rspec"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trainbbcode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 31
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam "Arcath" Laycock
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-21 00:00:00 +00:00
18
+ date: 2011-05-18 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,7 @@ files:
64
64
  - init.rb
65
65
  - lib/trainbbcode.rb
66
66
  - lib/trainbbcode/application_helper.rb
67
+ - lib/trainbbcode/coderay.rb
67
68
  - lib/trainbbcode/configure.rb
68
69
  - lib/trainbbcode/css.rb
69
70
  - lib/trainbbcode/parse.rb
@@ -74,7 +75,7 @@ files:
74
75
  - spec/trainbbcode_spec.rb
75
76
  - trainbbcode.gemspec
76
77
  has_rdoc: true
77
- homepage: http://www.arcath.net
78
+ homepage: http://trainbbcode.arcath.net
78
79
  licenses: []
79
80
 
80
81
  post_install_message:
@@ -103,9 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  requirements: []
104
105
 
105
106
  rubyforge_project:
106
- rubygems_version: 1.3.7
107
+ rubygems_version: 1.6.2
107
108
  signing_key:
108
109
  specification_version: 3
109
110
  summary: Provides BBCode for Ruby.
110
- test_files: []
111
-
111
+ test_files:
112
+ - spec/trainbbcode_spec.rb