lib/giblish/buildindex.rb in giblish-0.2.7 vs lib/giblish/buildindex.rb in giblish-0.2.8

- old
+ new

@@ -3,10 +3,11 @@ require "pathname" require "git" require_relative "cmdline" require_relative "pathtree" +require_relative "gititf" # Container class for bundling together the data we cache for # each asciidoc file we come across class DocInfo # Cache git info @@ -37,15 +38,16 @@ end # Base class with common functionality for all index builders class BasicIndexBuilder # set up the basic index building info - def initialize(path_manager) + def initialize(path_manager, handle_docid = false) @paths = path_manager @nof_missing_titles = 0 @added_docs = [] @src_str = "" + @manage_docid = handle_docid end # creates a DocInfo instance, fills it with basic info and # returns the filled in instance so that derived implementations can # add more data @@ -55,13 +57,10 @@ info = DocInfo.new info.converted = true info.stderr = adoc_stderr - # Get the doc id if it exists - info.doc_id = adoc.attributes["docid"] - # Get the purpose info if it exists info.purpose_str = get_purpose_info adoc # Get the relative path beneath the root dir to the doc d_attr = adoc.attributes @@ -69,14 +68,24 @@ "#{d_attr['outdir']}/#{d_attr['docname']}#{d_attr['docfilesuffix']}" ).relative_path_from( @paths.dst_root_abs ) - # Get the source file path and title + # Get the doc id if it exists + info.doc_id = adoc.attributes["docid"] + + # Get the source file path info.srcFile = adoc.attributes["docfile"] - info.title = adoc.doctitle + # If a docid exists, set titel to docid - title if we care about + # doc ids. + info.title = if !info.doc_id.nil? && @manage_docid + "#{info.doc_id} - #{adoc.doctitle}" + else + adoc.doctitle + end + # Cache the created DocInfo @added_docs << info info end @@ -129,10 +138,12 @@ adoc.blocks.each do |section| next unless section.is_a?(Asciidoctor::Section) && (section.level == 1) && (section.name =~ /^Purpose$/) purpose_str = "Purpose::\n\n" + + # filter out 'odd' text, such as lists etc... section.blocks.each do |bb| next unless bb.is_a?(Asciidoctor::Block) purpose_str << "#{bb.source}\n+\n" end end @@ -292,24 +303,24 @@ end end # A simple index generator that shows a table with the generated documents class SimpleIndexBuilder < BasicIndexBuilder - def initialize(path_manager) - super path_manager + def initialize(path_manager, manage_docid = false) + super path_manager, manage_docid end def add_doc(adoc, adoc_stderr) super(adoc, adoc_stderr) end end # Builds an index of the generated documents and includes some git metadata # repository class GitRepoIndexBuilder < BasicIndexBuilder - def initialize(path_manager, git_repo_root) - super path_manager + def initialize(path_manager, manage_docid, git_repo_root) + super path_manager, manage_docid # initialize state variables @git_repo_root = git_repo_root # no repo root given... @@ -329,16 +340,25 @@ # Redefine the srcFile to mean the relative path to the git repo root info.srcFile = Pathname.new(info.srcFile).relative_path_from(@git_repo_root).to_s # Get the commit history of the doc - @git_repo.log(50).object("*#{info.srcFile}").each do |l| + # (use a homegrown git log to get 'follow' flag) + gi = Giblish::GitItf.new(@git_repo_root) + gi.file_log(info.srcFile.to_s).each do |i| h = DocInfo::DocHistory.new - h.date = l.date - h.message = l.message - h.author = l.author.name + h.date = i["date"] + h.message = i["message"] + h.author = i["author"] info.history << h end + # @git_repo.log(50).object("*#{info.srcFile}").each do |l| + # h = DocInfo::DocHistory.new + # h.date = l.date + # h.message = l.message + # h.author = l.author.name + # info.history << h + # end end protected def generate_header