Module: Giblish

Defined in:
lib/giblish/docid.rb,
lib/giblish.rb,
lib/giblish/core.rb,
lib/giblish/utils.rb,
lib/giblish/gititf.rb,
lib/giblish/docinfo.rb,
lib/giblish/version.rb,
lib/giblish/buildgraph.rb,
lib/giblish/buildindex.rb,
lib/giblish/application.rb,
lib/giblish/docconverter.rb,
lib/giblish/indexheadings.rb

Overview

put the indexing in the giblish namespace

Defined Under Namespace

Classes: Application, AsciidoctorLogger, BasicIndexBuilder, DeploymentPaths, DocConverter, DocInfo, DocidCollector, FileTreeConverter, GitGraphBuilderGraphviz, GitItf, GitRepoConverter, GitRepoIndexBuilder, GitSummaryIndexBuilder, GraphBuilderGraphviz, HtmlConverter, IndexHeadings, PathManager, PdfConverter, SimpleIndexBuilder

Constant Summary collapse

VERSION =
"0.8.2".freeze

Class Method Summary collapse

Class Method Details

.applicationObject



14
15
16
# File 'lib/giblish.rb', line 14

def application
  @application ||= Giblish::Application.new
end

.generate_search_box_html(css, cgi_path, opts) ⇒ Object

returns raw html that displays a search box to let the user acces the text search functionality.

css - the name of the css file to use for the search result layout cgi_path - the (uri) path to a cgi script that implements the server side

functionality of searching the text

opts: :web_assets_top => string # the path to the ‘web_assets’ dir as seen when serving

the web server (eg www.mysite.com/blah/doc_root ->
web_assets_top shall be '/blah/doc_root')

:search_assets_top => string # the path to where the ‘heading.json’ file is located (

as seen from the local file system on the machine that
runs the search script)


403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/giblish/utils.rb', line 403

def generate_search_box_html(css, cgi_path, opts)
  # Replace the button with the below to use a text-only version of the btn
  # <button id="search" type="submit">Search</button>
  <<~SEARCH_INFO
    ++++
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
      <form class="example" action="#{cgi_path}" style="margin:20px 0px 20px 0px;max-width:790px">
          Search all documents:
          <input id="searchphrase" type="text" placeholder="Search.." name="searchphrase"/>
          <button id="search" type="submit"><i class="fa fa-search"></i></button>
          <br>

          <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="useregexp"/>
          <label for="useregexp">Use Regexp</label>

          <input type="hidden" name="searchassetstop" value="#{opts[:search_assets_top]}"</input>
          <input type="hidden" name="webassetstop" value="#{opts[:web_assets_top]}"</input>
          #{%(<input type="hidden" name="css" value="#{css}"</input>) unless css.nil?}
      </form>
    ++++

  SEARCH_INFO
end

.process_header_lines(lines) ⇒ Object

Helper method that provides the user with a way of processing only the lines within the asciidoc header block. The user must return nil to get the next line.

ex: process_header_lines(file_path) do |line|

if line == "Quack!"
   puts "Donald!"
   1
else
   nil
end

end



322
323
324
325
326
327
328
329
330
331
# File 'lib/giblish/utils.rb', line 322

def process_header_lines(lines)
  state = "before_header"
  lines.each do |line|
    case state
    when "before_header" then (state = "in_header" if line =~ /^[=+]^.*$/ || yield(line))
    when "in_header" then (state = "done" if line =~ /^\s*$/ || yield(line))
    when "done" then break
    end
  end
end

.process_header_lines_from_file(path) ⇒ Object

Helper method that provides the user with a way of processing only the lines within the asciidoc header block. The user must return nil to get the next line.

ex: process_header_lines_from_file(file_path) do |line|

if line == "Quack!"
   puts "Donald!"
   1
else
   nil
end

end



347
348
349
350
# File 'lib/giblish/utils.rb', line 347

def process_header_lines_from_file(path)
  lines = File.readlines(path)
  process_header_lines(lines, &Proc.new)
end

.register_docid_extensionObject

Helper method to register the docid preprocessor extension with the asciidoctor engine.



174
175
176
177
178
# File 'lib/giblish/docid.rb', line 174

def register_docid_extension
  Asciidoctor::Extensions.register do
    preprocessor DocidCollector
  end
end

.register_index_heading_extensionObject

Helper method to register the docid preprocessor extension with the asciidoctor engine.



244
245
246
247
248
# File 'lib/giblish/indexheadings.rb', line 244

def register_index_heading_extension
  Asciidoctor::Extensions.register do
    preprocessor IndexHeadings
  end
end

.to_valid_id(input_str, id_prefix = "_", id_separator = "_") ⇒ Object

transforms strings to valid asciidoctor id strings



366
367
368
369
370
# File 'lib/giblish/utils.rb', line 366

def to_valid_id(input_str, id_prefix = "_", id_separator = "_")
  id_str = input_str.strip.downcase.gsub(/[^a-z0-9]+/, id_separator)
  id_str = "#{id_prefix}#{id_str}"
  id_str.chomp(id_separator)
end

.which(cmd) ⇒ Object

See stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby Cross-platform way of finding an executable in the $PATH.

Ex

which('ruby') #=> /usr/bin/ruby


378
379
380
381
382
383
384
385
386
387
# File 'lib/giblish/utils.rb', line 378

def which(cmd)
  exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end

.with_captured_stderrObject

runs the supplied block but redirect stderr to a string returns the string containing stderr contents



355
356
357
358
359
360
361
362
# File 'lib/giblish/utils.rb', line 355

def with_captured_stderr
  old_stderr = $stderr
  $stderr = StringIO.new("", "w")
  yield
  $stderr.string
ensure
  $stderr = old_stderr
end