redclothcoderay 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +11 -7
- data/Rakefile +6 -8
- data/lib/redclothcoderay.rb +44 -0
- data/redclothcoderay.gemspec +21 -38
- data/test/always_on_3_test.rb +14 -0
- data/test/always_on_4_test.rb +14 -0
- data/test/coderay_options_test.rb +11 -0
- data/test/redclothcoderay_test.rb +2 -8
- data/test/test_helper.rb +6 -0
- metadata +19 -35
- data/CHANGELOG +0 -15
- data/MIT-LICENSE +0 -20
- data/Manifest +0 -7
- data/lib/redcloth_with_coderay.rb +0 -22
data/README
CHANGED
@@ -21,19 +21,23 @@ You have to specify that you want to use refs_syntax_highlighter when calling Re
|
|
21
21
|
require 'rubygems'
|
22
22
|
require 'redcloth'
|
23
23
|
require 'coderay'
|
24
|
-
require '
|
24
|
+
require 'redclothcoderay'
|
25
25
|
|
26
26
|
RedCloth.new('I am *bold* and <source>@hi_tech</source>').to_html(:textile, :refs_syntax_highlighter)
|
27
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
|
+
|
28
36
|
== In Ruby on Rails
|
29
37
|
|
30
|
-
|
38
|
+
In an initializer (config/initializers/[anything].rb) or at the bottom of environment.rb, add this line:
|
31
39
|
|
32
|
-
|
33
|
-
def textilize(text)
|
34
|
-
RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
|
35
|
-
end
|
36
|
-
end
|
40
|
+
Redclothcoderay.always_on
|
37
41
|
|
38
42
|
== Example
|
39
43
|
|
data/Rakefile
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'rake'
|
3
|
-
require '
|
2
|
+
require 'rake/testtask'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
p.runtime_dependencies = ['RedCloth', 'coderay']
|
4
|
+
task :default => :test
|
5
|
+
|
6
|
+
task :test do
|
7
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'test')
|
8
|
+
load "test/redclothcoderay_test.rb"
|
11
9
|
end
|
@@ -0,0 +1,44 @@
|
|
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
CHANGED
@@ -1,41 +1,24 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
1
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
2
|
+
s.name = "redclothcoderay"
|
3
|
+
s.version = "0.2.0"
|
4
|
+
s.date = "2009-04-23"
|
8
5
|
s.authors = ["August Lilleaas"]
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.email = %q{augustlilleaas@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/redcloth_with_coderay.rb", "README"]
|
13
|
-
s.files = ["CHANGELOG", "lib/redcloth_with_coderay.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "test/redclothcoderay_test.rb", "redclothcoderay.gemspec"]
|
6
|
+
s.email = "augustlilleaas@gmail.com"
|
7
|
+
s.rubyforge_project = "redclothcoderay"
|
14
8
|
s.has_rdoc = true
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
s.add_dependency(%q<RedCloth>, [">= 0"])
|
33
|
-
s.add_dependency(%q<coderay>, [">= 0"])
|
34
|
-
s.add_dependency(%q<echoe>, [">= 0"])
|
35
|
-
end
|
36
|
-
else
|
37
|
-
s.add_dependency(%q<RedCloth>, [">= 0"])
|
38
|
-
s.add_dependency(%q<coderay>, [">= 0"])
|
39
|
-
s.add_dependency(%q<echoe>, [">= 0"])
|
40
|
-
end
|
41
|
-
end
|
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
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,11 @@
|
|
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,12 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'redcloth'
|
3
|
-
require '
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
current_directory = File.dirname(__FILE__)
|
7
|
-
$:.unshift File.join(current_directory, '..', 'lib')
|
8
|
-
require 'redcloth_with_coderay'
|
9
|
-
|
3
|
+
require 'redclothcoderay'
|
10
4
|
|
11
5
|
class PluginTest < Test::Unit::TestCase
|
12
6
|
def test_parsing_inline_code
|
data/test/test_helper.rb
ADDED
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.
|
4
|
+
version: 0.2.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:
|
12
|
+
date: 2009-04-23 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,45 +32,29 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
-
|
36
|
-
name: echoe
|
37
|
-
type: :development
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: "0"
|
44
|
-
version:
|
45
|
-
description: Integrates CodeRay with RedCloth by adding a <source> tag.
|
35
|
+
description:
|
46
36
|
email: augustlilleaas@gmail.com
|
47
37
|
executables: []
|
48
38
|
|
49
|
-
extensions:
|
39
|
+
extensions:
|
40
|
+
- Rakefile
|
41
|
+
extra_rdoc_files: []
|
50
42
|
|
51
|
-
extra_rdoc_files:
|
52
|
-
- CHANGELOG
|
53
|
-
- lib/redcloth_with_coderay.rb
|
54
|
-
- README
|
55
43
|
files:
|
56
|
-
-
|
57
|
-
- lib/redcloth_with_coderay.rb
|
58
|
-
- Manifest
|
59
|
-
- MIT-LICENSE
|
60
|
-
- Rakefile
|
44
|
+
- redclothcoderay.gemspec
|
61
45
|
- README
|
46
|
+
- Rakefile
|
47
|
+
- lib/redclothcoderay.rb
|
62
48
|
- test/redclothcoderay_test.rb
|
63
|
-
-
|
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
|
64
53
|
has_rdoc: true
|
65
|
-
homepage: http://redclothcoderay.rubyforge.org
|
54
|
+
homepage: http://redclothcoderay.rubyforge.org
|
66
55
|
post_install_message:
|
67
|
-
rdoc_options:
|
68
|
-
|
69
|
-
- --inline-source
|
70
|
-
- --title
|
71
|
-
- Redclothcoderay
|
72
|
-
- --main
|
73
|
-
- README
|
56
|
+
rdoc_options: []
|
57
|
+
|
74
58
|
require_paths:
|
75
59
|
- lib
|
76
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -83,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
67
|
requirements:
|
84
68
|
- - ">="
|
85
69
|
- !ruby/object:Gem::Version
|
86
|
-
version: "
|
70
|
+
version: "0"
|
87
71
|
version:
|
88
72
|
requirements: []
|
89
73
|
|
@@ -92,5 +76,5 @@ rubygems_version: 1.3.1
|
|
92
76
|
signing_key:
|
93
77
|
specification_version: 2
|
94
78
|
summary: Integrates CodeRay with RedCloth by adding a <source> tag.
|
95
|
-
test_files:
|
96
|
-
|
79
|
+
test_files: []
|
80
|
+
|
data/CHANGELOG
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
*0.1.2 (November 25th 2008)
|
2
|
-
|
3
|
-
* Fixed some issues with whitespaces before <source> tags
|
4
|
-
|
5
|
-
* Removed String#has_newlines?, doing it "by hand" instead.
|
6
|
-
|
7
|
-
*0.1.1 (November 18th 2008)
|
8
|
-
|
9
|
-
* Removed any references to Rails
|
10
|
-
|
11
|
-
* Updated documentation.
|
12
|
-
|
13
|
-
*0.1.0 (November 18th 2008)
|
14
|
-
|
15
|
-
* Converted the plugin into a gem.
|
data/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
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.
|
data/Manifest
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module RedclothWithCoderay
|
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
|
-
|
6
|
-
# The RedCloth extension that performs the syntax highlighting.
|
7
|
-
def refs_syntax_highlighter(text)
|
8
|
-
text.gsub!(SOURCE_TAG_REGEXP) do |m|
|
9
|
-
all_of_it = $~[1]
|
10
|
-
whitespace_before = $~[2]
|
11
|
-
lang = ($~[3] || :ruby).to_sym
|
12
|
-
code = $~[4].strip
|
13
|
-
|
14
|
-
wrap_in = all_of_it =~ /\n/ ? MULTI_LINE : SINGLE_LINE
|
15
|
-
highlighted = wrap_in % CodeRay.scan(code, lang).div(:wrap => nil, :css => :class)
|
16
|
-
|
17
|
-
"#{whitespace_before}<notextile>#{highlighted}</notextile>"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
RedCloth.class_eval { include RedclothWithCoderay }
|