trainbbcode 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ Manifest
3
+ *.gem
4
+ *~
5
+ tmp/*
6
+ *.bundle
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lorem.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ TrainBBCode (1.0.1)
5
+ coderay
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ coderay (0.9.6)
11
+ diff-lcs (1.1.2)
12
+ rspec (2.3.0)
13
+ rspec-core (~> 2.3.0)
14
+ rspec-expectations (~> 2.3.0)
15
+ rspec-mocks (~> 2.3.0)
16
+ rspec-core (2.3.1)
17
+ rspec-expectations (2.3.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.3.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ TrainBBCode!
26
+ coderay
27
+ rspec
data/Rakefile CHANGED
@@ -1,15 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
4
-
5
- Echoe.new('trainbbcode','1.0.1') do |p|
6
- p.description = "Provides BBCode for Ruby."
7
- p.url = "http://www.arcath.net/"
8
- p.author = "Adam \"Arcath\" Laycock"
9
- p.email = "adam@arcath.net"
10
- p.ignore_pattern= ["tmp/*", "scripts/*"]
11
- p.development_dependencies = []
12
- p.runtime_dependencies = ["coderay"]
13
- end
14
-
15
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lib/trainbbcode.rb CHANGED
@@ -8,7 +8,7 @@ require 'rubygems'
8
8
  require 'coderay'
9
9
 
10
10
  #Helper Method
11
- if defined? RAILS_ROOT then
11
+ if defined? Rails
12
12
  require 'trainbbcode/application_helper.rb'
13
13
  ActionView::Base.send :include, TBBCHelper
14
14
  end
@@ -44,10 +44,17 @@ class TBBC
44
44
  scan.each do |splits|
45
45
  parse=splits[1].gsub("&lt;","<").gsub("&gt;",">")
46
46
  lang=splits[0]
47
- parsed="[nobbc]" + CodeRay.scan(parse, lang).div(:css => :class, :line_numbers => @config[:syntax_highlighting_line_numbers]) + "[/nobbc]"
47
+ parsed="[nobbc]" + CodeRay.scan(parse, lang).div(:line_numbers => @config[:syntax_highlighting_line_numbers]) + "[/nobbc]"
48
48
  input=input.gsub("[code lang=#{lang}]#{splits[1]}[/code]",parsed)
49
49
  end
50
50
  input
51
51
  end
52
-
52
+
53
+ def needs_html_safe?
54
+ if defined? Rails
55
+ return Rails.version =~ /^3\./
56
+ else
57
+ return false
58
+ end
59
+ end
53
60
  end
@@ -1,5 +1,6 @@
1
1
  class TBBC
2
-
2
+
3
+ # Returns the css required for coderay
3
4
  def css(config = nil)
4
5
  conf config
5
6
  output=" <style type=\"text/css\">
@@ -37,6 +38,10 @@ class TBBC
37
38
  .CodeRay .ta { #{@config[:syntax_highlighting_html]} } /* html tag */
