trainbbcode 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -18,8 +18,36 @@ to config/enviroments.rb
18
18
 
19
19
  This adds a method to string of .tbbc which lets you parse the code like this:
20
20
 
21
- "[b]bold text[/b] and [i]italic[/i]".tbbc
21
+ "[b]bold text[/b] and [i]italic[/i]".tbbc
22
22
 
23
23
  that would output:
24
24
 
25
- "<strong>bold text</strong> and <i>italic</i>"
25
+ "<strong>bold text</strong> and <i>italic</i>"
26
+
27
+ Or you can configure it by creating a TBBC object and running "conf"
28
+
29
+ tbbc=TBBC.new
30
+ tbbc.config(:strong_enabled => false)
31
+ tbbc.parse("[b]bold text[/b] and [i]italic[/i]")
32
+
33
+ This would output:
34
+
35
+ "[b]bold text[/b] and <i>italic</i>"
36
+
37
+ == Options
38
+
39
+ :url_target can be set to anything valid for a link target.
40
+ :image_alt the default value for the alt attribute in images
41
+
42
+ :TAG_enabled set for each tag in use e.g. :italic_enabled, it can be set to false to disable the tag
43
+
44
+ == Adding Custom Tags
45
+
46
+ :custom_tags is used to define custom tags. you pass an array of tag arrays, the bold tag would be added like this:
47
+
48
+ :custom_tags => [[/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>',true]]
49
+
50
+ The tag array is formatted like this:
51
+
52
+ [REGEX_PATTERN,HTML,ENABLED]
53
+
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('trainbbcode','0.1.1') do |p|
5
+ Echoe.new('trainbbcode','0.2.0') do |p|
6
6
  p.description = "Provides BBCode for Ruby."
7
7
  p.url = "http://www.arcath.net"
8
8
  p.author = "Adam \"Arcath\" Laycock"
data/lib/trainbbcode.rb CHANGED
@@ -1,18 +1,44 @@
1
1
  class TBBC
2
+ def initialize
3
+ self.conf(:configed_by => "system")
4
+ end
5
+ def conf(config)
6
+ config[:configed_by] ||= "user"
7
+ config[:image_alt] ||= "Posted Image"
8
+ config[:url_target] ||= "_BLANK"
9
+
10
+ @config=config
11
+ end
2
12
  def parse(s)
3
13
  #First off remove the < and > which will disable all HTML
4
14
  s=s.gsub("<","&lt;").gsub(">","&gt;")
5
15
  #Convert new lines to <br />'s
6
16
  s=s.gsub(/\n/,'<br />')
7
- #Tags
8
- s=s.gsub(/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>')
9
- s=s.gsub(/\[i\](.*?)\[\/b\]/,'<i>\1</i>')
10
- s=s.gsub(/\[u\](.*?)\[\/u\]/,'<u>\1</u>')
11
- s=s.gsub(/\[url\](.*?)\[\/url\]/,'<a href="\1" target="_BLANK">\1</a>')
12
- s=s.gsub(/\[url=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="_BLANK">\2</a>')
17
+ #Loading Custom Tags
18
+ if @config[:custom_tags] then
19
+ @config[:custom_tags].each do |tag|
20
+ s=s.gsub(tag[0],tag[1]) unless tag[2] == false
21
+ end
22
+ end
23
+ #Loading Default Tags and applying them
24
+ tags=load_default_tags
25
+ tags.each do |tag|
26
+ s=s.gsub(tag[0],tag[1]) unless tag[2] == false
27
+ end
13
28
 
14
29
  return s
15
30
  end
31
+ def load_default_tags
32
+ tags=[
33
+ [/\[b\](.*?)\[\/b\]/,'<strong>\1</strong>',@config[:strong_enabled]],
34
+ [/\[i\](.*?)\[\/i\]/,'<i>\1</i>',@config[:italic_enabled]],
35
+ [/\[u\](.*?)\[\/u\]/,'<u>\1</u>',@config[:underline_enabled]],
36
+ [/\[url\](.*?)\[\/url\]/,'<a href="\1" target="' + @config[:url_target] +'">\1</a>',@config[:url_enabled]],
37
+ [/\[url=(.*?)\](.*?)\[\/url\]/,'<a href="\1" target="' + @config[:url_target] + '">\2</a>',@config[:url_enabled]],
38
+ [/\[img\](.*?)\[\/img\]/,'<img src="\1" alt="'+ @config[:image_alt] + '" />',@config[:image_enabled]],
39
+ [/\[img alt=(.*?)\](.*?)\[\/img\]/,'<img src="\2" alt="\1" />',@config[:image_enabled]]
40
+ ]
41
+ end
16
42
  end
17
43
 
18
44
  class String
data/trainbbcode.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{trainbbcode}
5
- s.version = "0.1.1"
5
+ s.version = "0.2.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{2009-12-06}
9
+ s.date = %q{2009-12-07}
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"]
13
- s.files = ["README.rdoc", "Rakefile", "lib/trainbbcode.rb", "Manifest", "trainbbcode.gemspec"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/trainbbcode.rb", "trainbbcode.gemspec"]
14
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"]
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.1.1
4
+ version: 0.2.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: 2009-12-06 00:00:00 +00:00
12
+ date: 2009-12-07 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,10 +23,10 @@ extra_rdoc_files:
23
23
  - README.rdoc
24
24
  - lib/trainbbcode.rb
25
25
  files:
26
+ - Manifest
26
27
  - README.rdoc
27
28
  - Rakefile
28
29
  - lib/trainbbcode.rb
29
- - Manifest
30
30
  - trainbbcode.gemspec
31
31
  has_rdoc: true
32
32
  homepage: http://www.arcath.net