Class: Docdown::CodeCommands::Write
- Inherits:
-
Docdown::CodeCommand
- Object
- Docdown::CodeCommand
- Docdown::CodeCommands::Write
- 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
- #call ⇒ Object
-
#initialize(filename) ⇒ Write
constructor
A new instance of Write.
-
#to_md ⇒ Object
todo diff file if it already exists.
Methods inherited from Docdown::CodeCommand
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.("../", @filename) end |
Instance Method Details
#call ⇒ Object
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_md ⇒ Object
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 |