redclothcoderay 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 August Lilleaas
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -13,6 +13,9 @@ Installation as usual:
13
13
 
14
14
  sudo gem install redclothcoderay
15
15
 
16
+ You can also install the gem via github, to get the latest HEAD.
17
+
18
+ sudo gem install augustl-redclothcoderay --source=http://gems.github.com/
16
19
 
17
20
  == Using
18
21
 
data/Rakefile CHANGED
@@ -1,9 +1,23 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'test')
3
4
 
4
- task :default => :test
5
+ task :default => "test:v4"
5
6
 
6
- task :test do
7
- $LOAD_PATH << File.join(File.dirname(__FILE__), 'test')
8
- load "test/redclothcoderay_test.rb"
7
+ namespace :test do
8
+ desc "Test RedCloth 3"
9
+ task :v3 do
10
+ gem 'RedCloth', "< 4.0.0"
11
+ require 'RedCloth'
12
+
13
+ load "test/redclothcoderay_test.rb"
14
+ end
15
+
16
+ desc "Test RedCloth 4"
17
+ task :v4 do
18
+ gem 'RedCloth', ">= 4.0.0"
19
+ require 'RedCloth'
20
+
21
+ load "test/redclothcoderay_test.rb"
22
+ end
9
23
  end
@@ -1,38 +1,21 @@
1
1
  module RedclothCoderay
2
2
  SINGLE_LINE = '<code class="inline_code">%s</code>'
3
3
  MULTI_LINE = '<pre><code class="multiline_code">%s</code></pre>'
4
- SOURCE_TAG_REGEXP = /(([\t\n])?<source(?:\:([a-z]+))?>(.+?)<\/source>[\t\n]?)/m
4
+ SOURCE_TAG_REGEXP = /(([\t\n])?<source(?:\:([a-z]+))?>(.+?)<\/source>([\t\n])?)/m
5
5
  CODERAY_OPTIONS = {:wrap => nil, :css => :class}
6
6
 
7
- # The RedCloth extension that performs the syntax highlighting.
8
- def refs_syntax_highlighter(text)
9
- text.gsub!(SOURCE_TAG_REGEXP) do |m|
7
+ def preprocess_with_syntax_highlighting(text)
8
+ text.gsub(SOURCE_TAG_REGEXP) do |m|
10
9
  all_of_it = $~[1]
11
10
  whitespace_before = $~[2]
12
11
  lang = ($~[3] || :ruby).to_sym
13
12
  code = $~[4].strip
13
+ whitespace_after = $~[5]
14
14
 
15
15
  wrap_in = all_of_it =~ /\n/ ? MULTI_LINE : SINGLE_LINE
16
16
  highlighted = wrap_in % CodeRay.scan(code, lang).div(CODERAY_OPTIONS)
17
17
 
18
- "#{whitespace_before}<notextile>#{highlighted}</notextile>"
19
- end
20
- end
21
-
22
- # Adds the syntax highlighter to all RedCloth#to_htmls, so that you don't have to
23
- # do that to_html(:textile, :refs_syntax_highlighter) thin.
24
- def self.always_on
25
- if RedCloth::VERSION.to_s < "4"
26
- RedCloth::DEFAULT_RULES << :refs_syntax_highlighter
27
- else
28
- RedCloth::TextileDoc.class_eval {
29
- alias :_to_html :to_html
30
-
31
- def to_html(*rules)
32
- rules << :refs_syntax_highlighter
33
- _to_html(*rules)
34
- end
35
- }
18
+ "#{whitespace_before}<notextile>#{highlighted}</notextile>#{whitespace_after}"
36
19
  end
37
20
  end
38
21
 
@@ -41,4 +24,15 @@ module RedclothCoderay
41
24
  end
42
25
  end
43
26
 
44
- RedCloth.class_eval { include RedclothCoderay }
27
+ redcloth_thingie = RedCloth::VERSION.to_s < "4" ? RedCloth : RedCloth::TextileDoc
28
+
29
+ redcloth_thingie.class_eval {
30
+ alias_method :_initialize, :initialize
31
+
32
+ def initialize(text, *args)
33
+ text = preprocess_with_syntax_highlighting(text)
34
+ _initialize(text, *args)
35
+ end
36
+ }
37
+
38
+ redcloth_thingie.send(:include, RedclothCoderay)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "redclothcoderay"
3
- s.version = "0.2.0"
4
- s.date = "2009-04-23"
3
+ s.version = "0.3.0"
4
+ s.date = "2009-05-06"
5
5
  s.authors = ["August Lilleaas"]
6
6
  s.email = "augustlilleaas@gmail.com"
7
7
  s.rubyforge_project = "redclothcoderay"
@@ -11,14 +11,5 @@ Gem::Specification.new do |s|
11
11
  s.summary = "Integrates CodeRay with RedCloth by adding a <source> tag."
12
12
  s.homepage = "http://redclothcoderay.rubyforge.org"
13
13
  s.extensions = ["Rakefile"]
14
- s.files =
15
- ["redclothcoderay.gemspec",
16
- "README",
17
- "Rakefile",
18
- "lib/redclothcoderay.rb",
19
- "test/redclothcoderay_test.rb",
20
- "test/always_on_3_test.rb",
21
- "test/always_on_4_test.rb",
22
- "test/coderay_options_test.rb",
23
- "test/test_helper.rb"]
14
+ s.files = Dir["**/*"].select {|d| File.file?(d) }
24
15
  end
