trainbbcode 0.3.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +8 -1
- data/README.rdoc +27 -14
- data/Rakefile +2 -2
- data/lib/trainbbcode/configure.rb +50 -0
- data/lib/trainbbcode/css.rb +42 -0
- data/lib/trainbbcode/parse.rb +37 -0
- data/lib/trainbbcode/string.rb +14 -0
- data/lib/trainbbcode/tags.rb +46 -0
- data/lib/trainbbcode.rb +30 -157
- data/trainbbcode.gemspec +5 -5
- metadata +14 -4
data/Manifest
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
-
Manifest
|
2
1
|
README.rdoc
|
3
2
|
Rakefile
|
4
3
|
init.rb
|
5
4
|
lib/trainbbcode.rb
|
5
|
+
lib/trainbbcode/application_helper.rb
|
6
|
+
lib/trainbbcode/configure.rb
|
7
|
+
lib/trainbbcode/css.rb
|
8
|
+
lib/trainbbcode/parse.rb
|
9
|
+
lib/trainbbcode/string.rb
|
10
|
+
lib/trainbbcode/swear_filter.rb
|
11
|
+
lib/trainbbcode/tags.rb
|
6
12
|
trainbbcode.gemspec
|
13
|
+
Manifest
|
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ Rails Gem for BBCode
|
|
6
6
|
|
7
7
|
=== As a Gem
|
8
8
|
|
9
|
-
gem install trainbbcode
|
9
|
+
gem install trainbbcode
|
10
10
|
|
11
11
|
For rails you will need to add:
|
12
12
|
|
@@ -15,25 +15,38 @@ For rails you will need to add:
|
|
15
15
|
to config/enviroments.rb and then install the gem using:
|
16
16
|
|
17
17
|
rake gems:install
|
18
|
+
|
19
|
+
=== As a Plugin
|
20
|
+
|
21
|
+
script/plugin install git://github.com/Arcath/TrainBBCode
|
18
22
|
|
19
23
|
== Usage
|
20
24
|
|
21
|
-
|
25
|
+
The easiest way to use tbbc is with the string method provided, for example
|
26
|
+
|
27
|
+
>> "[b]Bold[/b]".tbbc
|
28
|
+
=> "<strong>Bold</strong>"
|
29
|
+
|
30
|
+
== Configuration
|
31
|
+
|
32
|
+
=== On the fly
|
33
|
+
|
34
|
+
If you want to quickly change something, e.g. disable a tag for a specific .tbbc call then you can configure it in the call:
|
22
35
|
|
23
|
-
|
36
|
+
>> "[b]Bold[/b] [i]Italic[/i]".tbbc(:strong_enabled => false)
|
37
|
+
=> "[b]Bold[/b] <i>Italic</i>"
|
24
38
|
|
25
|
-
|
39
|
+
Whilst this method works its not the cleanest way of doing it. Its fine for simple things like disabling a single tag (e.g. tables in signatures) but when defining custom tags or the coderay css its better to use the other config method
|
26
40
|
|
27
|
-
|
41
|
+
=== Globaly
|
28
42
|
|
29
|
-
|
43
|
+
This is done using config/tbbc.rb, this file needs to look like this:
|
30
44
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
45
|
+
class TBBC
|
46
|
+
def user_config
|
47
|
+
#Change the Config here
|
48
|
+
@config[:strong_enabled] = false
|
49
|
+
end
|
50
|
+
end
|
36
51
|
|
37
|
-
|
38
|
-
|
39
|
-
For More information and examples visit http://www.arcath.net/pages/2
|
52
|
+
That would produce the same output as the on the fly config but would work when ever you used .tbbc in the project.
|
data/Rakefile
CHANGED
@@ -2,9 +2,9 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('trainbbcode','0.
|
5
|
+
Echoe.new('trainbbcode','1.0.0') do |p|
|
6
6
|
p.description = "Provides BBCode for Ruby."
|
7
|
-
p.url = "http://www.arcath.net/
|
7
|
+
p.url = "http://www.arcath.net/"
|
8
8
|
p.author = "Adam \"Arcath\" Laycock"
|
9
9
|
p.email = "adam@arcath.net"
|
10
10
|
p.ignore_pattern= ["tmp/*", "scripts/*"]
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class TBBC
|
2
|
+
# Configures TBBC, loads a config file if present and the defaults
|
3
|
+
def conf(config)
|
4
|
+
@config = config || {}
|
5
|
+
load_config_from_defaults
|
6
|
+
if File.exist?("config/tbbc.rb")
|
7
|
+
load_config_from_file
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# Loads the users config file
|
14
|
+
def load_config_from_file
|
15
|
+
load 'config/tbbc.rb'
|
16
|
+
user_config
|
17
|
+
end
|
18
|
+
|
19
|
+
# Loads the default config.
|
20
|
+
#
|
21
|
+
# Is non-overiding so any config set by the user in thier own file remains.
|
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] ||= []
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class TBBC
|
2
|
+
|
3
|
+
def css(config = nil)
|
4
|
+
conf config
|
5
|
+
output=" <style type=\"text/css\">
|
6
|
+
.CodeRay {
|
7
|
+
background-color: #232323;
|
8
|
+
border: 1px solid black;
|
9
|
+
font-family: 'Courier New', 'Terminal', monospace;
|
10
|
+
color: #E6E0DB;
|
11
|
+
padding: 3px 5px;
|
12
|
+
overflow: auto;
|
13
|
+
font-size: 12px;
|
14
|
+
margin: 12px 0;
|
15
|
+
}
|
16
|
+
.CodeRay pre {
|
17
|
+
margin: 0px;
|
18
|
+
padding: 0px;
|
19
|
+
}
|
20
|
+
|
21
|
+
.CodeRay .an { #{@config[:syntax_highlighting_html]} } /* html attribute */
|
22
|
+
.CodeRay .c { #{@config[:syntax_highlighting_comment]} } /* comment */
|
23
|
+
.CodeRay .ch { #{@config[:syntax_highlighting_escaped]} } /* escaped character */
|
24
|
+
.CodeRay .cl { #{@config[:syntax_highlighting_class]} } /* class */
|
25
|
+
.CodeRay .co { #{@config[:syntax_highlighting_constant]} } /* constant */
|
26
|
+
.CodeRay .fl { #{@config[:syntax_highlighting_float]} } /* float */
|
27
|
+
.CodeRay .fu { #{@config[:syntax_highlighting_function]} } /* function */
|
28
|
+
.CodeRay .gv { #{@config[:syntax_highlighting_global]} } /* global variable */
|
29
|
+
.CodeRay .i { #{@config[:syntax_highlighting_integer]} } /* integer */
|
30
|
+
.CodeRay .il { #{@config[:syntax_highlighting_inline]} } /* inline code */
|
31
|
+
.CodeRay .iv { #{@config[:syntax_highlighting_instance]} } /* instance variable */
|
32
|
+
.CodeRay .pp { #{@config[:syntax_highlighting_doctype]} } /* doctype */
|
33
|
+
.CodeRay .r { #{@config[:syntax_highlighting_keyword]} } /* keyword */
|
34
|
+
.CodeRay .rx { #{@config[:syntax_highlighting_regex]} } /* regex */
|
35
|
+
.CodeRay .s { #{@config[:syntax_highlighting_string]} } /* string */
|
36
|
+
.CodeRay .sy { #{@config[:syntax_highlighting_symbol]} } /* symbol */
|
37
|
+
.CodeRay .ta { #{@config[:syntax_highlighting_html]} } /* html tag */
|
38
|
+
.CodeRay .pc { #{@config[:syntax_highlighting_boolean]} } /* boolean */
|
39
|
+
</style>"
|
40
|
+
return output
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class TBBC
|
2
|
+
# Parses the input and returns it in tbbc form.
|
3
|
+
#
|
4
|
+
# TBBC.new.parse("[b]Bold[/b]")
|
5
|
+
#
|
6
|
+
# Would return "<strong>Bold</strong>"
|
7
|
+
def parse(input)
|
8
|
+
#Remove the < and > which will disable all HTML
|
9
|
+
input=input.gsub("<","<").gsub(">",">") unless @config[:disable_html] == false
|
10
|
+
#CodeRay
|
11
|
+
input=coderay(input) unless @config[:syntax_highlighting] == false
|
12
|
+
#Convert new lines to <br />'s
|
13
|
+
input=input.gsub(/\n/,'<br />') unless @config[:newline_enabled] == false
|
14
|
+
#[nobbc] tags
|
15
|
+
input=nobbc input unless @config[:nobbc_enabled] == false
|
16
|
+
#Swear Filtering
|
17
|
+
input=swear_filter(input) unless @config[:swear_filter_enabled] == false
|
18
|
+
#Loading Custom Tags
|
19
|
+
begin
|
20
|
+
if @config[:custom_tags] then
|
21
|
+
@config[:custom_tags].each do |tag|
|
22
|
+
input=runtag(input,tag)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
rescue
|
26
|
+
input+="<br />Custom Tags failed to run"
|
27
|
+
end
|
28
|
+
#Loading Default Tags and applying them
|
29
|
+
if @config[:allow_defaults] then
|
30
|
+
TBBC::Tags.each do |tag|
|
31
|
+
input=runtag(input,tag)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
input=correctbrs input
|
35
|
+
return input
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class String
|
2
|
+
# Allows for "[b]Bold[/b]".tbbc
|
3
|
+
#
|
4
|
+
# This method is also configurable, taking the normal configuration options.
|
5
|
+
#
|
6
|
+
# "[b]Bold [i]and italic[/i][/b]".tbbc(:strong_enabled => false, :italic_enabled => false)
|
7
|
+
#
|
8
|
+
# Will return "[b]Bold [i]and italic[/i][/b]"
|
9
|
+
def tbbc(conf = nil)
|
10
|
+
bbc=TBBC.new
|
11
|
+
bbc.conf(conf) if conf
|
12
|
+
bbc.parse(self)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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]]
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Runs the given tag array on the given string.
|
28
|
+
def runtag(s,tag)
|
29
|
+
check = tag[2]
|
30
|
+
check = @config[tag[2]] if is_symbol? tag[2]
|
31
|
+
s=s.gsub(tag[0],replace_config_values(tag[1])) unless check == false
|
32
|
+
s
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_symbol?(v)
|
36
|
+
v == v.to_sym
|
37
|
+
end
|
38
|
+
|
39
|
+
def replace_config_values(s)
|
40
|
+
if s.scan(/@config\[:(.*?)\]/) != [] then
|
41
|
+
return s.gsub(/@config\[:(.*?)\]/,@config[$1.to_sym])
|
42
|
+
else
|
43
|
+
return s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/trainbbcode.rb
CHANGED
@@ -1,109 +1,26 @@
|
|
1
|
+
require 'trainbbcode/parse.rb'
|
2
|
+
require 'trainbbcode/tags.rb'
|
3
|
+
require 'trainbbcode/configure.rb'
|
4
|
+
require 'trainbbcode/string.rb'
|
5
|
+
require 'trainbbcode/css.rb'
|
6
|
+
require 'trainbbcode/swear_filter.rb'
|
7
|
+
require 'rubygems'
|
8
|
+
require 'coderay'
|
9
|
+
|
10
|
+
#Helper Method
|
11
|
+
require 'trainbbcode/application_helper.rb'
|
12
|
+
ActionView::Base.send :include, TBBCHelper
|
13
|
+
|
1
14
|
class TBBC
|
15
|
+
# Creates a new TBBC class with everything set to default
|
16
|
+
#
|
17
|
+
# Also sets :configed_by to "system"
|
2
18
|
def initialize
|
3
19
|
self.conf(:configed_by => "system")
|
4
|
-
@securitykey="#{Time.now.to_i}"
|
5
|
-
end
|
6
|
-
def conf(config)
|
7
|
-
require 'rubygems'
|
8
|
-
require 'coderay'
|
9
|
-
config[:configed_by] ||= "user"
|
10
|
-
config[:image_alt] ||= "Posted Image"
|
11
|
-
config[:url_target] ||= "_BLANK"
|
12
|
-
config[:allow_defaults] ||= true
|
13
|
-
config[:table_width] ||= "100%"
|
14
|
-
config[:syntax_highlighting] ||= true
|
15
|
-
config[:syntax_highlighting_html] ||= "color: #E7BE69"
|
16
|
-
config[:syntax_highlighting_comment] ||= "color:#BC9358; font-style: italic;"
|
17
|
-
config[:syntax_highlighting_escaped] ||= "color:#509E4F"
|
18
|
-
config[:syntax_highlighting_class] ||= "color:#FFF"
|
19
|
-
config[:syntax_highlighting_constant] ||= "color:#FFF"
|
20
|
-
config[:syntax_highlighting_float] ||= "color:#A4C260"
|
21
|
-
config[:syntax_highlighting_function] ||= "color:#FFC56D"
|
22
|
-
config[:syntax_highlighting_global] ||= "color:#D0CFFE"
|
23
|
-
config[:syntax_highlighting_integer] ||= "color:#A4C260"
|
24
|
-
config[:syntax_highlighting_inline] ||= "background:#151515"
|
25
|
-
config[:syntax_highlighting_instance] ||= "color:#D0CFFE"
|
26
|
-
config[:syntax_highlighting_doctype] ||= "color:#E7BE69"
|
27
|
-
config[:syntax_highlighting_keyword] ||= "color:#CB7832"
|
28
|
-
config[:syntax_highlighting_regex] ||= "color:#A4C260"
|
29
|
-
config[:syntax_highlighting_string] ||= "color:#A4C260"
|
30
|
-
config[:syntax_highlighting_symbol] ||= "color:#6C9CBD"
|
31
|
-
config[:syntax_highlighting_html] ||= "color:#E7BE69"
|
32
|
-
config[:syntax_highlighting_boolean] ||= "color:#6C9CBD"
|
33
|
-
config[:syntax_highlighting_line_numbers]||= :inline
|
34
|
-
#Instanize the config variable
|
35
|
-
@config=config
|
36
|
-
end
|
37
|
-
def parse(s)
|
38
|
-
#Remove the < and > which will disable all HTML
|
39
|
-
s=s.gsub("<","<").gsub(">",">") unless @config[:disable_html] == false
|
40
|
-
#CodeRay
|
41
|
-
s=coderay(s) unless @config[:syntax_highlighting] == false
|
42
|
-
#Convert new lines to <br />'s
|
43
|
-
s=s.gsub(/\n/,'<br />') unless @config[:newline_enabled] == false
|
44
|
-
#[nobbc] tags
|
45
|
-
s=nobbc s unless @config[:nobbc_enabled] == false
|
46
|
-
#Loading Custom Tags
|
47
|
-
begin
|
48
|
-
if @config[:custom_tags] then
|
49
|
-
@config[:custom_tags].each do |tag|
|
50
|
-
s=s.gsub(tag[0],tag[1]) unless tag[2] == false
|
51
|
-
end
|
52
|
-
end
|
53
|
-
rescue
|
54
|
-
s+="<br />Custom Tags failed to run"
|
55
|
-
end
|
56
|
-
#Loading Default Tags and applying them
|
57
|
-
if @config[:allow_defaults] then
|
58
|
-
tags=load_default_tags
|
59
|
-
tags.each do |tag|
|
60
|
-
s=s.gsub(tag[0],tag[1]) unless tag[2] == false
|
61
|
-
end
|
62
|
-
end
|
63
|
-
s=correctbrs s
|
64
|
-
return s
|
65
|
-
end
|
66
|
-
def load_default_tags
|
67
|
-
tags=[
|
68
|
-
#Bold
|
69
|
-
[/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>',@config[:strong_enabled]],
|
70
|
-
#Italic
|
71
|
-
[/\[i\](.*?)\[\/i\]/,'<i>\1</i>',@config[:italic_enabled]],
|
72
|
-
#Underline
|
73
|
-
[/\[u\](.*?)\[\/u\]/,'<u>\1</u>',@config[:underline_enabled]],
|
74
|
-
#Url
|
75
|
-
[/\[url\](.*?)\[\/url\]/,'<a href="\1" target="' + @config[:url_target] +'">\1</a>',@config[:url_enabled]],
|
76
|
-
[/\[url=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="' + @config[:url_target] + '">\2</a>',@config[:url_enabled]],
|
77
|
-
[/\[url=(.*?) target=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="\2">\3</a>',@config[:url_enabled]],
|
78
|
-
#Image
|
79
|
-
[/\[img\](.*?)\[\/img\]/,'<img src="\1" alt="'+ @config[:image_alt] + '" />',@config[:image_enabled]],
|
80
|
-
[/\[img alt=(.*?)\](.*?)\[\/img\]/,'<img src="\2" alt="\1" />',@config[:image_enabled]],
|
81
|
-
#Un-Ordered List
|
82
|
-
[/\[ul\](.*?)\[\/ul\]/,'<ul>\1</ul>',@config[:list_enabled]],
|
83
|
-
#Ordered List
|
84
|
-
[/\[ol\](.*?)\[\/ol\]/,'<ol>\1</ol>',@config[:list_enabled]],
|
85
|
-
#List Item
|
86
|
-
[/\[li\](.*?)\[\/li\]/,'<li>\1</li>',@config[:list_enabled]],
|
87
|
-
#Quote
|
88
|
-
[/\[quote\](.*?)\[\/quote\]/,'<blockquote>\1</blockquote>',@config[:quote_enabled]],
|
89
|
-
[/\[quote=(.*?)\](.*?)\[\/quote\]/,'<blockquote><i>Posted by <b>\1</b></i><br />\2</blockquote>',@config[:quote_enabled]],
|
90
|
-
#Color
|
91
|
-
[/\[color=(.*?)\](.*?)\[\/color\]/,'<span style="color:\1;">\2</span>',@config[:color_enabled]],
|
92
|
-
#Alignment
|
93
|
-
[/\[center\](.*?)\[\/center\]/,'<div style="text-align:center">\1</div>',@config[:alignment_enabled]],
|
94
|
-
[/\[left\](.*?)\[\/left\]/,'<div style="text-align:left">\1</div>',@config[:alignment_enabled]],
|
95
|
-
[/\[right\](.*?)\[\/right\]/,'<div style="text-align:right">\1</div>',@config[:alignment_enabled]],
|
96
|
-
#Acronym
|
97
|
-
[/\[acronym=(.*?)\](.*?)\[\/acronym\]/,'<acronym title="\1">\2</acronym>',@config[:acronym_enabled]],
|
98
|
-
#Tables
|
99
|
-
#Table Tag
|
100
|
-
[/\[table\](.*?)\[\/table\]/,'<table width="' + @config[:table_width]+ '">\1</table>',@config[:table_enabled]],
|
101
|
-
#Table Elements
|
102
|
-
[/\[tr\](.*?)\[\/tr\]/,'<tr>\1</tr>',@config[:table_enabled]],
|
103
|
-
[/\[td\](.*?)\[\/td\]/,'<td>\1</td>',@config[:table_enabled]],
|
104
|
-
[/\[th\](.*?)\[\/th\]/,'<th>\1</th>',@config[:table_enabled]]
|
105
|
-
]
|
106
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
107
24
|
def nobbc(s)
|
108
25
|
find=s.scan(/\[nobbc\](.*?)\[\/nobbc\]/)
|
109
26
|
find.each do |f|
|
@@ -112,67 +29,23 @@ class TBBC
|
|
112
29
|
end
|
113
30
|
return s
|
114
31
|
end
|
115
|
-
|
116
|
-
output="<style type=\"text/css\">
|
117
|
-
.CodeRay {
|
118
|
-
background-color: #232323;
|
119
|
-
border: 1px solid black;
|
120
|
-
font-family: 'Courier New', 'Terminal', monospace;
|
121
|
-
color: #E6E0DB;
|
122
|
-
padding: 3px 5px;
|
123
|
-
overflow: auto;
|
124
|
-
font-size: 12px;
|
125
|
-
margin: 12px 0;
|
126
|
-
}
|
127
|
-
.CodeRay pre {
|
128
|
-
margin: 0px;
|
129
|
-
padding: 0px;
|
130
|
-
}
|
131
|
-
|
132
|
-
.CodeRay .an { #{@config[:syntax_highlighting_html]} } /* html attribute */
|
133
|
-
.CodeRay .c { #{@config[:syntax_highlighting_comment]} } /* comment */
|
134
|
-
.CodeRay .ch { #{@config[:syntax_highlighting_escaped]} } /* escaped character */
|
135
|
-
.CodeRay .cl { #{@config[:syntax_highlighting_class]} } /* class */
|
136
|
-
.CodeRay .co { #{@config[:syntax_highlighting_constant]} } /* constant */
|
137
|
-
.CodeRay .fl { #{@config[:syntax_highlighting_float]} } /* float */
|
138
|
-
.CodeRay .fu { #{@config[:syntax_highlighting_function]} } /* function */
|
139
|
-
.CodeRay .gv { #{@config[:syntax_highlighting_global]} } /* global variable */
|
140
|
-
.CodeRay .i { #{@config[:syntax_highlighting_integer]} } /* integer */
|
141
|
-
.CodeRay .il { #{@config[:syntax_highlighting_inline]} } /* inline code */
|
142
|
-
.CodeRay .iv { #{@config[:syntax_highlighting_instance]} } /* instance variable */
|
143
|
-
.CodeRay .pp { #{@config[:syntax_highlighting_doctype]} } /* doctype */
|
144
|
-
.CodeRay .r { #{@config[:syntax_highlighting_keyword]} } /* keyword */
|
145
|
-
.CodeRay .rx { #{@config[:syntax_highlighting_regex]} } /* regex */
|
146
|
-
.CodeRay .s { #{@config[:syntax_highlighting_string]} } /* string */
|
147
|
-
.CodeRay .sy { #{@config[:syntax_highlighting_symbol]} } /* symbol */
|
148
|
-
.CodeRay .ta { #{@config[:syntax_highlighting_html]} } /* html tag */
|
149
|
-
.CodeRay .pc { #{@config[:syntax_highlighting_boolean]} } /* boolean */
|
150
|
-
</style>"
|
151
|
-
return output
|
152
|
-
end
|
32
|
+
|
153
33
|
def correctbrs(s)
|
154
34
|
#Corrects the extra brs
|
155
35
|
s=s.gsub(/<br \/><(ul|li|table|tr|td|th)/,'<\1')
|
156
36
|
s=s.gsub(/<br \/><\/(ul|li|table|tr|td|th)/,'</\1')
|
157
37
|
end
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
scan.
|
162
|
-
|
163
|
-
|
38
|
+
|
39
|
+
def coderay(input)
|
40
|
+
input=input.gsub("\r","")
|
41
|
+
scan=input.scan(/\[code lang=(.+?)\](.+?)\[\/code\]/m)
|
42
|
+
scan.each do |splits|
|
43
|
+
parse=splits[1].gsub("<","<").gsub(">",">")
|
44
|
+
lang=splits[0]
|
164
45
|
parsed="[nobbc]" + CodeRay.scan(parse, lang).div(:css => :class, :line_numbers => @config[:syntax_highlighting_line_numbers]) + "[/nobbc]"
|
165
|
-
|
46
|
+
input=input.gsub("[code lang=#{lang}]#{splits[1]}[/code]",parsed)
|
166
47
|
end
|
167
|
-
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
#Add .tbbc to Strings
|
172
|
-
class String
|
173
|
-
def tbbc(conf = nil)
|
174
|
-
bbc=TBBC.new
|
175
|
-
bbc.conf(conf) if conf
|
176
|
-
bbc.parse(self)
|
48
|
+
input
|
177
49
|
end
|
50
|
+
|
178
51
|
end
|
data/trainbbcode.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{trainbbcode}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "1.0.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Adam \"Arcath\" Laycock"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-07-06}
|
10
10
|
s.description = %q{Provides BBCode for Ruby.}
|
11
11
|
s.email = %q{adam@arcath.net}
|
12
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/trainbbcode.rb"]
|
13
|
-
s.files = ["
|
14
|
-
s.homepage = %q{http://www.arcath.net/
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/trainbbcode.rb", "lib/trainbbcode/configure.rb", "lib/trainbbcode/css.rb", "lib/trainbbcode/parse.rb", "lib/trainbbcode/string.rb", "lib/trainbbcode/tags.rb"]
|
13
|
+
s.files = ["README.rdoc", "Rakefile", "init.rb", "lib/trainbbcode.rb", "lib/trainbbcode/configure.rb", "lib/trainbbcode/css.rb", "lib/trainbbcode/parse.rb", "lib/trainbbcode/string.rb", "lib/trainbbcode/tags.rb", "Manifest", "trainbbcode.gemspec"]
|
14
|
+
s.homepage = %q{http://www.arcath.net/}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trainbbcode", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{trainbbcode}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trainbbcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam "Arcath" Laycock
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-07-06 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -31,15 +31,25 @@ extensions: []
|
|
31
31
|
extra_rdoc_files:
|
32
32
|
- README.rdoc
|
33
33
|
- lib/trainbbcode.rb
|
34
|
+
- lib/trainbbcode/configure.rb
|
35
|
+
- lib/trainbbcode/css.rb
|
36
|
+
- lib/trainbbcode/parse.rb
|
37
|
+
- lib/trainbbcode/string.rb
|
38
|
+
- lib/trainbbcode/tags.rb
|
34
39
|
files:
|
35
|
-
- Manifest
|
36
40
|
- README.rdoc
|
37
41
|
- Rakefile
|
38
42
|
- init.rb
|
39
43
|
- lib/trainbbcode.rb
|
44
|
+
- lib/trainbbcode/configure.rb
|
45
|
+
- lib/trainbbcode/css.rb
|
46
|
+
- lib/trainbbcode/parse.rb
|
47
|
+
- lib/trainbbcode/string.rb
|
48
|
+
- lib/trainbbcode/tags.rb
|
49
|
+
- Manifest
|
40
50
|
- trainbbcode.gemspec
|
41
51
|
has_rdoc: true
|
42
|
-
homepage: http://www.arcath.net/
|
52
|
+
homepage: http://www.arcath.net/
|
43
53
|
licenses: []
|
44
54
|
|
45
55
|
post_install_message:
|