Class: Octopress::Ui::UIServer

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/octopress/ui/ui.rb

Instance Method Summary collapse

Instance Method Details

#save_postObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/octopress/ui/ui.rb', line 11

def save_post
  return nil if params[:title] == "" || params[:content] == ""
  title = PinYin.permlink(params[:title])
  filename = File.join($root, 'source', '_posts', "#{Time.now.strftime('%Y-%m-%d')}-#{title}.markdown")
  FileUtils.touch(filename) unless File.exists?(filename)
  File.open(filename, 'w') do |file|
    file.puts "---"
    file.puts "layout: post"
    file.puts "title: #{params[:title]}"
    file.puts "---"
    file.puts ""

    file.write params[:content]
  end
  p system('rake generate')
end