diff --git a/lib/github/markup.rb b/lib/github/markup.rb index 82de5172..a2ead501 100644 --- a/lib/github/markup.rb +++ b/lib/github/markup.rb @@ -30,12 +30,12 @@ def markup(file, pattern, opts = {}, &block) markups << GemImplementation.new(pattern, file, &block) end - def command(command, regexp, &block) + def command(command, regexp, name, &block) if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}") command = file end - markups << CommandImplementation.new(regexp, command, &block) + markups << CommandImplementation.new(regexp, command, name, &block) end def can_render?(filename) diff --git a/lib/github/markup/command_implementation.rb b/lib/github/markup/command_implementation.rb index 92e1923d..1692ad1a 100644 --- a/lib/github/markup/command_implementation.rb +++ b/lib/github/markup/command_implementation.rb @@ -12,12 +12,13 @@ class CommandError < RuntimeError end class CommandImplementation < Implementation - attr_reader :command, :block + attr_reader :command, :block, :name - def initialize(regexp, command, &block) + def initialize(regexp, command, name, &block) super regexp @command = command.to_s @block = block + @name = name end def render(content) diff --git a/lib/github/markup/gem_implementation.rb b/lib/github/markup/gem_implementation.rb index a9f80b75..270f5a88 100644 --- a/lib/github/markup/gem_implementation.rb +++ b/lib/github/markup/gem_implementation.rb @@ -21,6 +21,10 @@ def render(content) load renderer.call(content) end + + def name + gem_name + end end end end diff --git a/lib/github/markup/markdown.rb b/lib/github/markup/markdown.rb index f2744ca3..8ccf7f07 100644 --- a/lib/github/markup/markdown.rb +++ b/lib/github/markup/markdown.rb @@ -44,6 +44,10 @@ def render(content) @renderer.call(content) end + def name + "markdown" + end + private def try_require(file) require file diff --git a/lib/github/markup/rdoc.rb b/lib/github/markup/rdoc.rb index 5bf14639..5448f455 100644 --- a/lib/github/markup/rdoc.rb +++ b/lib/github/markup/rdoc.rb @@ -1,20 +1,25 @@ +require "github/markup/implementation" require "rdoc" require "rdoc/markup/to_html" module GitHub module Markup - class RDoc - def initialize(content) - @content = content + class RDoc < Implementation + def initialize + super /rdoc/ end - def to_html + def render(content) if ::RDoc::VERSION.to_i >= 4 h = ::RDoc::Markup::ToHtml.new(::RDoc::Options.new) else h = ::RDoc::Markup::ToHtml.new end - h.convert(@content) + h.convert(content) + end + + def name + "rdoc" end end end diff --git a/lib/github/markups.rb b/lib/github/markups.rb index eb562909..0165f4a4 100644 --- a/lib/github/markups.rb +++ b/lib/github/markups.rb @@ -1,4 +1,5 @@ require "github/markup/markdown" +require "github/markup/rdoc" require "shellwords" markups << GitHub::Markup::Markdown.new @@ -7,13 +8,11 @@ RedCloth.new(content).to_html end -markup('github/markup/rdoc', /rdoc/) do |content| - GitHub::Markup::RDoc.new(content).to_html -end +markups << GitHub::Markup::RDoc.new markup('org-ruby', /org/) do |content| - Orgmode::Parser.new(content, { - :allow_include_files => false, + Orgmode::Parser.new(content, { + :allow_include_files => false, :skip_syntax_highlight => true }).to_html end @@ -30,14 +29,18 @@ Asciidoctor.render(content, :safe => :secure, :attributes => %w(showtitle idprefix idseparator=- env=github env-github source-highlighter=html-pipeline)) end -command("python2 -S #{Shellwords.escape(File.dirname(__FILE__))}/commands/rest2html", /re?st(\.txt)?/) +command( + "python2 -S #{Shellwords.escape(File.dirname(__FILE__))}/commands/rest2html", + /re?st(\.txt)?/, + "restructuredtext" +) # pod2html is nice enough to generate a full-on HTML document for us, # so we return the favor by ripping out the good parts. # # Any block passed to `command` will be handed the command's STDOUT for # post processing. -command('/usr/bin/env perl -MPod::Simple::HTML -e Pod::Simple::HTML::go', /pod/) do |rendered| +command('/usr/bin/env perl -MPod::Simple::HTML -e Pod::Simple::HTML::go', /pod/, "pod") do |rendered| if rendered =~ /\s*(.+)\s*/mi $1 end diff --git a/test/markup_test.rb b/test/markup_test.rb index 3d24b7a6..4c8fdf45 100644 --- a/test/markup_test.rb +++ b/test/markup_test.rb @@ -85,8 +85,20 @@ def test_knows_what_it_can_and_cannot_render assert_equal true, GitHub::Markup.can_render?('README.litcoffee') end + def test_each_render_has_a_name + assert_equal "markdown", GitHub::Markup.renderer('README.md').name + assert_equal "redcloth", GitHub::Markup.renderer('README.textile').name + assert_equal "rdoc", GitHub::Markup.renderer('README.rdoc').name + assert_equal "org-ruby", GitHub::Markup.renderer('README.org').name + assert_equal "creole", GitHub::Markup.renderer('README.creole').name + assert_equal "wikicloth", GitHub::Markup.renderer('README.wiki').name + assert_equal "asciidoctor", GitHub::Markup.renderer('README.adoc').name + assert_equal "restructuredtext", GitHub::Markup.renderer('README.rst').name + assert_equal "pod", GitHub::Markup.renderer('README.pod').name + end + def test_raises_error_if_command_exits_non_zero - GitHub::Markup.command('test/fixtures/fail.sh', /fail/) + GitHub::Markup.command('test/fixtures/fail.sh', /fail/, 'fail') assert GitHub::Markup.can_render?('README.fail') begin GitHub::Markup.render('README.fail', "stop swallowing errors")