redclothcoderay 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +19 -13
- data/Rakefile +21 -1
- data/lib/redclothcoderay.rb +12 -6
- data/redclothcoderay.gemspec +53 -12
- data/test/redclothcoderay_code_tag.rb +74 -0
- metadata +16 -11
data/README.rdoc
CHANGED
@@ -38,21 +38,27 @@ You can specify the CodeRay options, too (defaults to RedclothCoderay::CODERAY_O
|
|
38
38
|
This input:
|
39
39
|
|
40
40
|
Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!
|
41
|
-
|
41
|
+
|
42
42
|
What about a multi-line code sample?
|
43
|
-
|
43
|
+
|
44
44
|
<source:html>
|
45
45
|
<h1>Hello, world!</h1>
|
46
46
|
</source>
|
47
|
-
|
48
|
-
produces this output (indented for clarity):
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
Produces this output (indented for clarity):
|
49
|
+
|
50
|
+
<p>
|
51
|
+
Hello, this is <strong>textilized</strong>. It also has
|
52
|
+
<code class="inline_code">
|
53
|
+
<span class="iv">
|
54
|
+
@inline_code_examples
|
55
|
+
</span>
|
56
|
+
</code>!
|
57
|
+
</p>
|
58
|
+
|
59
|
+
<p>
|
60
|
+
What about a multi-line code sample?
|
61
|
+
</p>
|
62
|
+
<div class="multiline_code">
|
63
|
+
<span class="ta"><h1></span>Hello, world!<span class="ta"></h1></span>
|
64
|
+
</div>
|
data/Rakefile
CHANGED
@@ -20,4 +20,24 @@ namespace :test do
|
|
20
20
|
|
21
21
|
load "test/redclothcoderay_test.rb"
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'jeweler'
|
27
|
+
Jeweler::Tasks.new do |gemspec|
|
28
|
+
gemspec.name = "redclothcoderay"
|
29
|
+
gemspec.summary = "Integrates CodeRay with RedCloth by adding a <source> tag."
|
30
|
+
gemspec.description = %q{Adds CodeRay syntax highlighting support to RedCloth, with a ‘source’ tag.}
|
31
|
+
gemspec.email = ["augustlilleaas@gmail.com", "korhonen.matt@gmail.com"]
|
32
|
+
gemspec.homepage = "http://redclothcoderay.rubyforge.org"
|
33
|
+
gemspec.authors = ['August Lilleaas', 'Matias Korhonen']
|
34
|
+
gemspec.add_dependency('RedCloth')
|
35
|
+
gemspec.add_dependency('coderay')
|
36
|
+
gemspec.has_rdoc = true
|
37
|
+
gemspec.rubyforge_project = "redclothcoderay"
|
38
|
+
gemspec.files = FileList["lib", "lib/redclothcoderay.rb", "MIT-LICENSE", "Rakefile", "README.rdoc", "redclothcoderay.gemspec", "test", "test/coderay_options_test.rb", "test/redclothcoderay_test.rb", "test/test_helper.rb"]
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
42
|
+
end
|
43
|
+
|
data/lib/redclothcoderay.rb
CHANGED
@@ -3,7 +3,7 @@ module RedclothCoderay
|
|
3
3
|
MULTI_LINE = '<div class="multiline_code">%s</div>'
|
4
4
|
SOURCE_TAG_REGEXP = /(([\t\n])?<source(?:\:([a-z]+))?>(.+?)<\/source>([\t\n])?)/m
|
5
5
|
CODERAY_OPTIONS = {:wrap => nil, :css => :class}
|
6
|
-
|
6
|
+
|
7
7
|
def preprocess_with_syntax_highlighting(text)
|
8
8
|
text.gsub(SOURCE_TAG_REGEXP) do |m|
|
9
9
|
all_of_it = $~[1]
|
@@ -11,14 +11,20 @@ module RedclothCoderay
|
|
11
11
|
lang = ($~[3] || :ruby).to_sym
|
12
12
|
code = $~[4].strip
|
13
13
|
whitespace_after = $~[5]
|
14
|
-
|
14
|
+
|
15
15
|
wrap_in = all_of_it =~ /\n/ ? MULTI_LINE : SINGLE_LINE
|
16
|
-
|
17
|
-
|
16
|
+
if all_of_it =~ /\n/
|
17
|
+
highlighted = wrap_in % CodeRay.scan(code, lang).div(CODERAY_OPTIONS)
|
18
|
+
else
|
19
|
+
options = CODERAY_OPTIONS
|
20
|
+
options[:line_numbers] = nil
|
21
|
+
highlighted = wrap_in % CodeRay.scan(code, lang).span(options)
|
22
|
+
end
|
23
|
+
|
18
24
|
"#{whitespace_before}<notextile>#{highlighted}</notextile>#{whitespace_after}"
|
19
25
|
end
|
20
26
|
end
|
21
|
-
|
27
|
+
|
22
28
|
def self.coderay_options(options)
|
23
29
|
CODERAY_OPTIONS.replace(options)
|
24
30
|
end
|
@@ -28,7 +34,7 @@ redcloth_thingie = RedCloth::VERSION.to_s < "4" ? RedCloth : RedCloth::TextileDo
|
|
28
34
|
|
29
35
|
redcloth_thingie.class_eval {
|
30
36
|
alias_method :_initialize, :initialize
|
31
|
-
|
37
|
+
|
32
38
|
def initialize(text, *args)
|
33
39
|
text = preprocess_with_syntax_highlighting(text)
|
34
40
|
_initialize(text, *args)
|
data/redclothcoderay.gemspec
CHANGED
@@ -1,16 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
1
6
|
Gem::Specification.new do |s|
|
2
|
-
s.name =
|
3
|
-
s.version = "0.3.
|
7
|
+
s.name = %q{redclothcoderay}
|
8
|
+
s.version = "0.3.6"
|
9
|
+
|
4
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.email = "augustlilleaas@gmail.com"
|
8
|
-
s.files = ["lib", "lib/redclothcoderay.rb", "MIT-LICENSE", "Rakefile", "README.rdoc", "redclothcoderay.gemspec", "test", "test/coderay_options_test.rb", "test/redclothcoderay_test.rb", "test/test_helper.rb"]
|
9
|
-
s.rubyforge_project = "redclothcoderay"
|
10
|
-
s.has_rdoc = true
|
11
|
-
s.add_dependency('RedCloth')
|
12
|
-
s.add_dependency('coderay')
|
13
|
-
s.summary = "Integrates CodeRay with RedCloth by adding a <source> tag."
|
14
|
-
s.homepage = "http://redclothcoderay.rubyforge.org"
|
11
|
+
s.authors = ["August Lilleaas", "Matias Korhonen"]
|
12
|
+
s.date = %q{2009-11-15}
|
15
13
|
s.description = %q{Adds CodeRay syntax highlighting support to RedCloth, with a ‘source’ tag.}
|
14
|
+
s.email = ["augustlilleaas@gmail.com", "korhonen.matt@gmail.com"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"lib/redclothcoderay.rb",
|
23
|
+
"redclothcoderay.gemspec",
|
24
|
+
"test/coderay_options_test.rb",
|
25
|
+
"test/redclothcoderay_test.rb",
|
26
|
+
"test/test_helper.rb"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://redclothcoderay.rubyforge.org}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubyforge_project = %q{redclothcoderay}
|
32
|
+
s.rubygems_version = %q{1.3.5}
|
33
|
+
s.summary = %q{Integrates CodeRay with RedCloth by adding a <source> tag.}
|
34
|
+
s.test_files = [
|
35
|
+
"test/redclothcoderay_code_tag.rb",
|
36
|
+
"test/test_helper.rb",
|
37
|
+
"test/redclothcoderay_test.rb",
|
38
|
+
"test/coderay_options_test.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<RedCloth>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<coderay>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<RedCloth>, [">= 0"])
|
50
|
+
s.add_dependency(%q<coderay>, [">= 0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<RedCloth>, [">= 0"])
|
54
|
+
s.add_dependency(%q<coderay>, [">= 0"])
|
55
|
+
end
|
16
56
|
end
|
57
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'redclothcoderay'
|
3
|
+
|
4
|
+
class PluginWithCodeTagTest < Test::Unit::TestCase
|
5
|
+
def test_parsing_inline_code
|
6
|
+
text = "Hello, this is *textilized*. It also has <code>@inline_code_examples</code>!"
|
7
|
+
result = RedCloth.new(text).to_html
|
8
|
+
|
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)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_parsing_multiline_code
|
13
|
+
text = %Q{Hello, this is *textilized*.
|
14
|
+
<code>
|
15
|
+
def hello_world
|
16
|
+
puts "Allright"
|
17
|
+
end
|
18
|
+
</code>}
|
19
|
+
result = RedCloth.new(text).to_html
|
20
|
+
|
21
|
+
assert result.include?(%Q{<strong>textilized</strong>})
|
22
|
+
assert result.include?(%Q{<pre><code class="multiline_code">})
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_one_liner_multiline_code
|
26
|
+
text = %Q{Hello, this is *textilized*.
|
27
|
+
|
28
|
+
<code>
|
29
|
+
hello_to_you
|
30
|
+
</code>
|
31
|
+
}
|
32
|
+
result = RedCloth.new(text).to_html
|
33
|
+
|
34
|
+
assert result.include?(%Q{<strong>textilized</strong>})
|
35
|
+
assert result.include?(%Q{<pre><code class=\"multiline_code\">hello_to_you</code></pre>})
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_parsing_other_languages
|
39
|
+
text = %Q{Hello, this is *textilized* with some <code:html><p>HTML code</p></code>!}
|
40
|
+
result = RedCloth.new(text).to_html
|
41
|
+
|
42
|
+
assert result.include?(%Q{<strong>textilized</strong>})
|
43
|
+
assert result.include?(%Q{<code class="inline_code"><span class="ta"><p></span>HTML code<span class="ta"></p></span></code>})
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_after_a_header
|
47
|
+
text = %Q{h2. Hello, world.
|
48
|
+
|
49
|
+
<code>
|
50
|
+
hello_world
|
51
|
+
</code>}
|
52
|
+
result = RedCloth.new(text).to_html
|
53
|
+
assert result.include?(%Q{<h2>Hello, world.</h2>})
|
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
|
+
<code>
|
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
|
+
</code>}
|
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> => <span class="s"><span class="dl">"</span><span class="k">Address</span><span class="dl">"</span></span>,})
|
73
|
+
end
|
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.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- August Lilleaas
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-11-15 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -34,18 +34,20 @@ dependencies:
|
|
34
34
|
version: "0"
|
35
35
|
version:
|
36
36
|
description: "Adds CodeRay syntax highlighting support to RedCloth, with a \xE2\x80\x98source\xE2\x80\x99 tag."
|
37
|
-
email:
|
37
|
+
email:
|
38
|
+
- augustlilleaas@gmail.com
|
39
|
+
- korhonen.matt@gmail.com
|
38
40
|
executables: []
|
39
41
|
|
40
42
|
extensions: []
|
41
43
|
|
42
|
-
extra_rdoc_files:
|
43
|
-
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README.rdoc
|
44
46
|
files:
|
45
|
-
- lib/redclothcoderay.rb
|
46
47
|
- MIT-LICENSE
|
47
|
-
- Rakefile
|
48
48
|
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- lib/redclothcoderay.rb
|
49
51
|
- redclothcoderay.gemspec
|
50
52
|
- test/coderay_options_test.rb
|
51
53
|
- test/redclothcoderay_test.rb
|
@@ -55,8 +57,8 @@ homepage: http://redclothcoderay.rubyforge.org
|
|
55
57
|
licenses: []
|
56
58
|
|
57
59
|
post_install_message:
|
58
|
-
rdoc_options:
|
59
|
-
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
60
62
|
require_paths:
|
61
63
|
- lib
|
62
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -78,5 +80,8 @@ rubygems_version: 1.3.5
|
|
78
80
|
signing_key:
|
79
81
|
specification_version: 3
|
80
82
|
summary: Integrates CodeRay with RedCloth by adding a <source> tag.
|
81
|
-
test_files:
|
82
|
-
|
83
|
+
test_files:
|
84
|
+
- test/redclothcoderay_code_tag.rb
|
85
|
+
- test/test_helper.rb
|
86
|
+
- test/redclothcoderay_test.rb
|
87
|
+
- test/coderay_options_test.rb
|