Module: GithubExporter

Defined in:
lib/github_exporter/cli.rb,
lib/github_exporter/logger.rb,
lib/github_exporter/version.rb,
lib/github_exporter/exporter.rb,
lib/github_exporter/github_exporter.rb

Defined Under Namespace

Classes: CLI, Exporter

Constant Summary collapse

VERSION =
"0.1.6"
TMP_DIR =
"github_exporter_tmp"
CustomError =
Class.new(StandardError)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerLogger

Returns the logger for the project.

Returns:

  • (Logger)

    the logger for the project



6
7
8
# File 'lib/github_exporter/logger.rb', line 6

def logger
  @logger ||= Logger.new STDOUT
end

Class Method Details

.clone_repository(url, name, path) ⇒ Object

Clone the given repository from github

Parameters:

  • url (String)

    the github repository url like ‘github.com/schacon/ruby-git.git

  • name (String)

    the output name to be used

  • path (String)

    the output directory



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

def clone_repository(url, name, path)
  puts "git clone #{url} #{File.expand_path(path)}/#{name}"
  Git.clone url, name, path: File.expand_path(path)
end

.files_to_htmls(opts) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/github_exporter/github_exporter.rb', line 29

def files_to_htmls(opts)
  base_dir = base_dir(opts[:base_dir])
  exts     = opts[:exts]     || []
  non_exts = opts[:non_exts] || []
  args = [
    "print",
    "--base-dir",
    base_dir,
    "--exts",
    exts,
    "--theme",
    opts.fetch(:theme, "default"),
    "--recursive"
  ]
  args.concat(["--non-exts"]).concat(non_exts) unless non_exts.empty?

  puts "FYI: input options for VimPrinter : #{args}"
  VimPrinter::CLI.start(args)
end

.htmls_to_pdfs(opts) ⇒ Object

Export list of html files to pdfs using ‘html2pdf` gem



50
51
52
53
54
55
56
57
# File 'lib/github_exporter/github_exporter.rb', line 50

def htmls_to_pdfs(opts)
  base_dir = base_dir(opts[:base_dir])
  Html2Pdf::CLI.start [
    "export",
    "--base-dir",
    base_dir,
    "--recursive"]
end

.list_extensions(base_dir = ".") ⇒ Object



18
19
20
21
22
23
# File 'lib/github_exporter/github_exporter.rb', line 18

def list_extensions(base_dir = ".")
  extensions = Dir.glob(File.join(File.expand_path(base_dir), "**/*")).reduce([]) do |exts, file|
    exts << File.extname(file)
  end
  extensions.sort.uniq.delete_if { |e| e == "" }
end

.list_files(options = {}) ⇒ Object



25
26
27
# File 'lib/github_exporter/github_exporter.rb', line 25

def list_files(options = {})
  CodeLister.files(options)
end

.pdfs_to_pdf(opts) ⇒ Object

Merge/combine pdfs using ‘pdfs2pdf` gem



60
61
62
63
64
65
66
67
68
# File 'lib/github_exporter/github_exporter.rb', line 60

def pdfs_to_pdf(opts)
  base_dir = base_dir(opts[:base_dir])
  Pdfs2Pdf::CLI.start [
    "merge",
    "--base-dir",
    base_dir,
    "--recursive"
  ]
end