Class: Source2Pdf::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/source2pdf/exporter.rb

Overview

rubocop:disable ClassLength, MethodLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, opts = {}) ⇒ Exporter

The initializer for Exporter

Parameters:

  • url (String)

    the input URL like github.com/opal/opal.git or just the immediate folder name

  • opts (Hash<Symbol,Object>) (defaults to: {})

    the option hash

Options Hash (opts):

  • :exts (Array<String>)

    the list of file extension to be used

  • :non_exts (Array<String>)

    the list of file without extension to be used

  • :theme (String)

    the colorscheme to use with ‘vim_printer`

  • :output_name (String)

    the output filename if any



25
26
27
28
29
30
31
32
33
34
# File 'lib/source2pdf/exporter.rb', line 25

def initialize(url, opts = {})
  @url         = url
  @base_dir    = Dir.pwd
  @exts        = opts[:exts]     || []
  @non_exts    = opts[:non_exts] || []
  @theme       = opts[:theme]    || "default"
  @repo_name   = project_name(url)
  @output_path = File.expand_path([base_dir, repo_name].join(File::SEPARATOR))
  @output_name = pdf_filename(opts[:output_name]) || "#{@repo_name}.pdf"
end

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



11
12
13
# File 'lib/source2pdf/exporter.rb', line 11

def base_dir
  @base_dir
end

#extsObject (readonly)

Returns the value of attribute exts.



5
6
7
# File 'lib/source2pdf/exporter.rb', line 5

def exts
  @exts
end

#non_extsObject (readonly)

Returns the value of attribute non_exts.



5
6
7
# File 'lib/source2pdf/exporter.rb', line 5

def non_exts
  @non_exts
end

#output_nameObject (readonly)

Returns the value of attribute output_name.



5
6
7
# File 'lib/source2pdf/exporter.rb', line 5

def output_name
  @output_name
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



11
12
13
# File 'lib/source2pdf/exporter.rb', line 11

def output_path
  @output_path
end

#repo_nameObject (readonly)

Returns the value of attribute repo_name.



11
12
13
# File 'lib/source2pdf/exporter.rb', line 11

def repo_name
  @repo_name
end

#themeObject (readonly)

Returns the value of attribute theme.



5
6
7
# File 'lib/source2pdf/exporter.rb', line 5

def theme
  @theme
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/source2pdf/exporter.rb', line 5

def url
  @url
end

Instance Method Details

#exportObject

Print and export the source from a given URL to a pdf



37
38
39
40
41
42
43
44
45
46
# File 'lib/source2pdf/exporter.rb', line 37

def export
  clone
  puts "FYI: list of extensions: #{all_extensions}"
  puts "FYI: list of all files : #{all_files}"
  files2htmls
  htmls2pdfs
  pdfs2pdf
  copy_output
  cleanup
end

#to_sObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/source2pdf/exporter.rb', line 48

def to_s
  "    url         : \#{url}\n    base_dir    : \#{base_dir}\n    exts        : \#{exts}\n    non_exts    : \#{non_exts}\n    repo_name   : \#{repo_name}\n    theme       : \#{theme}\n    output_path : \#{output_path}\n    output_name : \#{output_name}\n EOT\nend\n"