Skip to content

Commit

Permalink
don't include the line number in the link if it's not given
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jun 20, 2009
1 parent 2b23b4a commit 5f1e88c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions lib/base/base_template.rb
Expand Up @@ -100,19 +100,27 @@ def inline_css(css)
# @return String
# An anchor link to a textmate reference or a file reference
def link_to_filename(name, line = nil, link_content = nil)
link_content ||= "#{name}:#{line}"
"<a href='#{file_url(name, line)}'>#{link_content}</a>"
"<a href='#{file_url(name, line)}'>#{link_content(name, line, link_content)}</a>"
end

def file_url(name, line)
def link_content(name, line=nil, link_content=nil) # :nodoc:
if link_content
link_content
elsif line
"#{name}:#{line}"
else
name
end
end

def file_url(name, line) # :nodoc:
filename = File.expand_path(name.gsub(/^\//, ''))
if MetricFu.configuration.platform.include?('darwin')
"txmt://open/?url=file://#{filename}&line=#{line}"
"txmt://open/?url=file://#{filename}" << (line ? "&line=#{line}" : "")
else
"file://#{filename}"
end
end


# Provides a brain dead way to cycle between two values during
# an iteration of some sort. Pass in the first_value, the second_value,
Expand Down
6 changes: 3 additions & 3 deletions spec/base/base_template_spec.rb
Expand Up @@ -95,14 +95,14 @@
File.stub(:expand_path).with('filename').and_return('/expanded/filename')
result = @template.send(:link_to_filename, 'filename')
result.should eql("<a href='txmt://open/?url=file://" \
+ "/expanded/filename&line='>filename:</a>")
+ "/expanded/filename'>filename</a>")
end

it "should do the right thing with a filename that starts with a slash" do
File.stub(:expand_path).with('filename').and_return('/expanded/filename')
result = @template.send(:link_to_filename, '/filename')
result.should eql("<a href='txmt://open/?url=file://" \
+ "/expanded/filename&line='>/filename:</a>")
+ "/expanded/filename'>/filename</a>")
end

it "should include a line number" do
Expand Down Expand Up @@ -133,7 +133,7 @@
it 'should return a file protocol link' do
name = "filename"
result = @template.send(:link_to_filename, name)
result.should == "<a href='file://filename'>filename:</a>"
result.should == "<a href='file://filename'>filename</a>"
end
end
end
Expand Down

0 comments on commit 5f1e88c

Please sign in to comment.