-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.rb
47 lines (36 loc) · 994 Bytes
/
editor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'rubygems'
require 'sinatra'
require 'haml'
$KCODE = 'u' if RUBY_VERSION < '1.9'
before do
content_type :html, 'charset' => 'utf-8'
end
set :public, File.dirname(__FILE__) + '/output'
#get '/' do
# Dir.chdir('source'){ @files = Dir.glob('*.textile') }
# haml :index
#end
get '/' do
Dir.chdir('source'){ @files = Dir.glob('*.textile') }
@file_name = params[:file]
haml :index
end
get '/:file' do
Dir.chdir('source'){ @files = Dir.glob('*.textile') }
@file_name = params[:file]
@file = File.read("source/#{@file_name}")
@first_part = @file_name.split(/\./).shift
haml :edit
end
post '/:file' do
#Dir.chdir('source'){ @files = Dir.glob('*.textile') }
@file_name = params[:file]
@file = File.open("source/#{@file_name}",'w')
@file.write params[:file_content]
@first_part = @file_name.split(/\./).shift
`ruby spree_guides.rb #{@first_part}`
redirect "#{@first_part}.html"
end
#get '/preview/:file' do
# File.read("output/#{params[:file]}")
#end