Class: Pressy::Editor

Inherits:
Object
  • Object
show all
Defined in:
lib/pressy/editor.rb

Instance Method Summary collapse

Constructor Details

#initialize(editor, console) ⇒ Editor

Returns a new instance of Editor



4
5
6
7
# File 'lib/pressy/editor.rb', line 4

def initialize(editor, console)
  @editor = editor
  @console = console
end

Instance Method Details

#edit(post) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pressy/editor.rb', line 9

def edit(post)
  rendered_post = Pressy::PostRenderer.render(post)
  content = Tempfile.create(['draft', '.md']) do |file|
    file.write rendered_post.content
    file.fsync
    @console.run("#{@editor} \"#{file.path}\"")

    File.read(file.path)
  end

  Pressy::PostParser.parse(format: post.format, content: content)
end