Class: Docfu::BaseOutput
- Inherits:
-
Object
- Object
- Docfu::BaseOutput
- Includes:
- FileUtils
- Defined in:
- lib/docfu/outputs/base.rb
Instance Method Summary collapse
- #check_missing_commands ⇒ Object
- #check_valid_project ⇒ Object
- #command_exists?(command) ⇒ Boolean
- #config ⇒ Object
- #contains_config_yaml? ⇒ Boolean
- #contains_info_yaml? ⇒ Boolean
- #figures(&block) ⇒ Object
- #generate(languages, debug) ⇒ Object
- #info ⇒ Object
- #not_a_project_error ⇒ Object
- #project_home ⇒ Object
- #required_commands ⇒ Object
Instance Method Details
#check_missing_commands ⇒ Object
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_project ⇒ Object
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
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 |
#config ⇒ Object
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
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
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 |
#info ⇒ Object
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_error ⇒ Object
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_home ⇒ Object
24 25 26 |
# File 'lib/docfu/outputs/base.rb', line 24 def project_home @home ||= Dir.pwd end |
#required_commands ⇒ Object
11 12 13 |
# File 'lib/docfu/outputs/base.rb', line 11 def required_commands [] end |