Skip to content

Commit

Permalink
[DocBuilder] "Show on GitHub" links now link to line-ranges (fixes #198)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Apr 7, 2015
1 parent bd1366a commit 73001fc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
[segiddins](https://github.com/segiddins)
[#196](https://github.com/realm/jazzy/issues/196)

* "Show on GitHub" links now link to line-ranges for multi-line definitions.
[JP Simard](https://github.com/jpsim)
[#198](https://github.com/realm/jazzy/issues/198)

##### Bug Fixes

* Fixed issue where docset would contain duplicate files.
Expand Down
2 changes: 1 addition & 1 deletion lib/jazzy/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def self.parse!
end

opt.on('-s', '--sourcekitten-sourcefile FILEPATH',
'XML doc file generated from sourcekitten to parse') do |s|
'File generated from sourcekitten output to parse') do |s|
config.sourcekitten_sourcefile = Pathname(s)
end

Expand Down
14 changes: 9 additions & 5 deletions lib/jazzy/doc_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ def self.prepare_output_dir(output_dir, clean)
# @return [Array] doc structure comprised of
# section names & child names & URLs
def self.doc_structure_for_docs(docs)
structure = []
docs.each do |doc|
structure << {
docs.map do |doc|
{
section: doc.name,
children: doc.children.sort_by(&:name).map do |child|
{ name: child.name, url: child.url }
end,
}
end
structure
end

# Build documentation from the given options
Expand Down Expand Up @@ -205,7 +203,11 @@ def self.should_link_to_github(file)
def self.gh_token_url(item, source_module)
if source_module.github_file_prefix && should_link_to_github(item.file)
relative_file_path = item.file.gsub(`pwd`.strip, '')
gh_line = "#L#{item.line}"
if item.start_line && (item.start_line != item.end_line)
gh_line = "#L#{item.start_line}-L#{item.end_line}"
else
gh_line = "#L#{item.line}"
end
source_module.github_file_prefix + relative_file_path + gh_line
end
end
Expand All @@ -228,6 +230,8 @@ def self.render_item(item, source_module)
item_render[:return] = Jazzy.markdown.render(item.return) if item.return
item_render[:parameters] = item.parameters if item.parameters.any?
item_render[:url] = item.url if item.children.any?
item_render[:start_line] = item.start_line
item_render[:end_line] = item.end_line
item_render.reject { |_, v| v.nil? }
end

Expand Down
2 changes: 2 additions & 0 deletions lib/jazzy/source_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SourceDeclaration
attr_accessor :url
attr_accessor :mark
attr_accessor :access_control_level
attr_accessor :start_line
attr_accessor :end_line

def overview
"#{abstract}\n\n#{discussion}".strip
Expand Down
2 changes: 2 additions & 0 deletions lib/jazzy/sourcekitten.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def self.make_source_declarations(docs)
doc['key.annotated_decl'],
)
declaration.access_control_level = acl
declaration.start_line = doc['key.parsed_scope.start']
declaration.end_line = doc['key.parsed_scope.end']

next unless make_doc_info(doc, declaration)
make_substructure(doc, declaration)
Expand Down
2 changes: 1 addition & 1 deletion spec/integration_specs

0 comments on commit 73001fc

Please sign in to comment.