38
39
  .CodeRay .pc { #{@config[:syntax_highlighting_boolean]} } /* boolean */
39
40
  </style>"
40
- return output
41
+ if needs_html_safe? then
42
+ return output.html_safe
43
+ else
44
+ return output
45
+ end
41
46
  end
42
47
  end
@@ -32,6 +32,10 @@ class TBBC
32
32
  end
33
33
  end
34
34
  input=correctbrs input
35
- return input
35
+ if needs_html_safe? then
36
+ return input.html_safe
37
+ else
38
+ return input
39
+ end
36
40
  end
37
41
  end
@@ -28,7 +28,12 @@ class TBBC
28
28
  def runtag(s,tag)
29
29
  check = tag[2]
30
30
  check = @config[tag[2]] if is_symbol? tag[2]
31
- s=s.gsub(tag[0],replace_config_values(tag[1])) unless check == false
31
+ if tag[1] =~ /^Callback:/
32
+ s = run_callback(s, tag[0], tag[1])
33
+ else
34
+ pattern = tag[1]
35
+ s=s.gsub(tag[0],replace_config_values(pattern)) unless check == false
36
+ end
32
37
  s
33
38
  end
34
39
 
@@ -44,4 +49,21 @@ class TBBC
44
49
  return s
45
50
  end
46
51
  end
52
+
53
+ def run_callback(string, regex, callback)
54
+ code = callback.gsub(/^Callback: /, '')
55
+ output = string
56
+ string.scan(regex).each do |arguments|
57
+ arguments_pass = build_pass_string(arguments)
58
+ replace = eval "#{code}#{arguments_pass}"
59
+ output = output.sub(regex, replace)
60
+ end
61
+ output
62
+ end
63
+
64
+ def build_pass_string(args)
65
+ output = "("
66
+ args.map { |arg| output = "#{output}\"#{arg}\", " }
67
+ output.gsub(/, $/,')')
68
+ end
47
69
  end
@@ -0,0 +1,3 @@
1
+ class TBBC
2
+ VERSION = "1.1.0"
3
+ end
@@ -1,5 +1,9 @@
1
1
  require 'lib/trainbbcode.rb'
2
2
 
3
+ def upcaser(input)
4
+ input.upcase
5
+ end
6
+
3
7
  describe TBBC, "#parse" do
4
8
  it "Should return <strong>BOLD</strong> for [b]BOLD[/b]" do
5
9
  TBBC.new.parse("[b]BOLD[/b]").should == "<strong>BOLD</strong>"
@@ -18,4 +22,16 @@ describe String, "#tbbc" do
18
22
  it "Should allow custom tags to run and return <strong><i>BOLD italics</i></strong> for [bi]BOLD italics[/bi]" do
19
23
  "[bi]BOLD italics[/bi]".tbbc(:custom_tags => [[/\[bi\](.*?)\[\/bi\]/,'<strong><i>\1</i></strong>',true]]).should == "<strong><i>BOLD italics</i></strong>"
20
24
  end
25
+
26
+ it "Should allow custom tags to pass to callbacks" do
27
+ "[up]HeLlo WorLd[/up]".tbbc(:custom_tags => [[/\[up\](.*?)\[\/up\]/,"Callback: upcaser",true]]).should == "HELLO WORLD"
28
+ end
29
+
30
+ it "Should not fail when a callback is defined but not used" do
31
+ "[dw]HeLlo WorLd[/dw]".tbbc(:custom_tags => [[/\[up\](.*?)\[\/up\]/,"Callback: upcaser",true]]).should == "[dw]HeLlo WorLd[/dw]"
32
+ end
33
+
34
+ it "Should allow for 2 identical callbacks per string" do
35
+ "[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
21
37
  end
data/trainbbcode.gemspec CHANGED
@@ -1,33 +1,21 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "trainbbcode/version"
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = %q{trainbbcode}
5
- s.version = "1.0.1"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Adam \"Arcath\" Laycock"]
9
- s.date = %q{2010-10-06}
10
- s.description = %q{Provides BBCode for Ruby.}
11
- s.email = %q{adam@arcath.net}
12
- s.extra_rdoc_files = ["README.rdoc", "lib/trainbbcode.rb", "lib/trainbbcode/application_helper.rb", "lib/trainbbcode/configure.rb", "lib/trainbbcode/css.rb", "lib/trainbbcode/parse.rb", "lib/trainbbcode/string.rb", "lib/trainbbcode/swear_filter.rb", "lib/trainbbcode/tags.rb"]
13
- s.files = ["README.rdoc", "Rakefile", "init.rb", "lib/trainbbcode.rb", "lib/trainbbcode/application_helper.rb", "lib/trainbbcode/configure.rb", "lib/trainbbcode/css.rb", "lib/trainbbcode/parse.rb", "lib/trainbbcode/string.rb", "lib/trainbbcode/swear_filter.rb", "lib/trainbbcode/tags.rb", "spec/trainbbcode_spec.rb", "trainbbcode.gemspec", "Manifest"]
14
- s.homepage = %q{http://www.arcath.net/}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trainbbcode", "--main", "README.rdoc"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{trainbbcode}
18
- s.rubygems_version = %q{1.3.5}
19
- s.summary = %q{Provides BBCode for Ruby.}
20
-
21
- if s.respond_to? :specification_version then
22
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
- s.specification_version = 3
24
-
25
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
- s.add_runtime_dependency(%q<coderay>, [">= 0"])
27
- else
28
- s.add_dependency(%q<coderay>, [">= 0"])
29
- end
30
- else
31
- s.add_dependency(%q<coderay>, [">= 0"])
32
- end
6
+ s.name = "trainbbcode"
7
+ s.version = TBBC::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Adam \"Arcath\" Laycock"]
10
+ s.email = ["gems@arcath.net"]
11
+ s.homepage = "http://www.arcath.net"
12
+ s.summary = "Provides BBCode for Ruby."
13
+
14
+ s.add_development_dependency "rspec"
15
+ s.add_dependency "coderay"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
33
21
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trainbbcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Adam "Arcath" Laycock
@@ -9,36 +15,50 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-10-06 00:00:00 +01:00
18
+ date: 2010-12-21 00:00:00 +00:00
13
19
  default_executable:
