diff --git a/lib/rdoc/generator/template/rails/_head.rhtml b/lib/rdoc/generator/template/rails/_head.rhtml index 09963076..bb0449e6 100644 --- a/lib/rdoc/generator/template/rails/_head.rhtml +++ b/lib/rdoc/generator/template/rails/_head.rhtml @@ -20,3 +20,4 @@ "> <% end %> + diff --git a/lib/sdoc/helpers.rb b/lib/sdoc/helpers.rb index e92a3934..7e0ffd88 100644 --- a/lib/sdoc/helpers.rb +++ b/lib/sdoc/helpers.rb @@ -1,6 +1,6 @@ module SDoc::Helpers - require_relative "helpers/github" - include SDoc::Helpers::GitHub + require_relative "helpers/git" + include SDoc::Helpers::Git def link_to(text, url, html_attributes = {}) return h(text) if url.nil? @@ -50,6 +50,10 @@ def og_title(title) "#{h title}#{" (#{project})" unless project.empty?}" end + def og_modified_time + git_head_timestamp if git? + end + def page_description(leading_html, max_length: 160) return if leading_html.nil? || !leading_html.include?("

") diff --git a/lib/sdoc/helpers/github.rb b/lib/sdoc/helpers/git.rb similarity index 81% rename from lib/sdoc/helpers/github.rb rename to lib/sdoc/helpers/git.rb index a69508ad..def2016d 100644 --- a/lib/sdoc/helpers/github.rb +++ b/lib/sdoc/helpers/git.rb @@ -1,4 +1,4 @@ -module SDoc::Helpers::GitHub +module SDoc::Helpers::Git def github_url(relative_path, line: nil) return unless github? line = "#L#{line}" if line @@ -24,6 +24,14 @@ def git_head_sha1 end end + attr_writer :git_head_timestamp + + def git_head_timestamp + @git_head_timestamp ||= Dir.chdir(@options.root) do + `git show -s --format=%cI HEAD` .chomp + end + end + attr_writer :git_origin_url def git_origin_url diff --git a/spec/helpers_spec.rb b/spec/helpers_spec.rb index b3c8f9ce..96ff2173 100644 --- a/spec/helpers_spec.rb +++ b/spec/helpers_spec.rb @@ -270,6 +270,26 @@ module Foo; module Bar; module Qux; end; end; end end end + describe "#og_modified_time" do + it "returns the commit time of the most recent commit in HEAD" do + @helpers.git_bin_path = "path/to/git" + @helpers.git_head_timestamp = "1999-12-31T12:34:56Z" + + _(@helpers.og_modified_time).must_equal "1999-12-31T12:34:56Z" + end + + it "returns the commit time of the most recent commit in HEAD (smoke test)" do + _(@helpers.og_modified_time). + must_match %r"\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[-+]\d{2}:\d{2}\z" + end + + it "returns nil when git is not installed" do + @helpers.git_bin_path = "" + + _(@helpers.og_modified_time).must_be_nil + end + end + describe "#page_description" do it "extracts the description from the leading paragraph" do _(@helpers.page_description(<<~HTML)).must_equal "leading"