Skip to content

Commit 4d1ab30

Browse files
committed
Replace the :repository_url option by :src_code_href option which takes a proc rather than a string.
1 parent e69c25e commit 4d1ab30

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

Rakefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ require 'lib/pdoc'
44
desc "Builds the documentation"
55
task :build_doc do
66
PDoc.run({
7-
:source_files => [File.expand_path(File.join(File.dirname(__FILE__), "test", "fixtures", "ajax.js"))],
7+
:source_files => [File.join(File.dirname(__FILE__), "test", "fixtures", "ajax.js")],
88
:destination => OUTPUT_DIR,
99
:syntax_highlighter => :pygments,
1010
:markdown_parser => :bluecloth,
11-
:repository_url => "https://github.com/example/ex/",
11+
:src_code_href => proc { |file, line|
12+
"https://github.com/example/ex/#{file}##{line}"
13+
},
1214
:pretty_urls => false,
1315
:bust_cache => true,
1416
:name => 'Example JavaScript Framework',

lib/pdoc/models/entity.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module PDoc
22
module Models
33
class Entity < Base
44
class << Entity
5-
attr_accessor :repository_url
5+
attr_accessor :src_code_href
66
end
77

88
def signatures
@@ -14,7 +14,8 @@ def <=>(other)
1414
end
1515

1616
def src_code_href
17-
@src_code_href ||= "#{Entity.repository_url}#{@file}#LID#{@line_number}"
17+
proc = Entity.src_code_href
18+
@src_code_href ||= proc ? proc.call(@file, @line_number) : nil
1819
end
1920

2021
def signatures?

lib/pdoc/runner.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ def initialize(*source_files)
1010
@parser = Parser
1111
@serializer = Serializer
1212
@bust_cache = options.delete(:bust_cache) || false
13-
Models::Entity.repository_url = options.delete(:repository_url)
13+
Models::Entity.src_code_href = options.delete(:src_code_href)
1414
@generator_options = options
15-
1615
end
1716

1817
def serialize(files)
@@ -46,7 +45,6 @@ def run
4645
puts " Markdown parser: #{@generator_options[:markdown_parser]}"
4746
puts " Syntax highlighter: #{@generator_options[:syntax_highlighter]}"
4847
puts " Pretty urls: #{@generator_options[:pretty_urls]}"
49-
puts " Repository url: #{Models::Entity.repository_url}"
5048
puts " Index page: #{@generator_options[:index_page]}"
5149
puts " Output directory: #{@output_directory}\n\n"
5250

templates/html/partials/title.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<% end %>
1212
</ul>
1313

14-
<% if object.respond_to?(:src_code_href) %>
14+
<% if object.respond_to?(:src_code_href) && object.src_code_href %>
1515
<p id="src_code_href"><a href="<%= object.src_code_href %>">src code</a></p>
1616
<% end %>
1717

0 commit comments

Comments
 (0)