14
20
  dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
15
35
  - !ruby/object:Gem::Dependency
16
36
  name: coderay
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
20
40
  requirements:
21
41
  - - ">="
22
42
  - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
23
46
  version: "0"
24
- version:
25
- description: Provides BBCode for Ruby.
26
- email: adam@arcath.net
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description:
50
+ email:
51
+ - gems@arcath.net
27
52
  executables: []
28
53
 
29
54
  extensions: []
30
55
 
31
- extra_rdoc_files:
32
- - README.rdoc
33
- - lib/trainbbcode.rb
34
- - lib/trainbbcode/application_helper.rb
35
- - lib/trainbbcode/configure.rb
36
- - lib/trainbbcode/css.rb
37
- - lib/trainbbcode/parse.rb
38
- - lib/trainbbcode/string.rb
39
- - lib/trainbbcode/swear_filter.rb
40
- - lib/trainbbcode/tags.rb
56
+ extra_rdoc_files: []
57
+
41
58
  files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - Gemfile.lock
42
62
  - README.rdoc
43
63
  - Rakefile
44
64
  - init.rb
@@ -50,39 +70,40 @@ files:
50
70
  - lib/trainbbcode/string.rb
51
71
  - lib/trainbbcode/swear_filter.rb
52
72
  - lib/trainbbcode/tags.rb
73
+ - lib/trainbbcode/version.rb
53
74
  - spec/trainbbcode_spec.rb
54
75
  - trainbbcode.gemspec
55
- - Manifest
56
76
  has_rdoc: true
57
- homepage: http://www.arcath.net/
77
+ homepage: http://www.arcath.net
58
78
  licenses: []
59
79
 
60
80
  post_install_message:
61
- rdoc_options:
62
- - --line-numbers
63
- - --inline-source
64
- - --title
65
- - Trainbbcode
66
- - --main
67
- - README.rdoc
81
+ rdoc_options: []
82
+
68
83
  require_paths:
69
84
  - lib
70
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
71
87
  requirements:
72
88
  - - ">="
73
89
  - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
74
93
  version: "0"
75
- version:
76
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
77
96
  requirements:
78
97
  - - ">="
79
98
  - !ruby/object:Gem::Version
80
- version: "1.2"
81
- version:
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
82
103
  requirements: []
83
104
 
84
- rubyforge_project: trainbbcode
85
- rubygems_version: 1.3.5
105
+ rubyforge_project:
106
+ rubygems_version: 1.3.7
86
107
  signing_key:
87
108
  specification_version: 3
88
109
  summary: Provides BBCode for Ruby.
data/Manifest DELETED
@@ -1,14 +0,0 @@
1
- README.rdoc
2
- Rakefile
3
- init.rb
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
12
- spec/trainbbcode_spec.rb
13
- trainbbcode.gemspec
14
- Manifest