Method: Doing::WWID#add_with_editor

Defined in:
lib/doing/wwid/editor.rb

#add_with_editor(**options) ⇒ Object

Raises:

  • (MissingEditor)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/doing/wwid/editor.rb', line 103

def add_with_editor(**options)
  raise MissingEditor, 'No EDITOR variable defined in environment' if Util.default_editor.nil?

  input = options[:date].strftime('%F %R | ')
  input += options[:title]
  input += "\n#{options[:note]}" if options[:note]
  input = fork_editor(input).strip

  d, title, note = format_input(input)
  raise EmptyInput, 'No content' if title.empty?

  if options[:ask]
    ask_note = Doing::Prompt.read_lines(prompt: 'Add a note')
    note.add(ask_note) unless ask_note.empty?
  end

  date = d.nil? ? options[:date] : d
  finish = options[:finish_last] || false
  add_item(title.cap_first, options[:section], { note: note, back: date, timed: finish })
  write(@doing_file)
end