Module: Mdtex

Defined in:
lib/mdtex.rb,
lib/mdtex/cli.rb,
lib/mdtex/util.rb,
lib/mdtex/version.rb,
lib/mdtex/constant.rb

Defined Under Namespace

Modules: Constant Classes: CLI

Constant Summary collapse

SETTING_FILE =
'./config.yml'
VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.exist_command?(command) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mdtex/util.rb', line 25

def exist_command?(command)
  `type "#{command}" 2> /dev/null` != ''
end

.load_configObject



6
7
8
9
10
# File 'lib/mdtex/util.rb', line 6

def load_config
  raise 'config.yml is not found.' unless File.exists? SETTING_FILE
  require 'mdtex/constant'
  Mdtex::Constant
end

.make_target_directory(target) ⇒ Object



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

def make_target_directory(target)
  target_dir = File.dirname(target)
  FileUtils.mkdir_p target_dir unless File.directory?(target_dir)
end

.md2latex(src, dest) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/mdtex/util.rb', line 17

def md2latex(src, dest)
  if exist_command?('pandoc')
    `pandoc #{src} -o #{dest} > /dev/null`
  else
    raise 'pandoc is not installed.'
  end
end

.relative_path(path, base = Dir.pwd) ⇒ Object



29
30
31
# File 'lib/mdtex/util.rb', line 29

def relative_path(path, base=Dir.pwd)
  Pathname(path).relative_path_from(Pathname(base))
end