sinatra-editable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra/editable.rb +8 -8
- metadata +2 -2
data/lib/sinatra/editable.rb
CHANGED
@@ -5,14 +5,14 @@ module Sinatra
|
|
5
5
|
|
6
6
|
module Helpers
|
7
7
|
def editable(item)
|
8
|
-
path = "#{
|
8
|
+
path = "#{settings.root}/#{settings.editable_dir}/#{item.to_s}.html"
|
9
9
|
if editable_exist?(item)
|
10
10
|
File.read(path)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def editable_exist?(item)
|
15
|
-
path = "#{
|
15
|
+
path = "#{settings.root}/#{settings.editable_dir}/#{item.to_s}.html"
|
16
16
|
File.exist?(path)
|
17
17
|
end
|
18
18
|
end
|
@@ -24,8 +24,8 @@ module Sinatra
|
|
24
24
|
app.set :editable_dir, 'editable'
|
25
25
|
app.set :editable_templater, :html
|
26
26
|
|
27
|
-
app.get "
|
28
|
-
path = "#{
|
27
|
+
app.get "#{app.editable_route}/*" do
|
28
|
+
path = "#{settings.root}/#{settings.editable_dir}/#{params[:splat].join('/')}.#{settings.editable_templater}"
|
29
29
|
if File.exist?(path)
|
30
30
|
File.read(path)
|
31
31
|
else
|
@@ -33,8 +33,8 @@ module Sinatra
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
app.put "
|
37
|
-
case
|
36
|
+
app.put "#{app.editable_route}/*" do
|
37
|
+
case settings.editable_templater
|
38
38
|
when :textile
|
39
39
|
new_template = params[:content]
|
40
40
|
new_html = RedCloth.new(new_template).to_html
|
@@ -47,10 +47,10 @@ module Sinatra
|
|
47
47
|
|
48
48
|
file_basename = params[:splat].pop.gsub(/\/$/,'')
|
49
49
|
|
50
|
-
dir = "#{
|
50
|
+
dir = "#{settings.root}/#{settings.editable_dir}/#{params[:splat].join('/')}"
|
51
51
|
|
52
52
|
html_path = "#{dir}/#{file_basename}.html"
|
53
|
-
template_path = "#{dir}/#{file_basename}.#{
|
53
|
+
template_path = "#{dir}/#{file_basename}.#{settings.editable_templater}"
|
54
54
|
|
55
55
|
FileUtils.mkdir_p dir unless File.exist?(File.dirname(dir))
|
56
56
|
|