Class: Docfu::BaseOutput

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/docfu/outputs/base.rb

Direct Known Subclasses

Ebook, Html, Pdf

Instance Method Summary collapse

Instance Method Details

#check_missing_commandsObject



15
16
17
18
19
20
21
22
# File 'lib/docfu/outputs/base.rb', line 15

def check_missing_commands
  missing = required_commands.reject{|command| command_exists?(command)}
  unless missing.empty?
    puts "Missing dependencies: #{missing.join(', ')}."
    puts "Install these and try again."
    exit 0
  end
end

#check_valid_projectObject



40
41
42
# File 'lib/docfu/outputs/base.rb', line 40

def check_valid_project
  not_a_project_error unless contains_info_yaml? and contains_config_yaml?
end

#command_exists?(command) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/docfu/outputs/base.rb', line 28

def command_exists?(command)
  if File.executable?(command) then
    return command
  end
  ENV['PATH'].split(File::PATH_SEPARATOR).map do |path|
    cmd = "#{path}/#{command}"
    File.executable?(cmd) \
    ||  File.executable?("#{cmd}.exe") \
    ||  File.executable?("#{cmd}.cmd")
  end.inject{|a, b| a || b}
end

#configObject



56
57
58
# File 'lib/docfu/outputs/base.rb', line 56

def config
  @config ||= YAML::load(File.open("#{project_home}/config.yml"))
end

#contains_config_yaml?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/docfu/outputs/base.rb', line 48

def contains_config_yaml?
  File.exists? "#{project_home}/config.yml"
end

#contains_info_yaml?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/docfu/outputs/base.rb', line 44

def contains_info_yaml?
  File.exists? "#{project_home}/info.yml"
end

#figures(&block) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/docfu/outputs/base.rb', line 66

def figures(&block)
  begin
    Dir["#{project_home}/figures/18333*.png"].each do |file|
      cp(file, file.sub(/18333fig0(\d)0?(\d+)\-tn/, '\1.\2'))
    end
    block.call
  ensure
    Dir["#{project_home}/figures/18333*.png"].each do |file|
      rm(file.gsub(/18333fig0(\d)0?(\d+)\-tn/, '\1.\2'))
    end
  end
end

#generate(languages, debug) ⇒ Object



6
7
8
9
# File 'lib/docfu/outputs/base.rb', line 6

def generate(languages, debug)
  puts "This output class has not been implemented"
  exit 0
end

#infoObject



52
53
54
# File 'lib/docfu/outputs/base.rb', line 52

def info
  @info ||= YAML::load(File.open("#{project_home}/info.yml"))
end

#not_a_project_errorObject



60
61
62
63
64
# File 'lib/docfu/outputs/base.rb', line 60

def not_a_project_error
  puts "This directory doesn't appear to be docfu repository."
  puts "To create a new docfu repository type: docfu new [document]"
  exit 0
end

#project_homeObject



24
25
26
# File 'lib/docfu/outputs/base.rb', line 24

def project_home
  @home ||= Dir.pwd
end

#required_commandsObject



11
12
13
# File 'lib/docfu/outputs/base.rb', line 11

def required_commands
  []
end