Method: CodeRunner::Run::FortranNamelist.edit_namelist_help

Defined in:
lib/coderunner/fortran_namelist.rb

.edit_namelist_help(namelist, message = "") ⇒ Object

Edit the help for the namelist. Requires the environment variable EDITOR to be set.

Raises:

  • (ArgumentError)


192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/coderunner/fortran_namelist.rb', line 192

def self.edit_namelist_help(namelist, message = "")
  raise ArgumentError.new("Unknown namelist #{namelist}") unless namelist_hash = rcp.namelists[namelist]
  raise "Please set the environment variable EDITOR" unless ENV['EDITOR']
  File.open('/tmp/.tmp_namelist_help.txt', 'w') do |file|
    file.puts "\n------------------------------------------------------------------\nEditing help and description for namelist \#{namelist}:\n-----------------------------------------------------------------\n\nEdit the help and description, then save and quit the editor. Help can be long and detailed, and can include MediaWiki markup. Description should be short and in plain text.\n\n\#{message}\n\n-------------------------------------begin help text\n\n\n\#{namelist_hash[:help]}\n\n\n------------------------------------begin description\n\n\#{namelist_hash[:description]}\n"
  end
  system "#{ENV['EDITOR']} /tmp/.tmp_namelist_help.txt"
  namelist_hash[:help], namelist_hash[:description] = File.read('/tmp/.tmp_namelist_help.txt').split(/^\-+begin help text/)[1].split(/^\-+begin description/, -1).map{|s| s.sub(/\A\s+/, '').sub(/\s+\Z/, '')}
  save_namelists
end