leethal-redclothcoderay 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ *0.1.1 (November 18th 2008)
2
+
3
+ * Removed any references to Rails
4
+
5
+ * Updated documentation.
6
+
7
+ *0.1.0 (November 18th 2008)
8
+
9
+ * Converted the plugin into a gem.
data/README CHANGED
@@ -1,25 +1,50 @@
1
- Rails plugin that extends Redcloth to parse the <source> tag and syntax highlight it. Sample input:
1
+ == Redcloth with CodeRay
2
2
 
3
- Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!
3
+ Adds CodeRay syntax highlighting support to RedCloth, with a 'source' tag. See the examples below.
4
4
 
5
- What about a multi-line code sample?
5
+ A short summary of what you can do:
6
6
 
7
- <source:html>
8
- <h1>Hello, world!</h1>
9
- </source>
10
-
11
- Which will return (indented for clarity):
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:
12
13
 
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>
14
+ sudo gem install redcloth
15
+
16
+
17
+ == Using
16
18
 
17
- <p>What about a multi-line code sample?</p>
19
+ You have to specify that you want to use refs_syntax_highlighter when calling RedCloth#to_html.
18
20
 
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>
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)
22
27
 
23
- This plugin overrides the built-in "textilize helper", just call it as usual, in a helper or a view:
28
+ == Example
24
29
 
25
- <%= textilize(@post.body) %>
30
+ This input:
31
+
32
+ Hello, this is *textilized*. It also has <source>@inline_code_examples</source>!
33
+
34
+ What about a multi-line code sample?
35
+
36
+ <source:html>
37
+ <h1>Hello, world!</h1>
38
+ </source>
39
+
40
+ produces this output (indented for clarity):
41
+
42
+ <p>Hello, this is <strong>textilized</strong>. It also has <code class="inline_code">
43
+ <span class="iv">@inline_code_examples</span>
44
+ </code>!</p>
45
+
46
+ <p>What about a multi-line code sample?</p>
47
+
48
+ <pre><code class=\"multiline_code\">
49
+ <span class=\"ta\">&amp;lt;h1&amp;gt;</span>Hello, world!<span class=\"ta\">&amp;lt;/h1&amp;gt;</span>
50
+ </code></pre>
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('redclothcoderay', '0.1.0') do |p|
5
+ Echoe.new('redclothcoderay', '0.1.1') do |p|
6
6
  p.description = "Integrates CodeRay with RedCloth by adding a <source> tag."
7
7
  p.url = "http://redclothcoderay.rubyforge.org/"
8
8
  p.author = "August Lilleaas"
@@ -1,7 +1,28 @@
1
- $: << File.join(File.dirname(__FILE__), 'redcloth_with_coderay')
1
+ class String
2
+ # Utility method to check if a string contains newlines.
3
+ def contains_newlines?
4
+ self =~ /\n/
5
+ end
6
+ end
2
7
 
3
- require 'redcloth_extension'
4
- require 'customized_textile_helper'
8
+ module RedclothWithCoderay
9
+ SINGLE_LINE = '<code class="inline_code">%s</code>'
10
+ MULTI_LINE = '<pre><code class="multiline_code">%s</code></pre>'
11
+ WRAPPER = '<notextile>%s</notextile>'
12
+ SOURCE_TAG_REGEXP = /([\t\n]?<source(?:\:([a-z]+))?>(.+?)<\/source>[\t\n]?)/m
13
+
14
+ # The RedCloth extension that performs the syntax highlighting.
15
+ def refs_syntax_highlighter(text)
16
+ text.gsub!(SOURCE_TAG_REGEXP) do |m|
17
+ all_of_it = $~[1]
18
+ lang = ($~[2] || :ruby).to_sym
19
+ code = $~[3].strip
20
+
21
+ wrap_in = all_of_it.contains_newlines? ? MULTI_LINE : SINGLE_LINE
22
+ highlighted = wrap_in % CodeRay.scan(code, lang).div(:wrap => nil, :css => :class)
23
+ WRAPPER % highlighted
24
+ end
25
+ end
26
+ end
5
27
 
6
- RedCloth.class_eval { include RedclothWithCoderay }
7
- ActionView::Helpers.class_eval { include CustomizedTextileHelper }
28
+ RedCloth.class_eval { include RedclothWithCoderay }
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{redclothcoderay}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["August Lilleaas"]
9
9
  s.date = %q{2008-11-18}
10
10
  s.description = %q{Integrates CodeRay with RedCloth by adding a <source> tag.}
11
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"]
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", "redclothcoderay.gemspec", "test/redclothcoderay_test.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://redclothcoderay.rubyforge.org/}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Redclothcoderay", "--main", "README"]
@@ -3,9 +3,6 @@ require 'redcloth'
3
3
  require 'coderay'
4
4
  require 'test/unit'
5
5
 
6
- require 'action_controller'
7
- require 'action_controller/test_process'
8
-
9
6
  current_directory = File.dirname(__FILE__)
10
7
  $:.unshift File.join(current_directory, '..', 'lib')
11
8
  require 'redcloth_with_coderay'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leethal-redclothcoderay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - August Lilleaas
@@ -46,20 +46,18 @@ executables: []
46
46
  extensions: []
47
47
 
48
48
  extra_rdoc_files:
49
- - lib/redcloth_with_coderay/customized_textile_helper.rb
50
- - lib/redcloth_with_coderay/redcloth_extension.rb
49
+ - CHANGELOG
51
50
  - lib/redcloth_with_coderay.rb
52
51
  - README
53
52
  files:
54
- - lib/redcloth_with_coderay/customized_textile_helper.rb
55
- - lib/redcloth_with_coderay/redcloth_extension.rb
53
+ - CHANGELOG
56
54
  - lib/redcloth_with_coderay.rb
57
55
  - Manifest
58
56
  - MIT-LICENSE
59
57
  - Rakefile
60
58
  - README
61
- - test/redclothcoderay_test.rb
62
59
  - redclothcoderay.gemspec
60
+ - test/redclothcoderay_test.rb
63
61
  has_rdoc: true
64
62
  homepage: http://redclothcoderay.rubyforge.org/
65
63
  post_install_message:
@@ -1,5 +0,0 @@
1
- module CustomizedTextileHelper
2
- def textilize(text)
3
- RedCloth.new(text).to_html(:textile, :refs_syntax_highlighter)
4
- end
5
- end
@@ -1,24 +0,0 @@
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