Skip to content

Commit

Permalink
Pass filename to all renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Izumi committed Apr 3, 2017
1 parent 4998caa commit 9fe0536
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/github/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def render(filename, content = nil)
content ||= File.read(filename)

if impl = renderer(filename, content)
impl.render(content)
impl.render(filename, content)
else
content
end
Expand All @@ -54,7 +54,7 @@ def render_s(symbol, content)
if content.nil?
raise ArgumentError, 'Can not render a nil.'
elsif markups.has_key?(symbol)
markups[symbol].render(content)
markups[symbol].render(nil, content)
else
content
end
Expand Down
2 changes: 1 addition & 1 deletion lib/github/markup/command_implementation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(regexp, languages, command, name, &block)
@name = name
end

def render(content)
def render(filename, content)
rendered = execute(command, content)
rendered = rendered.to_s.empty? ? content : rendered
call_block(rendered, content)
Expand Down
4 changes: 2 additions & 2 deletions lib/github/markup/gem_implementation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def load
@loaded = true
end

def render(content)
def render(filename, content)
load
renderer.call(content)
renderer.call(filename, content)
end

def name
Expand Down
2 changes: 1 addition & 1 deletion lib/github/markup/implementation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def load
# no-op by default
end

def render(content)
def render(filename, content)
raise NotImplementedError, "subclasses of GitHub::Markup::Implementation must define #render"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/github/markup/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def load
raise LoadError, "no suitable markdown gem found"
end

def render(content)
def render(filename, content)
load
@renderer.call(content)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/github/markup/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize
super(/rdoc/, ["RDoc"])
end

def render(content)
def render(filename, content)
if ::RDoc::VERSION.to_i >= 4
h = ::RDoc::Markup::ToHtml.new(::RDoc::Options.new)
else
Expand Down
10 changes: 5 additions & 5 deletions lib/github/markups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@

markup_impl(::GitHub::Markups::MARKUP_MARKDOWN, ::GitHub::Markup::Markdown.new)

markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth, /textile/, ["Textile"]) do |content|
markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth, /textile/, ["Textile"]) do |filename, content|
RedCloth.new(content).to_html
end

markup_impl(::GitHub::Markups::MARKUP_RDOC, GitHub::Markup::RDoc.new)

markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby', /org/, ["Org"]) do |content|
markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby', /org/, ["Org"]) do |filename, content|
Orgmode::Parser.new(content, {
:allow_include_files => false,
:skip_syntax_highlight => true
}).to_html
end

markup(::GitHub::Markups::MARKUP_CREOLE, :creole, /creole/, ["Creole"]) do |content|
markup(::GitHub::Markups::MARKUP_CREOLE, :creole, /creole/, ["Creole"]) do |filename, content|
Creole.creolize(content)
end

markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth, /mediawiki|wiki/, ["MediaWiki"]) do |content|
markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth, /mediawiki|wiki/, ["MediaWiki"]) do |filename, content|
wikicloth = WikiCloth::WikiCloth.new(:data => content)
WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS << 'tt' unless WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS.include?('tt')
wikicloth.to_html(:noedit => true)
end

markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor, /adoc|asc(iidoc)?/, ["AsciiDoc"]) do |content|
markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor, /adoc|asc(iidoc)?/, ["AsciiDoc"]) do |filename, content|
Asciidoctor::Compliance.unique_id_start_index = 1
Asciidoctor.convert(content, :safe => :secure, :attributes => %w(showtitle=@ idprefix idseparator=- outfilesuffix=.adoc env=github env-github source-highlighter=html-pipeline))
end
Expand Down

0 comments on commit 9fe0536

Please sign in to comment.