Class: Docdown::CodeCommands::Write

Inherits:
Docdown::CodeCommand show all
Defined in:
lib/docdown/code_commands/write.rb

Instance Attribute Summary

Attributes inherited from Docdown::CodeCommand

#command, #contents, #hidden, #keyword, #render_result

Instance Method Summary collapse

Methods inherited from Docdown::CodeCommand

#push, #render

Constructor Details

#initialize(filename) ⇒ Write

Returns a new instance of Write.



4
5
6
7
# File 'lib/docdown/code_commands/write.rb', line 4

def initialize(filename)
  @filename = filename
  @dir      = File.expand_path("../", @filename)
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
# File 'lib/docdown/code_commands/write.rb', line 14

def call
  puts "writing to : #{@filename}"
  FileUtils.mkdir_p(@dir)
  File.open(@filename, "w") do |f|
    f.write(contents)
  end
  contents
end

#to_mdObject

todo diff file if it already exists



10
11
12
# File 'lib/docdown/code_commands/write.rb', line 10

def to_md
  "In file `#{@filename}` add:\n#{contents}"
end