File tree Expand file tree Collapse file tree 5 files changed +82
-97
lines changed
rdoc/generator/template/rails Expand file tree Collapse file tree 5 files changed +82
-97
lines changed Original file line number Diff line number Diff line change 170
170
</ div >
171
171
<% end %>
172
172
173
- <% if method . token_stream %>
174
- <% markup = method . markup_code %>
175
- < div class ="sourcecode ">
176
- <%
177
- # generate github link
178
- github = if options . github
179
- if markup =~ /File\s (\S +), line (\d +)/
180
- path = $1
181
- line = $2. to_i
182
- end
183
- path && github_url ( path )
184
- else
185
- false
186
- end
187
- %>
188
- < p class ="source-link ">
189
- Source:
190
- <% if github %>
191
- < a href ="<%= "#{ github } #L#{ line } " %> " target ="_blank " class ="github_url "> on GitHub</ a >
192
- <% end %>
193
- </ p >
194
- < div id ="<%= method . aref %> _source ">
195
- < pre > < code class ="ruby "> <%= markup %> </ code > </ pre >
196
- </ div >
197
- </ div >
198
- <% end %>
199
- </ div >
173
+ <% source_code , source_url = method_source_code_and_url ( method ) %>
174
+ <% if source_code %>
175
+ < details class ="method__source ">
176
+ < summary >
177
+ < span class ="label "> Source code</ span >
178
+ </ summary >
179
+
180
+ < pre > < code class ="ruby "> <%= source_code %> </ code > </ pre >
181
+ <% if source_url %>
182
+ < a href ="<%= source_url %> " target ="_blank " class ="github_url "> See on GitHub</ a >
183
+ <% end %>
184
+ </ details >
185
+ <% elsif source_url %>
186
+ < a href ="<%= source_url %> " target ="_blank " class ="github_url "> See on GitHub</ a >
187
+ <% end %>
188
+ </ div >
200
189
<% end %> <%# methods.each %>
201
190
<% end %> <%# visibilities.each %>
202
191
<% end %> <%# context.methods_by_type %>
Original file line number Diff line number Diff line change 3
3
require 'fileutils'
4
4
require 'json'
5
5
6
- require 'sdoc/github'
7
6
require 'sdoc/templatable'
8
7
require 'sdoc/helpers'
9
8
require 'sdoc/version'
@@ -28,7 +27,6 @@ class RDoc::Generator::SDoc
28
27
DESCRIPTION = 'Searchable HTML documentation'
29
28
30
29
include ERB ::Util
31
- include SDoc ::GitHub
32
30
include SDoc ::Templatable
33
31
include SDoc ::Helpers
34
32
@@ -55,13 +53,16 @@ def self.setup_options(options)
55
53
opt = options . option_parser
56
54
opt . separator nil
57
55
opt . separator "SDoc generator options:"
56
+
57
+ # FIXME: Use options
58
+ # options.github = true
58
59
opt . separator nil
59
60
opt . on ( "--github" , "-g" ,
60
61
"Generate links to github." ) do |value |
61
62
options . github = true
62
63
end
63
- opt . separator nil
64
64
65
+ opt . separator nil
65
66
opt . on ( "--version" , "-v" , "Output current version" ) do
66
67
puts SDoc ::VERSION
67
68
exit
@@ -109,7 +110,7 @@ def file_dir
109
110
FILE_DIR
110
111
end
111
112
112
- private
113
+ private
113
114
114
115
### Output progress information if debugging is enabled
115
116
def debug_msg ( *msg )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
module SDoc ::Helpers
2
+ require_relative "helpers/git"
3
+ include ::SDoc ::Helpers ::Git
4
+
2
5
# Strips out HTML tags from a given string.
3
6
#
4
7
# Example:
@@ -21,12 +24,13 @@ def truncate(text, options = {})
21
24
end
22
25
end
23
26
24
- protected
25
- def group_name name
26
- if match = name . match ( /^([a-z])/i )
27
- match [ 1 ] . upcase
28
- else
29
- '#'
27
+ def method_source_code_and_url ( rdoc_method )
28
+ source_code = rdoc_method . tokens_to_s if rdoc_method . token_stream
29
+
30
+ if source_code &.match ( /File\s (\S +), line (\d +)/ )
31
+ source_url = github_url ( Regexp . last_match ( 1 ) , line : Regexp . last_match ( 2 ) )
30
32
end
33
+
34
+ [ rdoc_method . instance_of? ( RDoc ::GhostMethod ) ? nil : source_code , source_url ]
31
35
end
32
36
end
Original file line number Diff line number Diff line change
1
+ module SDoc ::Helpers ::Git
2
+ def github_url ( relative_path , line : nil )
3
+ return unless github?
4
+ line = "#L#{ line } " if line
5
+ "https://github.com/#{ github_repository } /blob/#{ git_head_sha1 } /#{ relative_path } #{ line } "
6
+ end
7
+
8
+ def github?
9
+ @options . github && git? && github_repository
10
+ end
11
+
12
+ attr_writer :git_repo_path
13
+
14
+ def git?
15
+ @git_repo_path ||= Dir . chdir ( @options . root ) { `git rev-parse --show-toplevel 2> /dev/null` . chomp }
16
+ !@git_repo_path . empty?
17
+ end
18
+
19
+ def git_command ( command )
20
+ Dir . chdir ( @options . root ) { `git #{ command } ` . chomp } if git?
21
+ end
22
+
23
+ attr_writer :git_head_branch
24
+
25
+ def git_head_branch
26
+ @git_head_branch ||= git_command ( "rev-parse --abbrev-ref HEAD" )
27
+ end
28
+
29
+ attr_writer :git_head_sha1
30
+
31
+ def git_head_sha1
32
+ @git_head_sha1 ||= git_command ( "rev-parse HEAD" )
33
+ end
34
+
35
+ attr_writer :git_head_timestamp
36
+
37
+ def git_head_timestamp
38
+ @git_head_timestamp ||= git_command ( "show -s --format=%cI HEAD" )
39
+ end
40
+
41
+ attr_writer :git_origin_url
42
+
43
+ def git_origin_url
44
+ @git_origin_url ||= git_command ( "config --get remote.origin.url" )
45
+ end
46
+
47
+ def github_repository
48
+ return @github_repository if defined? ( @github_repository )
49
+ @github_repository = git_origin_url . chomp ( ".git" ) [ %r"github\. com[/:](.+)" , 1 ]
50
+ end
51
+ end
You can’t perform that action at this time.
0 commit comments