Skip to content

Commit

Permalink
add markdown support to sdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Oct 5, 2009
1 parent cb2af98 commit e31e902
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions Rakefile
@@ -1,4 +1,5 @@
require 'rake/testtask' require 'rake/testtask'
require 'rake/rdoctask'


task :default => :test task :default => :test


Expand All @@ -25,12 +26,42 @@ rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end end


desc "Build sdoc documentation" begin
task :doc do require 'sdoc'
File.open('README.html', 'w') do |f| Rake::RDocTask.new do |rdoc|
require 'rdiscount' rdoc.main = 'README.md'
f.puts Markdown.new(File.read('README.md')).to_html rdoc.rdoc_files = %w( README.md LICENSE lib )
rdoc.rdoc_dir = 'docs'
end end
rescue LoadError
puts "sdoc support not enabled. Please install sdoc."
end


exec "sdoc -N --main=README.html README.html LICENSE lib" ##
# Markdown support for sdoc. Renders files ending in .md or .markdown
# with RDiscount.
module SDoc
module MarkdownSupport
def description
return super unless full_name =~ /\.(md|markdown)$/
# assuming your path is ROOT/html or ROOT/doc
path = Dir.pwd + '/../' + full_name
Markdown.new(File.read(path)).to_html + open_links_in_new_window
end

def open_links_in_new_window
<<-html
<script type="text/javascript">$(function() {
$('a').each(function() { $(this).attr('target', '_blank') })
})</script>
html
end
end
end

begin
require 'rdiscount'
RDoc::TopLevel.send :include, SDoc::MarkdownSupport
rescue LoadError
puts "Markdown support not enabled. Please install RDiscount."
end end

0 comments on commit e31e902

Please sign in to comment.