augustl-redclothcoderay 0.2.0 → 0.3.0
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/Rakefile +18 -4
- metadata +4 -12
- data/README +0 -64
- data/lib/redclothcoderay.rb +0 -44
- data/redclothcoderay.gemspec +0 -24
- data/test/always_on_3_test.rb +0 -14
- data/test/always_on_4_test.rb +0 -14
- data/test/coderay_options_test.rb +0 -11
- data/test/redclothcoderay_test.rb +0 -56
- data/test/test_helper.rb +0 -6
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 => :
|
5
|
+
task :default => "test:v4"
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: augustl-redclothcoderay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 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-
|
12
|
+
date: 2009-05-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,16 +40,8 @@ extensions:
|
|
40
40
|
- Rakefile
|
41
41
|
extra_rdoc_files: []
|
42
42
|
|
43
|
-
files:
|
44
|
-
|
45
|
-
- README
|
46
|
-
- Rakefile
|
47
|
-
- lib/redclothcoderay.rb
|
48
|
-
- test/redclothcoderay_test.rb
|
49
|
-
- test/always_on_3_test.rb
|
50
|
-
- test/always_on_4_test.rb
|
51
|
-
- test/coderay_options_test.rb
|
52
|
-
- test/test_helper.rb
|
43
|
+
files: []
|
44
|
+
|
53
45
|
has_rdoc: true
|
54
46
|
homepage: http://redclothcoderay.rubyforge.org
|
55
47
|
post_install_message:
|
data/README
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
== Redcloth with CodeRay
|
2
|
-
|
3
|
-
Adds CodeRay syntax highlighting support to RedCloth, with a 'source' tag. See the examples below.
|
4
|
-
|
5
|
-
A short summary of what you can do:
|
6
|
-
|
7
|
-
* <source>foo</source> - Use this tag to produce CodeRay highlighted HTML for the contents within that tag. The language defaults to Ruby.
|
8
|
-
* <source:css>foo</source> - Highlight as usual, but highlight as CSS. Supports everything CodeRay supports. Refer to the CodeRay documentation for a list of supported languages.
|
9
|
-
|
10
|
-
== Installing
|
11
|
-
|
12
|
-
Installation as usual:
|
13
|
-
|
14
|
-
sudo gem install redclothcoderay
|
15
|
-
|
16
|
-
|
17
|
-
== Using
|
18
|
-
|
19
|
-
You have to specify that you want to use refs_syntax_highlighter when calling RedCloth#to_html.
|
20
|
-
|
21
|
-
require 'rubygems'
|
22
|
-
require 'redcloth'
|
23
|
-
require 'coderay'
|
24
|
-
require 'redclothcoderay'
|
25
|
-
|
26
|
-
RedCloth.new('I am *bold* and <source>@hi_tech</source>').to_html(:textile, :refs_syntax_highlighter)
|
27
|
-
|
28
|
-
You can also use the always_on method to always use the refs_syntax_highlighter parser when calling to_html
|
29
|
-
|
30
|
-
RedclothCoderay.always_on
|
31
|
-
|
32
|
-
You can specify the CodeRay options, too (defaults to RedclothCoderay::CODERAY_OPTIONS).
|
33
|
-
|
34
|
-
RedclothCoderay.coderay_options :line_numbers => :table
|
35
|
-
|
36
|
-
== In Ruby on Rails
|
37
|
-
|
38
|
-
In an initializer (config/initializers/[anything].rb) or at the bottom of environment.rb, add this line:
|
39
|
-
|
40
|
-
Redclothcoderay.always_on
|
41
|
-
|
42
|
-
== Example
|
43
|
-
|
44
|
-
This input:
|
45
|
-
|
46
|
-
Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!
|
47
|
-
|
48
|
-
What about a multi-line code sample?
|
49
|
-
|
50
|
-
<source:html>
|
51
|
-
<h1>Hello, world!</h1>
|
52
|
-
</source>
|
53
|
-
|
54
|
-
produces this output (indented for clarity):
|
55
|
-
|
56
|
-
<p>Hello, this is <strong>textilized</strong>. It also has <code class="inline_code">
|
57
|
-
<span class="iv">@inline_code_examples</span>
|
58
|
-
</code>!</p>
|
59
|
-
|
60
|
-
<p>What about a multi-line code sample?</p>
|
61
|
-
|
62
|
-
<pre><code class=\"multiline_code\">
|
63
|
-
<span class=\"ta\">&lt;h1&gt;</span>Hello, world!<span class=\"ta\">&lt;/h1&gt;</span>
|
64
|
-
</code></pre>
|
data/lib/redclothcoderay.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module RedclothCoderay
|
2
|
-
SINGLE_LINE = '<code class="inline_code">%s</code>'
|
3
|
-
MULTI_LINE = '<pre><code class="multiline_code">%s</code></pre>'
|
4
|
-
SOURCE_TAG_REGEXP = /(([\t\n])?<source(?:\:([a-z]+))?>(.+?)<\/source>[\t\n]?)/m
|
5
|
-
CODERAY_OPTIONS = {:wrap => nil, :css => :class}
|
6
|
-
|
7
|
-
# The RedCloth extension that performs the syntax highlighting.
|
8
|
-
def refs_syntax_highlighter(text)
|
9
|
-
text.gsub!(SOURCE_TAG_REGEXP) do |m|
|
10
|
-
all_of_it = $~[1]
|
11
|
-
whitespace_before = $~[2]
|
12
|
-
lang = ($~[3] || :ruby).to_sym
|
13
|
-
code = $~[4].strip
|
14
|
-
|
15
|
-
wrap_in = all_of_it =~ /\n/ ? MULTI_LINE : SINGLE_LINE
|
16
|
-
highlighted = wrap_in % CodeRay.scan(code, lang).div(CODERAY_OPTIONS)
|
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
|
-
}
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.coderay_options(options)
|
40
|
-
CODERAY_OPTIONS.replace(options)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
RedCloth.class_eval { include RedclothCoderay }
|
data/redclothcoderay.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "redclothcoderay"
|
3
|
-
s.version = "0.2.0"
|
4
|
-
s.date = "2009-04-23"
|
5
|
-
s.authors = ["August Lilleaas"]
|
6
|
-
s.email = "augustlilleaas@gmail.com"
|
7
|
-
s.rubyforge_project = "redclothcoderay"
|
8
|
-
s.has_rdoc = true
|
9
|
-
s.add_dependency('RedCloth')
|
10
|
-
s.add_dependency('coderay')
|
11
|
-
s.summary = "Integrates CodeRay with RedCloth by adding a <source> tag."
|
12
|
-
s.homepage = "http://redclothcoderay.rubyforge.org"
|
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"]
|
24
|
-
end
|
data/test/always_on_3_test.rb
DELETED
@@ -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
|
data/test/always_on_4_test.rb
DELETED
@@ -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,11 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'RedCloth'
|
3
|
-
require 'redclothcoderay'
|
4
|
-
|
5
|
-
class CoderayOptionsTest < Test::Unit::TestCase
|
6
|
-
def test_it
|
7
|
-
RedclothCoderay.coderay_options :line_numbers => :table
|
8
|
-
assert_equal :table, RedclothCoderay::CODERAY_OPTIONS[:line_numbers]
|
9
|
-
assert RedCloth.new("<source>ugly_inline :stuff</source>").to_html(:refs_syntax_highlighter).include?(%{<table class="CodeRay"})
|
10
|
-
end
|
11
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'redcloth'
|
3
|
-
require 'redclothcoderay'
|
4
|
-
|
5
|
-
class PluginTest < Test::Unit::TestCase
|
6
|
-
def test_parsing_inline_code
|
7
|
-
text = "Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!"
|
8
|
-
result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
|
9
|
-
|
10
|
-
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
|
-
end
|
12
|
-
|
13
|
-
def test_parsing_multiline_code
|
14
|
-
text = %Q{Hello, this is *textilized*.
|
15
|
-
<source>
|
16
|
-
def hello_world
|
17
|
-
puts "Allright"
|
18
|
-
end
|
19
|
-
</source>}
|
20
|
-
result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
|
21
|
-
|
22
|
-
assert result.include?(%Q{<strong>textilized</strong>})
|
23
|
-
assert result.include?(%Q{<pre><code class="multiline_code">})
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_one_liner_multiline_code
|
27
|
-
text = %Q{Hello, this is *textilized*.
|
28
|
-
|
29
|
-
<source>
|
30
|
-
hello_to_you
|
31
|
-
</source>
|
32
|
-
}
|
33
|
-
result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
|
34
|
-
|
35
|
-
assert result.include?(%Q{<strong>textilized</strong>})
|
36
|
-
assert result.include?(%Q{<pre><code class=\"multiline_code\">hello_to_you</code></pre>})
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_parsing_other_languages
|
40
|
-
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)
|
42
|
-
|
43
|
-
assert result.include?(%Q{<strong>textilized</strong>})
|
44
|
-
assert result.include?(%Q{<code class="inline_code"><span class="ta"><p></span>HTML code<span class="ta"></p></span></code>})
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_after_a_header
|
48
|
-
text = %Q{h2. Hello, world.
|
49
|
-
|
50
|
-
<source>
|
51
|
-
hello_world
|
52
|
-
</source>}
|
53
|
-
result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
|
54
|
-
assert result.include?(%Q{<h2>Hello, world.</h2>})
|
55
|
-
end
|
56
|
-
end
|