class Docfu::BaseOutput

Public Instance Methods

check_missing_commands() click to toggle source
# File lib/docfu/outputs/base.rb, line 14
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_project() click to toggle source
# File lib/docfu/outputs/base.rb, line 39
def check_valid_project
  not_a_project_error unless contains_info_yaml? and contains_config_yaml?
end
command_exists?(command) click to toggle source
# File lib/docfu/outputs/base.rb, line 27
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
config() click to toggle source
# File lib/docfu/outputs/base.rb, line 55
def config
  @config ||= YAML::load(File.open("#{project_home}/config.yml"))
end
contains_config_yaml?() click to toggle source
# File lib/docfu/outputs/base.rb, line 47
def contains_config_yaml?
  File.exists? "#{project_home}/config.yml"
end
contains_info_yaml?() click to toggle source
# File lib/docfu/outputs/base.rb, line 43
def contains_info_yaml?
  File.exists? "#{project_home}/info.yml"
end
figures(&block) click to toggle source
# File lib/docfu/outputs/base.rb, line 65
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) click to toggle source
# File lib/docfu/outputs/base.rb, line 5
def generate(languages, debug)
  puts "This output class has not been implemented"
  exit 0
end
info() click to toggle source
# File lib/docfu/outputs/base.rb, line 51
def info
  @info ||= YAML::load(File.open("#{project_home}/info.yml"))
end
not_a_project_error() click to toggle source
# File lib/docfu/outputs/base.rb, line 59
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_home() click to toggle source
# File lib/docfu/outputs/base.rb, line 23
def project_home
  @home ||= Dir.pwd
end
required_commands() click to toggle source
# File lib/docfu/outputs/base.rb, line 10
def required_commands
  []
end