lib/giblish/buildindex.rb in giblish-0.3.1 vs lib/giblish/buildindex.rb in giblish-0.4.0

- old
+ new

@@ -8,50 +8,85 @@ module Giblish # Base class with common functionality for all index builders class BasicIndexBuilder # set up the basic index building info - def initialize(processed_docs, path_manager, handle_docid = false) + def initialize(processed_docs, converter, path_manager, handle_docid = false) @paths = path_manager @nof_missing_titles = 0 @processed_docs = processed_docs + @converter = converter @src_str = "" @manage_docid = handle_docid end - def source(dep_graph_exists = false) + def source(dep_graph_exists = false, make_searchable = false) <<~DOC_STR - #{generate_header} + #{generate_title_and_header} + #{generate_date_info} + #{add_search_box if make_searchable} #{generate_tree(dep_graph_exists)} #{generate_details} #{generate_footer} DOC_STR end protected + def generate_title_and_header + <<~DOC_HEADER + = Document index + from #{@paths.src_root_abs} + :icons: font + + DOC_HEADER + end + # return the adoc string for displaying the source file def display_source_file(doc_info) <<~SRC_FILE_TXT Source file:: - #{doc_info.srcFile_utf8} + #{doc_info.src_file} SRC_FILE_TXT end - def generate_header + def generate_date_info t = Time.now <<~DOC_HEADER - = Document index - from #{@paths.src_root_abs} + *Generated by Giblish at:* #{t.strftime('%Y-%m-%d %H:%M')} + DOC_HEADER + end - Generated by Giblish at:: + def add_search_box + # TODO: Fix the hard-coded path + cgi_path = "/cgi-bin/giblish-search.cgi" + css = @converter.converter_options[:attributes]["stylesheet"] - #{t.strftime('%Y-%m-%d %H:%M')} + # button with magnifying glass icon (not working when deployed) + # <button id="search" type="submit"><i class="fa fa-search"></i></button> + <<~SEARCH_INFO + ++++ + <form class="example" action="#{cgi_path}" style="margin:20px 0px 20px 0px;max-width:380px"> + Search all documents: + <input id="searchphrase" type="text" placeholder="Search.." name="searchphrase"/> + <button id="search" type="submit">Search</button> + <br> - DOC_HEADER - end + <input id="ignorecase" type="checkbox" value="true" name="ignorecase" checked/> + <label for="ignorecase">Ignore Case</label> + &nbsp;&nbsp; + <input id="useregexp" type="checkbox" value="true" name="regexp"/> + <label for="useregexp">Use Regexp</label> + <input type="hidden" name="topdir" value="#{@paths.dst_root_abs.to_s}"</input> + <input type="hidden" name="reltop" value="#{@paths.reldir_from_web_root(@paths.dst_root_abs)}"</input> + <input type="hidden" name="css" value="#{css}"</input> + </form> + ++++ + + SEARCH_INFO + end def get_docid_statistics largest = "" clash = [] @processed_docs.each do |d| # get the lexically largest doc id @@ -89,12 +124,11 @@ "" end if @manage_docid <<~DOC_ID_INFO - Document id numbers:: - The generation of this repository uses document id numbers. #{docid_info_str} #{dep_graph_str} + *Document id numbers:* #{docid_info_str} #{dep_graph_str} #{docid_warn_str} DOC_ID_INFO else @@ -103,16 +137,10 @@ end def generate_tree(dep_graph_exists) # output tree intro tree_string = <<~DOC_HEADER - == Document Overview - - _Click on the title to open the document or on `details` to see more - info about the document. A `(warn)` label indicates that there were - warnings while converting the document from its asciidoc format._ - #{generate_doc_id_info dep_graph_exists} [subs=\"normal\"] ---- DOC_HEADER @@ -170,12 +198,12 @@ "#{doc_info.doc_id} - #{doc_info.title}" else doc_info.title end - [title, "<<#{doc_info.rel_path}#,#{title}>>".encode("utf-8"), - "<<#{Giblish.to_valid_id(doc_info.title)},details>>\n".encode("utf-8")] + [title, "<<#{doc_info.rel_path}#,#{title}>>", + "<<#{Giblish.to_valid_id(doc_info.title)},details>>\n"] end # Generate an adoc string that will display as # DocTitle (warn) details # Where the DocTitle and details are links to the doc itself and a section @@ -204,22 +232,22 @@ d = node.data if d.converted tree_entry_converted prefix_str, d else # no converted file exists, show what we know - "#{prefix_str} FAIL: #{d.srcFile_utf8} <<#{d.srcFile_utf8},details>>\n" + "#{prefix_str} FAIL: #{d.src_file} <<#{d.src_file},details>>\n" end end # Derived classes can override this with useful info def generate_history_info(_d) "" end def generate_detail_fail(d) <<~FAIL_INFO - === #{d.srcFile_utf8} + === #{d.src_file} #{display_source_file(d)} Error detail:: #{d.stderr} @@ -286,20 +314,20 @@ end end # A simple index generator that shows a table with the generated documents class SimpleIndexBuilder < BasicIndexBuilder - def initialize(processed_docs, path_manager, manage_docid = false) - super processed_docs, path_manager, manage_docid + def initialize(processed_docs, converter, path_manager, manage_docid = false) + super processed_docs, converter, path_manager, manage_docid end end # Builds an index of the generated documents and includes some git metadata # from the repository class GitRepoIndexBuilder < BasicIndexBuilder - def initialize(processed_docs, path_manager, manage_docid, git_repo_root) - super processed_docs, path_manager, manage_docid + def initialize(processed_docs, converter, path_manager, manage_docid, git_repo_root) + super processed_docs, converter, path_manager, manage_docid # no repo root given... return unless git_repo_root begin @@ -326,17 +354,16 @@ SRC_FILE_TXT end - def generate_header + def generate_title_and_header t = Time.now <<~DOC_HEADER = Document index #{@git_repo.current_branch} - Generated by Giblish at:: - #{t.strftime('%Y-%m-%d %H:%M')} + :icons: DOC_HEADER end def generate_history_info(d) \ No newline at end of file