leethal-redclothcoderay 0.1.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/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.
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) %>
data/Rakefile ADDED
@@ -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,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,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,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,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leethal-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 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: RedCloth
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: coderay
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: echoe
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ description: Integrates CodeRay with RedCloth by adding a <source> tag.
43
+ email: augustlilleaas@gmail.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - lib/redcloth_with_coderay/customized_textile_helper.rb
50
+ - lib/redcloth_with_coderay/redcloth_extension.rb
51
+ - lib/redcloth_with_coderay.rb
52
+ - README
53
+ files:
54
+ - lib/redcloth_with_coderay/customized_textile_helper.rb
55
+ - lib/redcloth_with_coderay/redcloth_extension.rb
56
+ - lib/redcloth_with_coderay.rb
57
+ - Manifest
58
+ - MIT-LICENSE
59
+ - Rakefile
60
+ - README
61
+ - test/redclothcoderay_test.rb
62
+ - redclothcoderay.gemspec
63
+ has_rdoc: true
64
+ homepage: http://redclothcoderay.rubyforge.org/
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --line-numbers
68
+ - --inline-source
69
+ - --title
70
+ - Redclothcoderay
71
+ - --main
72
+ - README
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "1.2"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: redclothcoderay
90
+ rubygems_version: 1.2.0
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: Integrates CodeRay with RedCloth by adding a <source> tag.
94
+ test_files:
95
+ - test/redclothcoderay_test.rb