Pregunta

Tengo una tarea en mi archivo de rastrillo para crear una nueva publicación en Jekyll. (Lo tomé prestado de Octos).

Intenté hackearlo para que cree un nuevo archivo de Markdown, agregue la información de encabezado predeterminada y luego la abra en IA Writer. Crea el archivo y agrega la información, pero lo que abre no es el archivo. Parece que la variable de nombre de archivo no se está pasando al comando del sistema, pero no tengo idea de cómo debería escribirla.

Aquí está el código:

# Usage rake new_post['Title of the Post']
desc "Beginning a new post in _posts"
task :new_post, :title do |t, args|
  args.with_defaults(:title => 'new-post')
  title = args.title
  filename = "_posts/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.markdown"
  open_filename = "#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.markdown"
  if File.exist?(filename)
    abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
  end
  puts "Creating new post: #{filename}"
  open(filename, 'w') do |post|
    post.puts "---"
    post.puts "layout: post"
    post.puts "title: \"#{title.gsub(/&/,'&')}\""
    post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
    post.puts "categories: "
    post.puts "---"
  end
  puts "Opening: #{filename}"
  system('open -a IA\ Writer ~/Dropbox/Archive/jdb/#{filename}')
end
¿Fue útil?

Solución

En línea system... cambio ' a ". En ' Ruby no usa variables, ejemplo:

001 > filename = "test"
=> "test"
002 > puts '#{filename}'
=> #{filename}
003 > puts "#{filename}"
=> test
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top