Skip to content

Commit

Permalink
Merge pull request #1139 from github/kivikakk/pass-symlink
Browse files Browse the repository at this point in the history
Pass through symlink info
  • Loading branch information
Ashe Connor authored Jan 30, 2018
2 parents 968ba4e + 6704f82 commit 50cb58f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ gem "rdoc", "~>3.6"
gem "org-ruby", "= 0.9.9"
gem "creole", "~>0.3.6"
gem "wikicloth", "=0.8.3"
gem "twitter-text", "~> 1.14"
gem "asciidoctor", "= 1.5.6.1"
gem "rake"
2 changes: 1 addition & 1 deletion github-markup.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'sanitize', '~> 2.1', '>= 2.1.0'
s.add_development_dependency 'nokogiri', '1.6.8.1'
s.add_development_dependency 'nokogiri-diff', '~> 0.2.0'
s.add_development_dependency "github-linguist", "~> 5.0", ">= 5.0.8"
s.add_development_dependency "github-linguist", "~> 6.0"
end
17 changes: 9 additions & 8 deletions lib/github/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def preload!
end
end

def render(filename, content = nil)
def render(filename, content = nil, symlink = nil)
content ||= File.read(filename)
symlink = (File.symlink?(filename) rescue false) if symlink.nil?

if impl = renderer(filename, content)
if impl = renderer(filename, content, symlink)
impl.render(filename, content)
else
content
Expand Down Expand Up @@ -79,20 +80,20 @@ def command(symbol, command, regexp, languages, name, &block)
markup_impl(symbol, CommandImplementation.new(regexp, languages, command, name, &block))
end

def can_render?(filename, content)
!!renderer(filename, content)
def can_render?(filename, content, symlink = false)
!!renderer(filename, content, symlink)
end

def renderer(filename, content)
language = language(filename, content)
def renderer(filename, content, symlink = false)
language = language(filename, content, symlink)
markup_impls.find { |impl|
impl.match?(filename, language)
}
end

def language(filename, content)
def language(filename, content, symlink = false)
if defined?(::Linguist)
blob = Linguist::Blob.new(filename, content)
blob = Linguist::Blob.new(filename, content, symlink: symlink)
return Linguist.detect(blob, allow_empty: true)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/markup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_raises_error_if_command_exits_non_zero
GitHub::Markup.command(:doesntmatter, 'test/fixtures/fail.sh', /fail/, ['Java'], 'fail')
assert GitHub::Markup.can_render?('README.java', 'stop swallowing errors')
begin
GitHub::Markup.render('README.java', "stop swallowing errors")
GitHub::Markup.render('README.java', "stop swallowing errors", false)
rescue GitHub::Markup::CommandError => e
assert_equal "failure message", e.message
else
Expand Down

0 comments on commit 50cb58f

Please sign in to comment.