Class: Mdpresent::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/mdpresent/command.rb

Class Method Summary collapse

Class Method Details

.execute(cmd) ⇒ Object



39
40
41
42
# File 'lib/mdpresent/command.rb', line 39

def execute cmd
  Logger.log("[command.execution] executing #{cmd}")
  system cmd
end

.generate_presentation(file, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mdpresent/command.rb', line 18

def generate_presentation file, options
  # get the absolute path of mdfile provided by user.
  file_with_path = File.expand_path(file)

  # use git to get the project root
  project_root = `git rev-parse --show-toplevel`.strip

  # run mdpress generate command inside the www dir.
  # since this is where we want to keep all the generated code.
  Dir.chdir "#{project_root}/www"
  puts "Generating presentation files..."
  case options[:action]
  when :default
    execute I18n.t "commands.mdpress.gen", { file: file_with_path }
  when :style
    execute I18n.t("commands.mdpress.style", {style: options[:style], file: file_with_path})
  when :watch
    execute I18n.t("commands.mdpress.watch", {file: file_with_path})
  end
end

.path(cmd) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/mdpresent/command.rb', line 7

def path cmd
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable? exe
    }
  end
  return nil
end