trainbbcode 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest +0 -1
- data/README.rdoc +25 -5
- data/Rakefile +1 -1
- data/lib/trainbbcode.rb +47 -7
- data/trainbbcode.gemspec +2 -2
- metadata +2 -2
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -14,6 +14,19 @@ config.gem "trainbbcode"
|
|
14
14
|
|
15
15
|
to config/enviroments.rb
|
16
16
|
|
17
|
+
== Optional Requirements
|
18
|
+
|
19
|
+
=== Ultraviolet
|
20
|
+
|
21
|
+
If you want to use syntax highlighting you will need to install the "ultraviolet" gem
|
22
|
+
|
23
|
+
Once you have the gem installed you will need to run:
|
24
|
+
|
25
|
+
uv -s ruby --copy-files css
|
26
|
+
gief css filez
|
27
|
+
|
28
|
+
|
29
|
+
|
17
30
|
== Usage
|
18
31
|
|
19
32
|
This adds a method to string of .tbbc which lets you parse the code like this:
|
@@ -34,15 +47,18 @@ This would output:
|
|
34
47
|
|
35
48
|
"[b]bold text[/b] and <i>italic</i>"
|
36
49
|
|
37
|
-
|
50
|
+
=== Options
|
38
51
|
|
39
|
-
:url_target
|
40
|
-
:image_alt
|
41
|
-
:allow_defaults
|
52
|
+
:url_target can be set to anything valid for a link target.
|
53
|
+
:image_alt the default value for the alt attribute in images
|
54
|
+
:allow_defaults if set to false the default tags (see Tags) will be disabled
|
55
|
+
:disable_html if set to false < and > will not be removed, all HTML will be allowed
|
56
|
+
:newline_enabled if set to false \n wont be turned into html breaks
|
57
|
+
:syntax_highlighting if set to false (or if the gem isnt installed) syntax highlighting will not be used
|
42
58
|
|
43
59
|
:TAG_enabled set for each tag in use e.g. :italic_enabled, it can be set to false to disable the tag
|
44
60
|
|
45
|
-
|
61
|
+
=== Adding Custom Tags
|
46
62
|
|
47
63
|
:custom_tags is used to define custom tags. you pass an array of tag arrays, the bold tag would be added like this:
|
48
64
|
|
@@ -52,6 +68,10 @@ The tag array is formatted like this:
|
|
52
68
|
|
53
69
|
[REGEX_PATTERN,HTML,ENABLED]
|
54
70
|
|
71
|
+
=== Adding the CSS
|
72
|
+
|
73
|
+
call the css method
|
74
|
+
|
55
75
|
== Tags
|
56
76
|
|
57
77
|
=== Standard
|
data/Rakefile
CHANGED
data/lib/trainbbcode.rb
CHANGED
@@ -3,6 +3,16 @@ class TBBC
|
|
3
3
|
self.conf(:configed_by => "system")
|
4
4
|
end
|
5
5
|
def conf(config)
|
6
|
+
require 'rubygems'
|
7
|
+
begin
|
8
|
+
require 'uv'
|
9
|
+
#UV Settings
|
10
|
+
config[:syntax_output] ||= "html"
|
11
|
+
config[:syntax_line_numbers] ||= true
|
12
|
+
config[:syntax_theme] ||= "twilight"
|
13
|
+
rescue LoadError
|
14
|
+
config[:syntax_highlighting]=false
|
15
|
+
end
|
6
16
|
config[:configed_by] ||= "user"
|
7
17
|
config[:image_alt] ||= "Posted Image"
|
8
18
|
config[:url_target] ||= "_BLANK"
|
@@ -11,19 +21,27 @@ class TBBC
|
|
11
21
|
@config=config
|
12
22
|
end
|
13
23
|
def parse(s)
|
14
|
-
#
|
15
|
-
|
24
|
+
#Run the UV Parser (if enabled) to sort out any code
|
25
|
+
unless @config[:syntax_highlighting] == false
|
26
|
+
s=uv s
|
27
|
+
end
|
28
|
+
#Remove the < and > which will disable all HTML
|
29
|
+
s=s.gsub("<","<").gsub(">",">") unless @config[:disable_html] == false
|
16
30
|
#Convert new lines to <br />'s
|
17
|
-
s=s.gsub(/\n/,'<br />')
|
31
|
+
s=s.gsub(/\n/,'<br />') unless @config[:newline_enabled] == false
|
18
32
|
#[nobbc] tags
|
19
33
|
unless @config[:nobbc_enabled] == false
|
20
34
|
s=nobbc s
|
21
35
|
end
|
22
36
|
#Loading Custom Tags
|
23
|
-
|
24
|
-
@config[:custom_tags]
|
25
|
-
|
37
|
+
begin
|
38
|
+
if @config[:custom_tags] then
|
39
|
+
@config[:custom_tags].each do |tag|
|
40
|
+
s=s.gsub(tag[0],tag[1]) unless tag[2] == false
|
41
|
+
end
|
26
42
|
end
|
43
|
+
rescue
|
44
|
+
s+="<br />Custom Tags failed to run"
|
27
45
|
end
|
28
46
|
#Loading Default Tags and applying them
|
29
47
|
if @config[:allow_defaults] then
|
@@ -53,7 +71,12 @@ class TBBC
|
|
53
71
|
#Ordered List
|
54
72
|
[/\[ol\](.*?)\[\/ol\]/,'<ol>\1</ol>',@config[:list_enabled]],
|
55
73
|
#List Item
|
56
|
-
[/\[li\](.*?)\[\/li\]/,'<li>\1</li>',@config[:list_enabled]]
|
74
|
+
[/\[li\](.*?)\[\/li\]/,'<li>\1</li>',@config[:list_enabled]],
|
75
|
+
#Quote
|
76
|
+
[/\[quote\](.*?)\[\/quote\]/,'<blockquote>\1</blockquote>',@config[:quote_enabled]],
|
77
|
+
[/\[quote=(.*?)\](.*?)\[\/quote\]/,'<blockquote><i>Posted by <b>\1</b></i><br />\2</blockquote>',@config[:quote_enabled]],
|
78
|
+
#Color
|
79
|
+
[/\[color=(.*?)\](.*?)\[\/color\]/,'<span style="color:\1;">\2</span>',@config[:color_enabled]]
|
57
80
|
]
|
58
81
|
end
|
59
82
|
def nobbc(s)
|
@@ -65,6 +88,23 @@ class TBBC
|
|
65
88
|
s=s.gsub("[nobbc]","").gsub("[/nobbc]","")
|
66
89
|
return s
|
67
90
|
end
|
91
|
+
def css
|
92
|
+
output="<style type=\"text/css\">
|
93
|
+
blockquote{
|
94
|
+
|
95
|
+
}
|
96
|
+
</style>"
|
97
|
+
output+=Uv.themes.map{|theme| %Q(<link rel="stylesheet" type="text/css" href="css/#{theme}.css" />\n)}
|
98
|
+
return output
|
99
|
+
end
|
100
|
+
def uv(s)
|
101
|
+
find=s.scan(/\[code lang=(.*?)\](.*?)\[\/code\]/)
|
102
|
+
finde.each do |f|
|
103
|
+
r=Uv.parse(f[1], @config[:syntax_output], f[0], @config[:syntax_line_numbers], @config[:syntax_theme])
|
104
|
+
end
|
105
|
+
s=s.gsub(/\[code lang=(.*?)\]/,'').gsub("[/code]",'')
|
106
|
+
return s
|
107
|
+
end
|
68
108
|
end
|
69
109
|
|
70
110
|
#Add .tbbc to Strings
|
data/trainbbcode.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{trainbbcode}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.2"
|
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{2009-12-
|
9
|
+
s.date = %q{2009-12-27}
|
10
10
|
s.description = %q{Provides BBCode for Ruby.}
|
11
11
|
s.email = %q{adam@arcath.net}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "lib/trainbbcode.rb"]
|
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.2.
|
4
|
+
version: 0.2.2
|
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: 2009-12-
|
12
|
+
date: 2009-12-27 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|