Skip to content

Commit ab67c57

Browse files
Merge pull request #270 from jonathanhefner/banner-prefer-badge_version
Prefer `ENV["HORO_BADGE_VERSION"]` version in banner
2 parents a1c937a + 5042d1e commit ab67c57

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

lib/rdoc/generator/template/rails/class.rhtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
<div class="banner">
2222
<% if project_name %>
23-
<div><%= project_name %> <%= project_version %></div>
23+
<div>
24+
<%= project_name %>
25+
<span title="<%= project_git_head %>"><%= badge_version || project_version %></span>
26+
</div>
2427
<% end %>
2528

2629
<h2>

lib/rdoc/generator/template/rails/file.rhtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
<div class="banner">
1919
<% if project_name %>
20-
<div><%= project_name %> <%= project_version %></div>
20+
<div>
21+
<%= project_name %>
22+
<span title="<%= project_git_head %>"><%= badge_version || project_version %></span>
23+
</div>
2124
<% end %>
2225

2326
<h2>

lib/rdoc/generator/template/rails/index.rhtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
<div class="banner">
1717
<% if project_name %>
18-
<div><%= project_name %> <%= project_version %></div>
18+
<div>
19+
<%= project_name %>
20+
<span title="<%= project_git_head %>"><%= badge_version || project_version %></span>
21+
</div>
1922
<% end %>
2023

2124
<h2>

lib/sdoc/helpers.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def badge_version
4141
h(ENV["HORO_BADGE_VERSION"]) if ENV["HORO_BADGE_VERSION"]
4242
end
4343

44+
def project_git_head
45+
h "#{git_head_branch}@#{git_head_sha1[0, 12]}" if git?
46+
end
47+
4448
def page_title(title = nil)
4549
h [title, @options.title].compact.join(" - ")
4650
end

lib/sdoc/helpers/git.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def git_command(command)
2020
Dir.chdir(@options.root) { `git #{command}`.chomp } if git?
2121
end
2222

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+
2329
attr_writer :git_head_sha1
2430

2531
def git_head_sha1

spec/helpers_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,26 @@ module Foo; module Bar; module Qux; end; end; end
229229
end
230230
end
231231

232+
describe "#project_git_head" do
233+
it "returns the branch name and abbreviated SHA1 of the most recent commit in HEAD" do
234+
@helpers.git_bin_path = "path/to/git"
235+
@helpers.git_head_branch = "1-0-stable"
236+
@helpers.git_head_sha1 = "1337c0d3d00d" * 3
237+
238+
_(@helpers.project_git_head).must_equal "1-0-stable@1337c0d3d00d"
239+
end
240+
241+
it "returns the branch name and abbreviated SHA1 of the most recent commit in HEAD (smoke test)" do
242+
_(@helpers.project_git_head).must_match %r"\A.+@[[:xdigit:]]{12}\z"
243+
end
244+
245+
it "returns nil when git is not installed" do
246+
@helpers.git_bin_path = ""
247+
248+
_(@helpers.project_git_head).must_be_nil
249+
end
250+
end
251+
232252
describe "#page_title" do
233253
it "includes options.title" do
234254
@helpers.options.title = "My Docs"

0 commit comments

Comments
 (0)