trainbbcode 0.2.0 → 0.2.1
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/README.rdoc +32 -0
- data/Rakefile +1 -1
- data/lib/trainbbcode.rb +34 -7
- data/trainbbcode.gemspec +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -38,6 +38,7 @@ This would output:
|
|
38
38
|
|
39
39
|
:url_target can be set to anything valid for a link target.
|
40
40
|
:image_alt the default value for the alt attribute in images
|
41
|
+
:allow_defaults Can be used to diable the default tags and only use your custom ones
|
41
42
|
|
42
43
|
:TAG_enabled set for each tag in use e.g. :italic_enabled, it can be set to false to disable the tag
|
43
44
|
|
@@ -51,3 +52,34 @@ The tag array is formatted like this:
|
|
51
52
|
|
52
53
|
[REGEX_PATTERN,HTML,ENABLED]
|
53
54
|
|
55
|
+
== Tags
|
56
|
+
|
57
|
+
=== Standard
|
58
|
+
|
59
|
+
[b]BOLD[/b] => <strong>BOLD</strong>
|
60
|
+
[i]ITALICS[/i] => <i>ITALICS</i>
|
61
|
+
[u]UNDERLINE[/u] => <u>UNDERLINE</u>
|
62
|
+
[url=http://example.com]example[/url] => <a href="http://example.com" target="YOURDEFAULT">example</a>
|
63
|
+
[url]http://example.com[/url] => <a href="http://example.com" target="YOURDEFAULT">http://example.com</a>
|
64
|
+
[img]http://example.com/test.jpg[/img] => <img src="http://example.com/test.jpg" alt="DEAFULTALT" />
|
65
|
+
[img alt=Test]http://example.com/test.jpg[/img] => <img src="http://example.com/test.jpg" alt="Test" />
|
66
|
+
|
67
|
+
=== Block
|
68
|
+
|
69
|
+
[ul]
|
70
|
+
[li]Test[/li]
|
71
|
+
[li]Test2[/li]
|
72
|
+
[/ul]
|
73
|
+
|
74
|
+
becomes
|
75
|
+
|
76
|
+
<ul>
|
77
|
+
<li>Test</li>
|
78
|
+
<li>Test2</li>
|
79
|
+
</ul>
|
80
|
+
|
81
|
+
same applies for [ol]
|
82
|
+
|
83
|
+
=== Special
|
84
|
+
|
85
|
+
[nobbc][b]BOLD[/b][/nobbc] => [b]BOLD[/b] (using the char codes for [ and ])
|
data/Rakefile
CHANGED
data/lib/trainbbcode.rb
CHANGED
@@ -6,7 +6,8 @@ class TBBC
|
|
6
6
|
config[:configed_by] ||= "user"
|
7
7
|
config[:image_alt] ||= "Posted Image"
|
8
8
|
config[:url_target] ||= "_BLANK"
|
9
|
-
|
9
|
+
config[:allow_defaults] ||= true
|
10
|
+
#Instanize the config variable
|
10
11
|
@config=config
|
11
12
|
end
|
12
13
|
def parse(s)
|
@@ -14,6 +15,10 @@ class TBBC
|
|
14
15
|
s=s.gsub("<","<").gsub(">",">")
|
15
16
|
#Convert new lines to <br />'s
|
16
17
|
s=s.gsub(/\n/,'<br />')
|
18
|
+
#[nobbc] tags
|
19
|
+
unless @config[:nobbc_enabled] == false
|
20
|
+
s=nobbc s
|
21
|
+
end
|
17
22
|
#Loading Custom Tags
|
18
23
|
if @config[:custom_tags] then
|
19
24
|
@config[:custom_tags].each do |tag|
|
@@ -21,26 +26,48 @@ class TBBC
|
|
21
26
|
end
|
22
27
|
end
|
23
28
|
#Loading Default Tags and applying them
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
if @config[:allow_defaults] then
|
30
|
+
tags=load_default_tags
|
31
|
+
tags.each do |tag|
|
32
|
+
s=s.gsub(tag[0],tag[1]) unless tag[2] == false
|
33
|
+
end
|
34
|
+
end
|
29
35
|
return s
|
30
36
|
end
|
31
37
|
def load_default_tags
|
32
38
|
tags=[
|
39
|
+
#Bold
|
33
40
|
[/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>',@config[:strong_enabled]],
|
41
|
+
#Italic
|
34
42
|
[/\[i\](.*?)\[\/i\]/,'<i>\1</i>',@config[:italic_enabled]],
|
43
|
+
#Underline
|
35
44
|
[/\[u\](.*?)\[\/u\]/,'<u>\1</u>',@config[:underline_enabled]],
|
45
|
+
#Url
|
36
46
|
[/\[url\](.*?)\[\/url\]/,'<a href="\1" target="' + @config[:url_target] +'">\1</a>',@config[:url_enabled]],
|
37
47
|
[/\[url=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="' + @config[:url_target] + '">\2</a>',@config[:url_enabled]],
|
48
|
+
#Image
|
38
49
|
[/\[img\](.*?)\[\/img\]/,'<img src="\1" alt="'+ @config[:image_alt] + '" />',@config[:image_enabled]],
|
39
|
-
[/\[img alt=(.*?)\](.*?)\[\/img\]/,'<img src="\2" alt="\1" />',@config[:image_enabled]]
|
50
|
+
[/\[img alt=(.*?)\](.*?)\[\/img\]/,'<img src="\2" alt="\1" />',@config[:image_enabled]],
|
51
|
+
#Un-Ordered List
|
52
|
+
[/\[ul\](.*?)\[\/ul\]/,'<ul>\1</ul>',@config[:list_enabled]],
|
53
|
+
#Ordered List
|
54
|
+
[/\[ol\](.*?)\[\/ol\]/,'<ol>\1</ol>',@config[:list_enabled]],
|
55
|
+
#List Item
|
56
|
+
[/\[li\](.*?)\[\/li\]/,'<li>\1</li>',@config[:list_enabled]]
|
40
57
|
]
|
41
58
|
end
|
59
|
+
def nobbc(s)
|
60
|
+
find=s.scan(/\[nobbc\](.*?)\[\/nobbc\]/)
|
61
|
+
find.each do |f|
|
62
|
+
replace=f[0].gsub("[","[").gsub("]","]")
|
63
|
+
s=s.gsub(f[0],replace)
|
64
|
+
end
|
65
|
+
s=s.gsub("[nobbc]","").gsub("[/nobbc]","")
|
66
|
+
return s
|
67
|
+
end
|
42
68
|
end
|
43
69
|
|
70
|
+
#Add .tbbc to Strings
|
44
71
|
class String
|
45
72
|
def tbbc
|
46
73
|
bbc=TBBC.new
|
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.1"
|
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-08}
|
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.1
|
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-08 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|