Class: Rundoc::CodeCommand::Write

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

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



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

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

#to_md(env) ⇒ Object



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

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