@@ -1,11 +1,10 @@
1
1
  require 'test_helper'
2
- require 'redcloth'
3
2
  require 'redclothcoderay'
4
3
 
5
4
  class PluginTest < Test::Unit::TestCase
6
5
  def test_parsing_inline_code
7
6
  text = "Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!"
8
- result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
7
+ result = RedCloth.new(text).to_html
9
8
 
10
9
  assert_equal(%Q{<p>Hello, this is <strong>textilized</strong>. It also has <code class="inline_code"><span class="iv">@inline_code_examples</span></code>!</p>}, result)
11
10
  end
@@ -17,7 +16,7 @@ class PluginTest < Test::Unit::TestCase
17
16
  puts "Allright"
18
17
  end
19
18
  </source>}
20
- result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
19
+ result = RedCloth.new(text).to_html
21
20
 
22
21
  assert result.include?(%Q{<strong>textilized</strong>})
23
22
  assert result.include?(%Q{<pre><code class="multiline_code">})
@@ -30,7 +29,7 @@ class PluginTest < Test::Unit::TestCase
30
29
  hello_to_you
31
30
  </source>
32
31
  }
33
- result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
32
+ result = RedCloth.new(text).to_html
34
33
 
35
34
  assert result.include?(%Q{<strong>textilized</strong>})
36
35
  assert result.include?(%Q{<pre><code class=\"multiline_code\">hello_to_you</code></pre>})
@@ -38,7 +37,7 @@ class PluginTest < Test::Unit::TestCase
38
37
 
39
38
  def test_parsing_other_languages
40
39
  text = %Q{Hello, this is *textilized* with some <source:html><p>HTML code</p></source>!}
41
- result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
40
+ result = RedCloth.new(text).to_html
42
41
 
43
42
  assert result.include?(%Q{<strong>textilized</strong>})
44
43
  assert result.include?(%Q{<code class="inline_code"><span class="ta">&lt;p&gt;</span>HTML code<span class="ta">&lt;/p&gt;</span></code>})
@@ -50,7 +49,26 @@ class PluginTest < Test::Unit::TestCase
50
49
  <source>
51
50
  hello_world
52
51
  </source>}
53
- result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
52
+ result = RedCloth.new(text).to_html
54
53
  assert result.include?(%Q{<h2>Hello, world.</h2>})
55
54
  end
55
+
56
+ # This case is a real case that caused borks, which lead to 0.3.0.
57
+ def test_odd_indents
58
+ text = %Q{Let's try, now.
59
+
60
+ <source>
61
+ class Person < ActiveRecord::Base
62
+ composed_of :address, :class_name => "Address",
63
+ :mapping => [
64
+ [:address_street, :street],
65
+ [:address_postal_code, :postal_code]]
66
+ end
67
+ </source>}
68
+
69
+ result = RedCloth.new(text).to_html
70
+
71
+ assert result.include?(%{[<span class="sy">:address_street</span>, <span class="sy">:street</span>],})
72
+ assert result.include?(%{composed_of <span class="sy">:address</span>, <span class="sy">:class_name</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">Address</span><span class="dl">&quot;</span></span>,})
73
+ end
56
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redclothcoderay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - August Lilleaas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-23 00:00:00 +02:00
12
+ date: 2009-05-06 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,14 +41,13 @@ extensions:
41
41
  extra_rdoc_files: []
42
42
 
43
43
  files:
44
- - redclothcoderay.gemspec
45
- - README
46
- - Rakefile
47
44
  - lib/redclothcoderay.rb
48
- - test/redclothcoderay_test.rb
49
- - test/always_on_3_test.rb
50
- - test/always_on_4_test.rb
45
+ - MIT-LICENSE
46
+ - Rakefile
47
+ - README.rdoc
48
+ - redclothcoderay.gemspec
51
49
  - test/coderay_options_test.rb
50
+ - test/redclothcoderay_test.rb
52
51
  - test/test_helper.rb
53
52
  has_rdoc: true
54
53
  homepage: http://redclothcoderay.rubyforge.org
@@ -1,14 +0,0 @@
1
- require 'test_helper'
2
- gem 'RedCloth', "< 4.0.0"
3
- require 'RedCloth'
4
- require 'redclothcoderay'
5
-
6
- # Is in isolation, because it meddles with states and shit. CBA to mock that.
7
- class AlwaysOn3Test < Test::Unit::TestCase
8
- def test_always_on
9
- RedclothCoderay.always_on
10
- result = RedCloth.new(%{I thar. <source>inline_code</source> and *textile*!}).to_html
11
- assert result.include?("<strong>textile</strong>")
12
- assert result.include?('<code class="inline_code">')
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- require 'test_helper'
2
- gem 'RedCloth', ">= 4.0.0"
3
- require 'RedCloth'
4
- require 'redclothcoderay'
5
-
6
- # Is in isolation, because it meddles with states and shit. CBA to mock that.
7
- class AlwaysOn3Test < Test::Unit::TestCase
8
- def test_always_on
9
- RedclothCoderay.always_on
10
- result = RedCloth.new(%{I thar. <source>inline_code</source> and *textile*!}).to_html
11
- assert result.include?("<strong>textile</strong>")
12
- assert result.include?('<code class="inline_code">')
13
- end
14
- end