diff options
author | murphy <murphy@rubychan.de> | 2008-08-28 05:35:55 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2008-08-28 05:35:55 +0000 |
commit | 03ffb9431e140e09e5f1a7ae6c2d582c1895554e (patch) | |
tree | 851b2e84707d0ae983690719e32866fc1863e7d3 | |
parent | 282dfb77a71d3c9ef20aa8c0ad955e4061652b75 (diff) | |
download | coderay-03ffb9431e140e09e5f1a7ae6c2d582c1895554e.tar.gz |
Changed CodeRay.for_redcloth into require 'coderay/for_redcloth'.
* Cleanup in documentation.rake.
-rw-r--r-- | lib/coderay.rb | 1 | ||||
-rw-r--r-- | lib/coderay/for_redcloth.rb | 70 | ||||
-rw-r--r-- | rake_tasks/documentation.rake | 14 | ||||
-rwxr-xr-x | test/functional/basic.rb | 2 |
4 files changed, 40 insertions, 47 deletions
diff --git a/lib/coderay.rb b/lib/coderay.rb index df330fb..4d9aae1 100644 --- a/lib/coderay.rb +++ b/lib/coderay.rb @@ -141,7 +141,6 @@ module CodeRay require 'coderay/encoder' require 'coderay/duo' require 'coderay/style' - require 'coderay/for_redcloth' class << self diff --git a/lib/coderay/for_redcloth.rb b/lib/coderay/for_redcloth.rb index 4de597e..dd8d22f 100644 --- a/lib/coderay/for_redcloth.rb +++ b/lib/coderay/for_redcloth.rb @@ -1,54 +1,54 @@ -# A little hack to enable CodeRay highlighting in RedCloth. - -module CodeRay +module CodeRay # :nodoc: # A little hack to enable CodeRay highlighting in RedCloth. # # Usage: # require 'coderay' - # CodeRay.for_redcloth + # require 'coderay/for_redcloth' # RedCloth.new('@[ruby]puts "Hello, World!"@').to_html # # Make sure you have RedCloth 4.0.3 activated, for example by calling # require 'rubygems' # before RedCloth is loaded and before calling CodeRay.for_redcloth. - def self.for_redcloth - gem 'RedCloth', '>= 4.0.3' rescue nil - require 'redcloth' - raise 'CodeRay.for_redcloth needs RedCloth 4.0.3 or later.' unless RedCloth::VERSION.to_s >= '4.0.3' - RedCloth::TextileDoc.send :include, ForRedCloth::TextileDoc - RedCloth::Formatters::HTML.module_eval do - undef_method :code, :bc_open, :bc_close - def code(opts) - opts[:block] = true - if opts[:lang] && !filter_coderay - require 'coderay' - @in_bc ||= nil - format = @in_bc ? :div : :span - highlighted_code = CodeRay.encode opts[:text], opts[:lang], format, :stream => true - highlighted_code.sub(/\A<(span|div)/) { |m| m + pba(@in_bc || opts) } - else - "<code#{pba(opts)}>#{opts[:text]}</code>" + module ForRedCloth + + def self.install + gem 'RedCloth', '>= 4.0.3' rescue nil + require 'redcloth' + raise 'CodeRay.for_redcloth needs RedCloth 4.0.3 or later.' unless RedCloth::VERSION.to_s >= '4.0.3' + RedCloth::TextileDoc.send :include, ForRedCloth::TextileDoc + RedCloth::Formatters::HTML.module_eval do + undef_method :code, :bc_open, :bc_close + def code(opts) # :nodoc: + opts[:block] = true + if opts[:lang] && !filter_coderay + require 'coderay' + @in_bc ||= nil + format = @in_bc ? :div : :span + highlighted_code = CodeRay.encode opts[:text], opts[:lang], format, :stream => true + highlighted_code.sub(/\A<(span|div)/) { |m| m + pba(@in_bc || opts) } + else + "<code#{pba(opts)}>#{opts[:text]}</code>" + end + end + def bc_open(opts) # :nodoc: + opts[:block] = true + @in_bc = opts + opts[:lang] ? '' : "<pre#{pba(opts)}>" + end + def bc_close(opts) # :nodoc: + @in_bc = nil + opts[:lang] ? '' : "</pre>\n" end - end - def bc_open(opts) - opts[:block] = true - @in_bc = opts - opts[:lang] ? '' : "<pre#{pba(opts)}>" - end - def bc_close(opts) - @in_bc = nil - opts[:lang] ? '' : "</pre>\n" end end - end - - module ForRedCloth # :nodoc: - - module TextileDoc # :nodoc: + + module TextileDoc # :nodoc: attr_accessor :filter_coderay end end end + +CodeRay::ForRedCloth.install
\ No newline at end of file diff --git a/rake_tasks/documentation.rake b/rake_tasks/documentation.rake index ab09c46..af4e229 100644 --- a/rake_tasks/documentation.rake +++ b/rake_tasks/documentation.rake @@ -3,7 +3,7 @@ require 'pathname' CODERAY_TEMPLATE = Pathname.new(File.dirname(__FILE__)).join('..', 'rake_helpers', 'coderay_rdoc_template.rb').expand_path.to_s
-def set_rdoc_info rd, small = false
+def set_rdoc_info rd
rd.main = 'README'
rd.title = "CodeRay Documentation"
rd.options << '--line-numbers' << '--inline-source' << '--tab-width' << '2'
@@ -11,8 +11,8 @@ def set_rdoc_info rd, small = false rd.options << '--all'
rd.template = ENV.fetch('template', CODERAY_TEMPLATE)
- rd.rdoc_files.add *EXTRA_FILES.in(ROOT)
- rd.rdoc_files.add *Dir[File.join(LIB_ROOT, "#{'**/' unless small}*.rb")]
+ rd.rdoc_files.add(*EXTRA_FILES.in(ROOT))
+ rd.rdoc_files.add(*Dir[File.join(LIB_ROOT, "**/*.rb")])
end
namespace :doc do
@@ -23,12 +23,6 @@ namespace :doc do rd.rdoc_dir = 'doc/all'
end
- desc 'Generate test documentation for CodeRay (faster)'
- Rake::RDocTask.new :small do |rd|
- set_rdoc_info rd, true
- rd.rdoc_dir = 'doc/small'
- end
-
desc 'Upload rdoc to ' + FTP_DOMAIN
task :upload => :all do
gn 'Uploading documentation:'
@@ -37,7 +31,7 @@ namespace :doc do uploader = uploader_for ftp
ftp.chdir FTP_CODERAY_DIR
ftp.chdir 'doc'
- Dir['**/*.*'].each &uploader
+ Dir['**/*.*'].each(&uploader)
end
end
gn 'Documentation uploaded.'
diff --git a/test/functional/basic.rb b/test/functional/basic.rb index 07818ea..2880c77 100755 --- a/test/functional/basic.rb +++ b/test/functional/basic.rb @@ -36,7 +36,7 @@ class BasicTest < Test::Unit::TestCase def test_for_redcloth require 'rubygems' - CodeRay.for_redcloth + require 'coderay/for_redcloth' assert_equal '<p><span lang="ruby" class="CodeRay">puts <span style="background-color:#fff0f0"><span style="color:#710">"</span><span style="color:#D20">Hello, World!</span><span style="color:#710">"</span></span></span></p>', RedCloth.new('@[ruby]puts "Hello, World!"@').to_html end |