Class: Rundoc::CodeCommand::Write

Inherits:
Rundoc::CodeCommand show all
Includes:
FileUtil
Defined in:
lib/rundoc/code_command/write.rb

Constant Summary

Constants inherited from Rundoc::CodeCommand

NEWLINE

Instance Attribute Summary

Attributes inherited from Rundoc::CodeCommand

#command, #contents, #keyword, #original_args, #render_command, #render_result

Instance Method Summary collapse

Methods included from FileUtil

#filename, #mkdir_p

Methods inherited from Rundoc::CodeCommand

#hidden?, #not_hidden?, #push

Constructor Details

#initialize(filename) ⇒ Write

Returns a new instance of Write.



21
22
23
# File 'lib/rundoc/code_command/write.rb', line 21

def initialize(filename)
  @filename = filename
end

Instance Method Details

#call(env = {}) ⇒ Object



34
35
36
37
38
39
# File 'lib/rundoc/code_command/write.rb', line 34

def call(env = {})
  puts "Writing to: '#{filename}'"
  mkdir_p
  File.write(filename, contents)
  contents
end

#to_md(env) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/rundoc/code_command/write.rb', line 25

def to_md(env)
  if render_command?
    raise "must call write in its own code section" unless env[:commands].empty?
    env[:before] << "In file `#{filename}` write:"
    env[:before] << NEWLINE
  end
  nil
end