redclothcoderay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.
@@ -0,0 +1,8 @@
1
+ lib/redcloth_with_coderay/customized_textile_helper.rb
2
+ lib/redcloth_with_coderay/redcloth_extension.rb
3
+ lib/redcloth_with_coderay.rb
4
+ Manifest
5
+ MIT-LICENSE
6
+ Rakefile
7
+ README
8
+ test/redclothcoderay_test.rb
data/README ADDED
@@ -0,0 +1,25 @@
1
+ Rails plugin that extends Redcloth to parse the <source> tag and syntax highlight it. Sample input:
2
+
3
+ Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!
4
+
5
+ What about a multi-line code sample?
6
+
7
+ <source:html>
8
+ <h1>Hello, world!</h1>
9
+ </source>
10
+
11
+ Which will return (indented for clarity):
12
+
13
+ <p>Hello, this is <strong>textilized</strong>. It also has <code class="inline_code">
14
+ <span class="iv">@inline_code_examples</span>
15
+ </code>!</p>
16
+
17
+ <p>What about a multi-line code sample?</p>
18
+
19
+ <pre><code class=\"multiline_code\">
20
+ <span class=\"ta\">&amp;lt;h1&amp;gt;</span>Hello, world!<span class=\"ta\">&amp;lt;/h1&amp;gt;</span>
21
+ </code></pre>
22
+
23
+ This plugin overrides the built-in "textilize helper", just call it as usual, in a helper or a view:
24
+
25
+ <%= textilize(@post.body) %>
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('redclothcoderay', '0.1.0') do |p|
6
+ p.description = "Integrates CodeRay with RedCloth by adding a <source> tag."
7
+ p.url = "http://redclothcoderay.rubyforge.org/"
8
+ p.author = "August Lilleaas"
9
+ p.email = "augustlilleaas@gmail.com"
10
+ p.runtime_dependencies = ['RedCloth', 'coderay']
11
+ end
@@ -0,0 +1,7 @@
1
+ $: << File.join(File.dirname(__FILE__), 'redcloth_with_coderay')
2
+
3
+ require 'redcloth_extension'
4
+ require 'customized_textile_helper'
5
+
6
+ RedCloth.class_eval { include RedclothWithCoderay }
7
+ ActionView::Helpers.class_eval { include CustomizedTextileHelper }
@@ -0,0 +1,5 @@
1
+ module CustomizedTextileHelper
2
+ def textilize(text)
3
+ RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ class String
2
+ def contains_newlines?
3
+ self =~ /\n/
4
+ end
5
+ end
6
+
7
+ module RedclothWithCoderay
8
+ SINGLE_LINE = '<code class="inline_code">%s</code>'
9
+ MULTI_LINE = '<pre><code class="multiline_code">%s</code></pre>'
10
+ WRAPPER = '<notextile>%s</notextile>'
11
+ SOURCE_TAG_REGEXP = /([\t\n]?<source(?:\:([a-z]+))?>(.+?)<\/source>[\t\n]?)/m
12
+
13
+ def refs_syntax_highlighter(text)
14
+ text.gsub!(SOURCE_TAG_REGEXP) do |m|
15
+ all_of_it = $~[1]
16
+ lang = ($~[2] || :ruby).to_sym
17
+ code = $~[3].strip
18
+
19
+ wrap_in = all_of_it.contains_newlines? ? MULTI_LINE : SINGLE_LINE
20
+ highlighted = wrap_in % CodeRay.scan(code, lang).div(:wrap => nil, :css => :class)
21
+ WRAPPER % highlighted
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{redclothcoderay}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["August Lilleaas"]
9
+ s.date = %q{2008-11-18}
10
+ s.description = %q{Integrates CodeRay with RedCloth by adding a <source> tag.}
11
+ s.email = %q{augustlilleaas@gmail.com}
12
+ s.extra_rdoc_files = ["lib/redcloth_with_coderay/customized_textile_helper.rb", "lib/redcloth_with_coderay/redcloth_extension.rb", "lib/redcloth_with_coderay.rb", "README"]
13
+ s.files = ["lib/redcloth_with_coderay/customized_textile_helper.rb", "lib/redcloth_with_coderay/redcloth_extension.rb", "lib/redcloth_with_coderay.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "test/redclothcoderay_test.rb", "redclothcoderay.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://redclothcoderay.rubyforge.org/}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Redclothcoderay", "--main", "README"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{redclothcoderay}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Integrates CodeRay with RedCloth by adding a <source> tag.}
21
+ s.test_files = ["test/redclothcoderay_test.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<RedCloth>, [">= 0"])
29
+ s.add_runtime_dependency(%q<coderay>, [">= 0"])
30
+ s.add_development_dependency(%q<echoe>, [">= 0"])
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
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'redcloth'
3
+ require 'coderay'
4
+ require 'test/unit'
5
+
6
+ require 'action_controller'
7
+ require 'action_controller/test_process'
8
+
9
+ current_directory = File.dirname(__FILE__)
10
+ $:.unshift File.join(current_directory, '..', 'lib')
11
+ require 'redcloth_with_coderay'
12
+
13
+
14
+ class PluginTest < Test::Unit::TestCase
15
+ def test_parsing_inline_code
16
+ text = "Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!"
17
+ result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
18
+
19
+ 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)
20
+ end
21
+
22
+ def test_parsing_multiline_code
23
+ text = %Q{Hello, this is *textilized*.
24
+ <source>
25
+ def hello_world
26
+ puts "Allright"
27
+ end
28
+ </source>}
29
+ result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
30
+
31
+ assert result.include?(%Q{<strong>textilized</strong>})
32
+ assert result.include?(%Q{<pre><code class="multiline_code">})
33
+ end
34
+
35
+ def test_one_liner_multiline_code
36
+ text = %Q{Hello, this is *textilized*.
37
+
38
+ <source>
39
+ hello_to_you
40
+ </source>
41
+ }
42
+ result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
43
+
44
+ assert result.include?(%Q{<strong>textilized</strong>})
45
+ assert result.include?(%Q{<pre><code class=\"multiline_code\">hello_to_you</code></pre>})
46
+ end
47
+
48
+ def test_parsing_other_languages
49
+ text = %Q{Hello, this is *textilized* with some <source:html><p>HTML code</p></source>!}
50
+ result = RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
51
+
52
+ assert result.include?(%Q{<strong>textilized</strong>})
53
+ 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>})
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redclothcoderay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - August Lilleaas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-18 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: RedCloth
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: coderay
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
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.
46
+ email: augustlilleaas@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - lib/redcloth_with_coderay/customized_textile_helper.rb
53
+ - lib/redcloth_with_coderay/redcloth_extension.rb
54
+ - lib/redcloth_with_coderay.rb
55
+ - README
56
+ files:
57
+ - lib/redcloth_with_coderay/customized_textile_helper.rb
58
+ - lib/redcloth_with_coderay/redcloth_extension.rb
59
+ - lib/redcloth_with_coderay.rb
60
+ - Manifest
61
+ - MIT-LICENSE
62
+ - Rakefile
63
+ - README
64
+ - test/redclothcoderay_test.rb
65
+ - redclothcoderay.gemspec
66
+ has_rdoc: true
67
+ homepage: http://redclothcoderay.rubyforge.org/
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --line-numbers
71
+ - --inline-source
72
+ - --title
73
+ - Redclothcoderay
74
+ - --main
75
+ - README
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "1.2"
89
+ version:
90
+ requirements: []
91
+
92
+ rubyforge_project: redclothcoderay
93
+ rubygems_version: 1.3.1
94
+ signing_key:
95
+ specification_version: 2
96
+ summary: Integrates CodeRay with RedCloth by adding a <source> tag.
97
+ test_files:
98
+ - test/redclothcoderay_test.rb