Fixed a bug with system creation; also fixed a semi-hardcoded EXPORT_DIRECTORY path in controller
This commit is contained in:
parent
778e9420b5
commit
88b3a1ba08
|
@ -6,15 +6,13 @@ class WikiController < ApplicationController
|
||||||
|
|
||||||
before_filter :pre_process
|
before_filter :pre_process
|
||||||
|
|
||||||
EXPORT_DIRECTORY = File.dirname(__FILE__) + "/../../storage/" unless const_defined?("EXPORT_DIRECTORY")
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if @web_name
|
if @web_name
|
||||||
redirect_show 'HomePage'
|
redirect_show 'HomePage'
|
||||||
elsif not wiki.setup?
|
elsif not @wiki.setup?
|
||||||
redirect_to :action => 'new_system'
|
redirect_to :action => 'new_system'
|
||||||
elsif wiki.webs.length == 1
|
elsif @wiki.webs.length == 1
|
||||||
redirect_show 'HomePage', wiki.webs.values.first.address
|
redirect_show 'HomePage', @wiki.webs.values.first.address
|
||||||
else
|
else
|
||||||
redirect_to :action => 'web_list'
|
redirect_to :action => 'web_list'
|
||||||
end
|
end
|
||||||
|
@ -23,13 +21,13 @@ class WikiController < ApplicationController
|
||||||
# Administrating the Instiki setup --------------------------------------------
|
# Administrating the Instiki setup --------------------------------------------
|
||||||
|
|
||||||
def create_system
|
def create_system
|
||||||
wiki.setup(@params['password'], @params['web_name'], @params['web_address']) unless wiki.setup?
|
@wiki.setup(@params['password'], @params['web_name'], @params['web_address']) unless @wiki.setup?
|
||||||
redirect_to :action => 'index'
|
redirect_show('HomePage', @params['web_address'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_web
|
def create_web
|
||||||
if wiki.authenticate(@params['system_password'])
|
if @wiki.authenticate(@params['system_password'])
|
||||||
wiki.create_web(@params['name'], @params['address'])
|
@wiki.create_web(@params['name'], @params['address'])
|
||||||
redirect_show('HomePage', @params['address'])
|
redirect_show('HomePage', @params['address'])
|
||||||
else
|
else
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
|
@ -82,7 +80,7 @@ class WikiController < ApplicationController
|
||||||
|
|
||||||
def export_pdf
|
def export_pdf
|
||||||
file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}"
|
file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}"
|
||||||
file_path = EXPORT_DIRECTORY + file_name
|
file_path = WikiService.storage_path + file_name
|
||||||
|
|
||||||
export_web_to_tex(file_path + ".tex") unless FileTest.exists?(file_path + ".tex")
|
export_web_to_tex(file_path + ".tex") unless FileTest.exists?(file_path + ".tex")
|
||||||
convert_tex_to_pdf(file_path + ".tex")
|
convert_tex_to_pdf(file_path + ".tex")
|
||||||
|
@ -91,7 +89,7 @@ class WikiController < ApplicationController
|
||||||
|
|
||||||
def export_tex
|
def export_tex
|
||||||
file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.tex"
|
file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.tex"
|
||||||
file_path = EXPORT_DIRECTORY + file_name
|
file_path = WikiService.storage_path + file_name
|
||||||
|
|
||||||
export_web_to_tex(file_path) unless FileTest.exists?(file_path)
|
export_web_to_tex(file_path) unless FileTest.exists?(file_path)
|
||||||
send_export(file_name, file_path)
|
send_export(file_name, file_path)
|
||||||
|
@ -184,7 +182,7 @@ class WikiController < ApplicationController
|
||||||
page = wiki.read_page(@web_name, @page_name)
|
page = wiki.read_page(@web_name, @page_name)
|
||||||
safe_page_name = @page.name.gsub(/\W/, '')
|
safe_page_name = @page.name.gsub(/\W/, '')
|
||||||
file_name = "#{safe_page_name}-#{@web.address}-#{@page.created_at.strftime("%Y-%m-%d-%H-%M")}"
|
file_name = "#{safe_page_name}-#{@web.address}-#{@page.created_at.strftime("%Y-%m-%d-%H-%M")}"
|
||||||
file_path = EXPORT_DIRECTORY + file_name
|
file_path = WikiService.storage_path + file_name
|
||||||
|
|
||||||
export_page_to_tex(file_path + '.tex') unless FileTest.exists?(file_path + '.tex')
|
export_page_to_tex(file_path + '.tex') unless FileTest.exists?(file_path + '.tex')
|
||||||
convert_tex_to_pdf(file_path + '.tex')
|
convert_tex_to_pdf(file_path + '.tex')
|
||||||
|
@ -286,7 +284,7 @@ class WikiController < ApplicationController
|
||||||
|
|
||||||
file_prefix = "#{@web.address}-#{file_type}-"
|
file_prefix = "#{@web.address}-#{file_type}-"
|
||||||
timestamp = @web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')
|
timestamp = @web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')
|
||||||
file_path = EXPORT_DIRECTORY + file_prefix + timestamp + '.zip'
|
file_path = WikiService.storage_path + file_prefix + timestamp + '.zip'
|
||||||
tmp_path = "#{file_path}.tmp"
|
tmp_path = "#{file_path}.tmp"
|
||||||
|
|
||||||
Zip::ZipOutputStream.open(tmp_path) do |zip_out|
|
Zip::ZipOutputStream.open(tmp_path) do |zip_out|
|
||||||
|
@ -306,7 +304,7 @@ class WikiController < ApplicationController
|
||||||
EOL
|
EOL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
FileUtils.rm_rf(Dir[EXPORT_DIRECTORY + file_prefix + '*.zip'])
|
FileUtils.rm_rf(Dir[WikiService.storage_path + file_prefix + '*.zip'])
|
||||||
FileUtils.mv(tmp_path, file_path)
|
FileUtils.mv(tmp_path, file_path)
|
||||||
send_file(file_path, :type => 'application/zip')
|
send_file(file_path, :type => 'application/zip')
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,7 +100,7 @@ class WikiService
|
||||||
include AbstractWikiService
|
include AbstractWikiService
|
||||||
include Madeleine::Automatic::Interceptor
|
include Madeleine::Automatic::Interceptor
|
||||||
|
|
||||||
@@storage_path = self.name.downcase + '_storage'
|
@@storage_path = './storage/'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def storage_path
|
def storage_path
|
||||||
|
|
|
@ -73,7 +73,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
||||||
'web_address' => 'my_wiki')
|
'web_address' => 'my_wiki')
|
||||||
|
|
||||||
assert_redirected_to :action => 'index'
|
assert_redirected_to :web => 'my_wiki', :action => 'show', :id => 'HomePage'
|
||||||
assert @controller.wiki.setup?
|
assert @controller.wiki.setup?
|
||||||
assert_equal 'a_password', @controller.wiki.system[:password]
|
assert_equal 'a_password', @controller.wiki.system[:password]
|
||||||
assert_equal 1, @controller.wiki.webs.size
|
assert_equal 1, @controller.wiki.webs.size
|
||||||
|
@ -89,7 +89,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
||||||
'web_address' => 'my_wiki'
|
'web_address' => 'my_wiki'
|
||||||
|
|
||||||
assert_redirected_to :action => 'index'
|
assert_redirected_to :web => 'my_wiki', :action => 'show', :id => 'HomePage'
|
||||||
assert_equal wiki_before, @controller.wiki
|
assert_equal wiki_before, @controller.wiki
|
||||||
# and no new wikis shuld be created either
|
# and no new wikis shuld be created either
|
||||||
assert_equal 1, @controller.wiki.webs.size
|
assert_equal 1, @controller.wiki.webs.size
|
||||||
|
|
Loading…
Reference in a new issue