Module: Source2Epub

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

Defined Under Namespace

Classes: CLI, Configuration, Exporter

Constant Summary collapse

VERSION =
"0.2.2"
TMP_DIR =
"source2epub_tmp"
CustomError =
Class.new(StandardError)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Configure Source2Epub someplace sensible, like

‘config/initializers/source2epub.rb’

Source2Epub.configure do |config|

config.creator = ".."

end



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

def configuration
  @configuration
end

.loggerLogger



6
7
8
# File 'lib/source2epub/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



12
13
14
15
# File 'lib/source2epub/source2epub.rb', line 12

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

.configure {|configuration| ... } ⇒ Object

Yields:



29
30
31
# File 'lib/source2epub/configuration.rb', line 29

def configure
  yield(configuration)
end

.files_to_htmls(opts) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/source2epub/source2epub.rb', line 28

def files_to_htmls(opts)
  base_dir = base_dir(opts[:base_dir])
  unless File.exist?(base_dir) && File.directory?(base_dir)
    fail "Starting directory must be valid, and exist"
  end

  exts     = opts[:exts]     || []
  non_exts = opts[:non_exts] || []
  theme    = opts.fetch(:theme, "default")
  command  = opts[:command]

  if command
    args = [
      "print",
      "--base-dir",
      base_dir,
      "--command",
      command,
      "--theme",
      theme
    ]
  else
    args = [
      "print",
      "--base-dir",
      base_dir,
      "--exts",
      exts,
      "--theme",
      theme,
      "--recursive"
    ]
    args.concat(["--non-exts"]).concat(non_exts) unless non_exts.empty?
  end
  # puts "FYI: input options for vim_printer #{args}"
  VimPrinter::CLI.start(args)
end

.list_extensions(base_dir = ".") ⇒ Object



17
18
19
20
21
22
# File 'lib/source2epub/source2epub.rb', line 17

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



24
25
26
# File 'lib/source2epub/source2epub.rb', line 24

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