Class: Logi::Compiler

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/logi/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

black, blue, color, cyan, green, log, magenta, red, strip_cwd_path, strip_home_path, strip_path, white, yellow

Constructor Details

#initialize(options = {}) ⇒ Compiler

Returns a new instance of Compiler.



11
12
13
# File 'lib/logi/compiler.rb', line 11

def initialize options={}
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/logi/compiler.rb', line 10

def options
  @options
end

Instance Method Details

#compile(command, path, layout) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/logi/compiler.rb', line 15

def compile command, path, layout
  wiki = IO.popen("logi-wiki #{path}", 'r')
  out  = IO.popen("logi-#{command} #{path} #{layout}", 'r+')
  copy_stream(wiki, out)
  out.close_write
  log_compile(command, path, layout) unless out.eof?
  out
end

#copy_stream(from, to) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/logi/compiler.rb', line 33

def copy_stream from, to
  IO.copy_stream(from, to)
rescue TypeError # JRuby can only copy from file to file
  to.write(from.read(8192)) until from.eof?
ensure
  from.close
end

#write(output, out) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/logi/compiler.rb', line 24

def write output, out
  return if out.eof?
  log_write(output)
  FileUtils.mkdir_p(File.dirname(output))
  copy_stream(out, output)
ensure
  out.close
end